diff options
Diffstat (limited to 'awk/rawk/tests/core')
-rw-r--r-- | awk/rawk/tests/core/README.md | 108 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_array_fix.rawk | 50 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_basic.rawk | 26 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_edge_cases.rawk | 59 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_failure.rawk | 16 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_multiline.rawk | 43 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_pattern_matching.rawk | 110 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_pattern_matching_simple.rawk | 13 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_recursive.rawk | 53 | ||||
-rw-r--r-- | awk/rawk/tests/core/test_suite.rawk | 145 |
10 files changed, 0 insertions, 623 deletions
diff --git a/awk/rawk/tests/core/README.md b/awk/rawk/tests/core/README.md deleted file mode 100644 index 21ae650..0000000 --- a/awk/rawk/tests/core/README.md +++ /dev/null @@ -1,108 +0,0 @@ -# Core Language Tests - -This directory contains tests for the fundamental features of the rawk language. - -## Test Files - -### `test_suite.rawk` - Comprehensive Test Suite -The main test suite that covers all core language features: -- Basic function definitions and calls -- Multi-line functions -- Nested function calls -- Function calls within function bodies -- Edge cases and error conditions -- Boolean assertions -- Array operations -- Conditional expressions -- Complex expressions - -**Run with:** -```bash -awk -f ../../rawk.awk test_suite.rawk | awk -f - -``` - -### `test_basic.rawk` - Basic Functions -Tests basic single-line function definitions and calls: -- Addition, multiplication, string concatenation -- Function call replacement with internal names - -**Run with:** -```bash -awk -f ../../rawk.awk test_basic.rawk | awk -f - -``` - -### `test_multiline.rawk` - Multi-line Functions -Tests multi-line function definitions: -- Complex function bodies with multiple statements -- Return statements -- Array processing within functions - -**Run with:** -```bash -awk -f ../../rawk.awk test_multiline.rawk | awk -f - -``` - -### `test_edge_cases.rawk` - Edge Cases -Tests edge cases and error conditions: -- Functions with no arguments -- Functions with many arguments -- Complex expressions -- String operations -- Conditional expressions -- Array access - -**Run with:** -```bash -awk -f ../../rawk.awk test_edge_cases.rawk | awk -f - -``` - -### `test_recursive.rawk` - Recursive Functions -Tests recursive function support: -- Factorial function -- Fibonacci function -- Countdown function -- Self-referential function calls - -**Run with:** -```bash -awk -f ../../rawk.awk test_recursive.rawk | awk -f - -``` - -### `test_array_fix.rawk` - Array Handling -Tests array operations and utilities: -- Basic array operations -- Standard library array functions -- Associative arrays -- Array statistics - -**Run with:** -```bash -awk -f ../../rawk.awk test_array_fix.rawk | awk -f - -``` - -### `test_failure.rawk` - Assertion Failures -Demonstrates the assertion system: -- Shows how failing tests are reported -- Tests error message formatting -- Validates test framework functionality - -**Run with:** -```bash -awk -f ../../rawk.awk test_failure.rawk | awk -f - 2>&1 -``` - -## Expected Results - -All tests should pass with clear output showing: -- ✓ Test results with descriptions -- 🎉 Success messages -- Proper error reporting for failures - -The comprehensive test suite should show: -``` -=== Test Summary === -Total tests: 15 -Passed: 15 -Failed: 0 -🎉 All tests passed! -``` \ No newline at end of file diff --git a/awk/rawk/tests/core/test_array_fix.rawk b/awk/rawk/tests/core/test_array_fix.rawk deleted file mode 100644 index e488762..0000000 --- a/awk/rawk/tests/core/test_array_fix.rawk +++ /dev/null @@ -1,50 +0,0 @@ -# Test to isolate array handling issues -$test_array_func = (arr) -> { - return "Array has " length(arr) " elements" -}; - -BEGIN { - print "=== Testing Array Handling ===" - - # Test basic array operations - data[1] = 10 - data[2] = 20 - data[3] = 30 - - # Test our custom function - result = test_array_func(data) - expect_equal(result, "Array has 3 elements", "test_array_func should return correct count") - print "✓ " result - - # Test keys function - key_count = keys(data) - expect_equal(key_count, 3, "keys() should return count of 3") - get_keys(data, key_array) - expect_true(key_array[1] == 1 || key_array[1] == 2 || key_array[1] == 3, "First key should be 1, 2, or 3") - expect_true(key_array[2] == 1 || key_array[2] == 2 || key_array[2] == 3, "Second key should be 1, 2, or 3") - expect_true(key_array[3] == 1 || key_array[3] == 2 || key_array[3] == 3, "Third key should be 1, 2, or 3") - print "✓ keys() function works correctly" - - # Test values function - value_count = values(data) - expect_equal(value_count, 3, "values() should return count of 3") - get_values(data, value_array) - expect_true(value_array[1] == 10 || value_array[1] == 20 || value_array[1] == 30, "First value should be 10, 20, or 30") - expect_true(value_array[2] == 10 || value_array[2] == 20 || value_array[2] == 30, "Second value should be 10, 20, or 30") - expect_true(value_array[3] == 10 || value_array[3] == 20 || value_array[3] == 30, "Third value should be 10, 20, or 30") - print "✓ values() function works correctly" - - # Test associative array - info["name"] = "rawk" - info["type"] = "language" - info["target"] = "awk" - - info_key_count = keys(info) - info_value_count = values(info) - - expect_equal(info_key_count, 3, "keys() should work with associative arrays") - expect_equal(info_value_count, 3, "values() should work with associative arrays") - print "✓ Associative array operations work correctly" - - print "🎉 All array handling tests passed!" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_basic.rawk b/awk/rawk/tests/core/test_basic.rawk deleted file mode 100644 index d92091a..0000000 --- a/awk/rawk/tests/core/test_basic.rawk +++ /dev/null @@ -1,26 +0,0 @@ -# Basic rawk function definitions -$add = (x, y) -> x + y; -$multiply = (a, b) -> a * b; -$greet = (name) -> "Hello, " name; - -# Test the functions -BEGIN { - print "Testing basic functions:" - - # Test add function - result = add(5, 3) - expect_equal(result, 8, "add(5, 3) should return 8") - print "✓ add(5, 3) = " result - - # Test multiply function - result = multiply(4, 7) - expect_equal(result, 28, "multiply(4, 7) should return 28") - print "✓ multiply(4, 7) = " result - - # Test greet function - result = greet("World") - expect_equal(result, "Hello, World", "greet(\"World\") should return 'Hello, World'") - print "✓ greet(\"World\") = " result - - print "🎉 All basic function tests passed!" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_edge_cases.rawk b/awk/rawk/tests/core/test_edge_cases.rawk deleted file mode 100644 index 8196acd..0000000 --- a/awk/rawk/tests/core/test_edge_cases.rawk +++ /dev/null @@ -1,59 +0,0 @@ -# Test edge cases and error conditions -$no_args = () -> "no arguments"; -$single_arg = (x) -> x; -$many_args = (a, b, c, d, e) -> a + b + c + d + e; -$empty_body = (x) -> ; -$complex_expr = (x, y) -> (x * y) + (x / y) - (x % y); - -# Test functions with different argument patterns -$string_concat = (str1, str2) -> str1 " " str2; -$array_access = (arr, idx) -> arr[idx]; -$conditional = (x) -> x > 0 ? "positive" : "negative"; - -# Test the edge cases -BEGIN { - print "=== Testing Edge Cases ===" - - # Test no arguments - result = no_args() - expect_equal(result, "no arguments", "no_args() should return 'no arguments'") - print "✓ no_args() = " result - - # Test single argument - result = single_arg(42) - expect_equal(result, 42, "single_arg(42) should return 42") - print "✓ single_arg(42) = " result - - # Test many arguments - result = many_args(1,2,3,4,5) - expect_equal(result, 15, "many_args(1,2,3,4,5) should return 15") - print "✓ many_args(1,2,3,4,5) = " result - - # Test complex expressions - result = complex_expr(10, 3) - expect_true(result > 32.3 && result < 32.4, "complex_expr(10, 3) should be approximately 32.3333") - print "✓ complex_expr(10, 3) = " result - - # Test string concatenation - result = string_concat("Hello", "World") - expect_equal(result, "Hello World", "string_concat(\"Hello\", \"World\") should return 'Hello World'") - print "✓ string_concat(\"Hello\", \"World\") = " result - - # Test conditional - result = conditional(5) - expect_equal(result, "positive", "conditional(5) should return 'positive'") - print "✓ conditional(5) = " result - - result = conditional(-3) - expect_equal(result, "negative", "conditional(-3) should return 'negative'") - print "✓ conditional(-3) = " result - - # Test array access - test_arr[1] = "first" - test_arr[2] = "second" - result = array_access(test_arr, 2) - expect_equal(result, "second", "array_access(test_arr, 2) should return 'second'") - print "✓ array_access(test_arr, 2) = " result - - print "🎉 All edge case tests passed!" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_failure.rawk b/awk/rawk/tests/core/test_failure.rawk deleted file mode 100644 index adeafa5..0000000 --- a/awk/rawk/tests/core/test_failure.rawk +++ /dev/null @@ -1,16 +0,0 @@ -# Test that demonstrates failing assertions -$add = (x, y) -> x + y; - -BEGIN { - print "Testing assertion failures (this should fail):" - - # This should pass - result = add(2, 3) - expect_equal(result, 5, "add(2, 3) should return 5") - print "✓ This assertion should pass" - - # This should fail - result = add(2, 3) - expect_equal(result, 10, "add(2, 3) should return 10 (this will fail)") - print "This line should not be reached" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_multiline.rawk b/awk/rawk/tests/core/test_multiline.rawk deleted file mode 100644 index 95a889f..0000000 --- a/awk/rawk/tests/core/test_multiline.rawk +++ /dev/null @@ -1,43 +0,0 @@ -# Multi-line rawk function definitions -$calculate_area = (width, height) -> { - area = width * height - return area -}; - -$format_message = (name, age) -> { - message = "Name: " name ", Age: " age - return message -}; - -$process_array = (arr) -> { - sum = 0 - for (i in arr) { - sum += arr[i] - } - return sum -}; - -# Test the multi-line functions -BEGIN { - print "Testing multi-line functions:" - - # Test calculate_area function - result = calculate_area(5, 3) - expect_equal(result, 15, "calculate_area(5, 3) should return 15") - print "✓ calculate_area(5, 3) = " result - - # Test format_message function - result = format_message("Alice", 30) - expect_equal(result, "Name: Alice, Age: 30", "format_message(\"Alice\", 30) should return 'Name: Alice, Age: 30'") - print "✓ format_message(\"Alice\", 30) = " result - - # Test with array - test_array[1] = 10 - test_array[2] = 20 - test_array[3] = 30 - result = process_array(test_array) - expect_equal(result, 60, "process_array([10,20,30]) should return 60") - print "✓ process_array([10,20,30]) = " result - - print "🎉 All multi-line function tests passed!" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_pattern_matching.rawk b/awk/rawk/tests/core/test_pattern_matching.rawk deleted file mode 100644 index e9ebfd0..0000000 --- a/awk/rawk/tests/core/test_pattern_matching.rawk +++ /dev/null @@ -1,110 +0,0 @@ -# Test suite for rawk pattern matching -# This demonstrates the new pattern matching capabilities - -BEGIN { - print "=== rawk Pattern Matching Test Suite ===" - print "" - - # Test counters - total_tests = 0 - passed_tests = 0 - failed_tests = 0 - - # Helper function to run tests - $run_test = (name, actual, expected) -> { - total_tests++ - if (actual == expected) { - passed_tests++ - print "✓ " name - } else { - failed_tests++ - print "❌ " name " (expected '" expected "', got '" actual "')" - } - } - - # Pattern matching function for number classification - $classify_number = (value) -> { - case value of - | 0 -> "zero" - | n if is_positive(n) -> "positive" - | n if is_negative(n) -> "negative" - | _ -> "unknown" - } - - # Pattern matching function for string classification - $classify_string = (str) -> { - case str of - | "" -> "empty" - | s if is_alpha(s) -> "alphabetic" - | s if is_numeric(s) -> "numeric" - | s if is_alphanumeric(s) -> "alphanumeric" - | s if is_palindrome(s) -> "palindrome" - | _ -> "other" - } - - # Pattern matching function for type checking - $classify_type = (value) -> { - case value of - | v if is_number(v) -> "number" - | v if is_string(v) -> "string" - | v if is_empty(v) -> "empty" - | _ -> "unknown" - } - - # Pattern matching function for validation - $validate_input = (value) -> { - case value of - | "" -> "empty input" - | v if is_email(v) -> "valid email" - | v if is_url(v) -> "valid url" - | v if is_ipv4(v) -> "valid ipv4" - | v if is_number(v) && is_in_range(v, 1, 100) -> "valid number in range" - | _ -> "invalid input" - } - - # Test number classification - print "=== Number Classification Tests ===" - run_test("classify_number(0)", classify_number(0), "zero") - run_test("classify_number(42)", classify_number(42), "positive") - run_test("classify_number(-5)", classify_number(-5), "negative") - run_test("classify_number(3.14)", classify_number(3.14), "positive") - - print "" - print "=== String Classification Tests ===" - run_test("classify_string(\"\")", classify_string(""), "empty") - run_test("classify_string(\"hello\")", classify_string("hello"), "alphabetic") - run_test("classify_string(\"123\")", classify_string("123"), "numeric") - run_test("classify_string(\"Hello123\")", classify_string("Hello123"), "alphanumeric") - run_test("classify_string(\"racecar\")", classify_string("racecar"), "palindrome") - run_test("classify_string(\"hello world\")", classify_string("hello world"), "other") - - print "" - print "=== Type Classification Tests ===" - run_test("classify_type(42)", classify_type(42), "number") - run_test("classify_type(\"hello\")", classify_type("hello"), "string") - run_test("classify_type(\"\")", classify_type(""), "empty") - run_test("classify_type(0)", classify_type(0), "number") - - print "" - print "=== Validation Tests ===" - run_test("validate_input(\"\")", validate_input(""), "empty input") - run_test("validate_input(\"user@example.com\")", validate_input("user@example.com"), "valid email") - run_test("validate_input(\"http://example.com\")", validate_input("http://example.com"), "valid url") - run_test("validate_input(\"192.168.1.1\")", validate_input("192.168.1.1"), "valid ipv4") - run_test("validate_input(50)", validate_input(50), "valid number in range") - run_test("validate_input(150)", validate_input(150), "invalid input") - run_test("validate_input(\"invalid\")", validate_input("invalid"), "invalid input") - - # Print summary - print "" - print "=== Test Summary ===" - print "Total tests: " total_tests - print "Passed: " passed_tests - print "Failed: " failed_tests - - if (failed_tests == 0) { - print "🎉 All pattern matching tests passed!" - } else { - print "❌ Some tests failed!" - } -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_pattern_matching_simple.rawk b/awk/rawk/tests/core/test_pattern_matching_simple.rawk deleted file mode 100644 index 746093a..0000000 --- a/awk/rawk/tests/core/test_pattern_matching_simple.rawk +++ /dev/null @@ -1,13 +0,0 @@ -# Simple pattern matching test -$classify = (value) -> { - case value of - | 0 -> "zero" - | n if is_positive(n) -> "positive" - | _ -> "unknown" -} - -# Test the function -print "Testing pattern matching:" -print "classify(0) = " classify(0) -print "classify(42) = " classify(42) -print "classify(-5) = " classify(-5) \ No newline at end of file diff --git a/awk/rawk/tests/core/test_recursive.rawk b/awk/rawk/tests/core/test_recursive.rawk deleted file mode 100644 index 4e89a4d..0000000 --- a/awk/rawk/tests/core/test_recursive.rawk +++ /dev/null @@ -1,53 +0,0 @@ -# Test recursive functions -$factorial = (n) -> { - if (n <= 1) { - return 1 - } else { - return n * factorial(n - 1) - } -}; - -$fibonacci = (n) -> { - if (n <= 1) { - return n - } else { - return fibonacci(n - 1) + fibonacci(n - 2) - } -}; - -$countdown = (n) -> { - if (n <= 0) { - return "Done!" - } else { - return n " " countdown(n - 1) - } -}; - -BEGIN { - print "=== Testing Recursive Functions ===" - - # Test factorial - result = factorial(5) - expect_equal(result, 120, "factorial(5) should return 120") - print "✓ factorial(5) = " result - - result = factorial(3) - expect_equal(result, 6, "factorial(3) should return 6") - print "✓ factorial(3) = " result - - # Test fibonacci - result = fibonacci(6) - expect_equal(result, 8, "fibonacci(6) should return 8") - print "✓ fibonacci(6) = " result - - result = fibonacci(4) - expect_equal(result, 3, "fibonacci(4) should return 3") - print "✓ fibonacci(4) = " result - - # Test countdown - result = countdown(3) - expect_equal(result, "3 2 1 Done!", "countdown(3) should return '3 2 1 Done!'") - print "✓ countdown(3) = " result - - print "🎉 All recursive function tests passed!" -} \ No newline at end of file diff --git a/awk/rawk/tests/core/test_suite.rawk b/awk/rawk/tests/core/test_suite.rawk deleted file mode 100644 index fd069aa..0000000 --- a/awk/rawk/tests/core/test_suite.rawk +++ /dev/null @@ -1,145 +0,0 @@ -# rawk Test Suite -# This file tests all major features of the rawk language using assertions - -# Basic function definitions for testing -$add = (x, y) -> x + y; -$multiply = (a, b) -> a * b; -$greet = (name) -> "Hello, " name; -$square = (x) -> x * x; -$double = (x) -> x * 2; - -# Multi-line function for testing -$calculate_area = (width, height) -> { - area = width * height - return area -}; - -# Function that calls other functions -$complex_calc = (x, y) -> { - doubled = double(x) - squared = square(y) - result = add(doubled, squared) - return result -}; - -# Test runner -BEGIN { - print "=== rawk Test Suite ===" - test_count = 0 - passed_count = 0 - - # Test 1: Basic single-line functions - test_count++ - result = add(5, 3) - expect_equal(result, 8, "add(5, 3) should return 8") - passed_count++ - print "✓ Test " test_count ": Basic addition" - - test_count++ - result = multiply(4, 7) - expect_equal(result, 28, "multiply(4, 7) should return 28") - passed_count++ - print "✓ Test " test_count ": Basic multiplication" - - test_count++ - result = greet("World") - expect_equal(result, "Hello, World", "greet(\"World\") should return 'Hello, World'") - passed_count++ - print "✓ Test " test_count ": String concatenation" - - # Test 2: Multi-line functions - test_count++ - result = calculate_area(5, 3) - expect_equal(result, 15, "calculate_area(5, 3) should return 15") - passed_count++ - print "✓ Test " test_count ": Multi-line function" - - # Test 3: Nested function calls - test_count++ - result = double(square(3)) - expect_equal(result, 18, "double(square(3)) should return 18") - passed_count++ - print "✓ Test " test_count ": Nested function calls" - - test_count++ - result = square(double(3)) - expect_equal(result, 36, "square(double(3)) should return 36") - passed_count++ - print "✓ Test " test_count ": Different nested function order" - - # Test 4: Function calls within function bodies - test_count++ - result = complex_calc(3, 4) - expect_equal(result, 22, "complex_calc(3, 4) should return 22") - passed_count++ - print "✓ Test " test_count ": Function calls within function bodies" - - # Test 5: Edge cases - test_count++ - result = add(0, 0) - expect_equal(result, 0, "add(0, 0) should return 0") - passed_count++ - print "✓ Test " test_count ": Zero values" - - test_count++ - result = multiply(-2, 3) - expect_equal(result, -6, "multiply(-2, 3) should return -6") - passed_count++ - print "✓ Test " test_count ": Negative numbers" - - # Test 6: String operations - test_count++ - result = greet("") - expect_equal(result, "Hello, ", "greet(\"\") should return 'Hello, '") - passed_count++ - print "✓ Test " test_count ": Empty string" - - # Test 7: Boolean assertions - test_count++ - expect_true(add(2, 2) == 4, "2 + 2 should equal 4") - passed_count++ - print "✓ Test " test_count ": Boolean true assertion" - - test_count++ - expect_false(add(2, 2) == 5, "2 + 2 should not equal 5") - passed_count++ - print "✓ Test " test_count ": Boolean false assertion" - - # Test 8: Array operations (basic) - test_count++ - data[1] = 10 - data[2] = 20 - data[3] = 30 - expect_equal(data[1], 10, "data[1] should be 10") - expect_equal(data[2], 20, "data[2] should be 20") - expect_equal(data[3], 30, "data[3] should be 30") - passed_count++ - print "✓ Test " test_count ": Basic array operations" - - # Test 9: Conditional expressions - test_count++ - result = 5 > 3 ? "greater" : "less" - expect_equal(result, "greater", "5 > 3 should be 'greater'") - passed_count++ - print "✓ Test " test_count ": Conditional expressions" - - # Test 10: Complex expressions - test_count++ - result = (2 + 3) * 4 - expect_equal(result, 20, "(2 + 3) * 4 should be 20") - passed_count++ - print "✓ Test " test_count ": Complex expressions" - - # Summary - print "\n=== Test Summary ===" - print "Total tests: " test_count - print "Passed: " passed_count - print "Failed: " (test_count - passed_count) - - if (passed_count == test_count) { - print "🎉 All tests passed!" - } else { - print "❌ Some tests failed!" - exit 1 - } -} \ No newline at end of file |