about summary refs log tree commit diff stats
path: root/awk/rawk/tests/test_stdlib.rawk
diff options
context:
space:
mode:
Diffstat (limited to 'awk/rawk/tests/test_stdlib.rawk')
-rw-r--r--awk/rawk/tests/test_stdlib.rawk70
1 files changed, 70 insertions, 0 deletions
diff --git a/awk/rawk/tests/test_stdlib.rawk b/awk/rawk/tests/test_stdlib.rawk
new file mode 100644
index 0000000..480e707
--- /dev/null
+++ b/awk/rawk/tests/test_stdlib.rawk
@@ -0,0 +1,70 @@
+BEGIN {
+    print "=== Standard Library Tests ==="
+}
+
+RAWK {
+    $validate_email = (email) -> {
+        return is_email(email);
+    };
+    
+    $validate_url = (url) -> {
+        return is_url(url);
+    };
+    
+    $validate_number = (num) -> {
+        return is_number(num) && is_positive(num);
+    };
+    
+    $process_data = (data) -> {
+        if (is_csv(data)) {
+            return "CSV data detected";
+        } else if (is_hex(data)) {
+            return "Hex data detected";
+        } else {
+            return "Unknown format";
+        }
+    };
+}
+
+{
+    # Test email validation
+    expect_true(validate_email("user@example.com"), "Valid email should pass");
+    expect_false(validate_email("invalid-email"), "Invalid email should fail");
+    
+    # Test URL validation
+    expect_true(validate_url("https://example.com"), "Valid URL should pass");
+    expect_false(validate_url("not-a-url"), "Invalid URL should fail");
+    
+    # Test number validation
+    expect_true(validate_number(42), "Positive number should pass");
+    expect_false(validate_number(-5), "Negative number should fail");
+    expect_false(validate_number("abc"), "Non-number should fail");
+    
+    # Test data format detection
+    expect_equal(process_data("name,age,city"), "CSV data detected", "CSV detection should work");
+    expect_equal(process_data("FF00AA"), "Hex data detected", "Hex detection should work");
+    expect_equal(process_data("plain text"), "Unknown format", "Unknown format should be detected");
+    
+    # Test HTTP predicates
+    expect_true(http_is_redirect(301), "301 should be a redirect");
+    expect_true(http_is_client_error(404), "404 should be a client error");
+    expect_true(http_is_server_error(500), "500 should be a server error");
+    expect_true(http_is_get("GET"), "GET should be a GET method");
+    expect_true(http_is_post("POST"), "POST should be a POST method");
+    
+    # Test string predicates
+    expect_true(is_alpha("Hello"), "Alphabetic string should pass");
+    expect_true(is_numeric("12345"), "Numeric string should pass");
+    expect_true(is_alphanumeric("Hello123"), "Alphanumeric string should pass");
+    expect_true(is_uppercase("HELLO"), "Uppercase string should pass");
+    expect_true(is_lowercase("hello"), "Lowercase string should pass");
+    
+    # Test numeric predicates
+    expect_true(is_even(2), "2 should be even");
+    expect_true(is_odd(3), "3 should be odd");
+    expect_true(is_prime(7), "7 should be prime");
+    expect_false(is_prime(4), "4 should not be prime");
+    
+    print "All standard library tests passed!";
+    exit 0;
+} 
\ No newline at end of file