about summary refs log tree commit diff stats
path: root/awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk
blob: 426f3690ee11e42794fd199b43295b495492fd62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Simple example: Using rawk predicate functions

BEGIN {
    print "=== rawk Predicate Functions Example ==="
    print ""
    
    # Test various predicate functions
    print "=== Type Checking ==="
    print "is_number(42): " is_number(42)
    print "is_string(\"hello\"): " is_string("hello")
    print "is_empty(\"\"): " is_empty("")
    print "is_empty(0): " is_empty(0)
    
    print ""
    print "=== Numeric Predicates ==="
    print "is_positive(42): " is_positive(42)
    print "is_negative(-5): " is_negative(-5)
    print "is_zero(0): " is_zero(0)
    print "is_integer(42): " is_integer(42)
    print "is_float(3.14): " is_float(3.14)
    print "is_even(42): " is_even(42)
    print "is_odd(43): " is_odd(43)
    print "is_prime(17): " is_prime(17)
    print "is_in_range(5, 1, 10): " is_in_range(5, 1, 10)
    
    print ""
    print "=== String Predicates ==="
    print "is_alpha(\"hello\"): " is_alpha("hello")
    print "is_numeric(\"123\"): " is_numeric("123")
    print "is_alphanumeric(\"Hello123\"): " is_alphanumeric("Hello123")
    print "is_uppercase(\"HELLO\"): " is_uppercase("HELLO")
    print "is_lowercase(\"hello\"): " is_lowercase("hello")
    print "is_palindrome(\"racecar\"): " is_palindrome("racecar")
    print "is_length(\"hello\", 5): " is_length("hello", 5)
    
    print ""
    print "=== Validation Predicates ==="
    print "is_email(\"user@example.com\"): " is_email("user@example.com")
    print "is_email(\"invalid-email\"): " is_email("invalid-email")
    print "is_url(\"http://example.com\"): " is_url("http://example.com")
    print "is_url(\"example.com\"): " is_url("example.com")
    print "is_ipv4(\"192.168.1.1\"): " is_ipv4("192.168.1.1")
    print "is_ipv4(\"256.1.2.3\"): " is_ipv4("256.1.2.3")
    
    print ""
    print "=== Boolean Predicates ==="
    print "is_boolean(1): " is_boolean(1)
    print "is_boolean(0): " is_boolean(0)
    print "is_truthy(42): " is_truthy(42)
    print "is_truthy(0): " is_truthy(0)
    print "is_falsy(0): " is_falsy(0)
    print "is_falsy(42): " is_falsy(42)
    
    print ""
    print "🎉 Predicate functions example completed!"
}