diff options
Diffstat (limited to 'awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk')
-rw-r--r-- | awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk b/awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk new file mode 100644 index 0000000..426f369 --- /dev/null +++ b/awk/rawk/scratch/tests_old/stdlib/example_predicates_simple.rawk @@ -0,0 +1,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!" +} \ No newline at end of file |