diff options
Diffstat (limited to 'awk/rawk/scratch/tests_old/stdlib/README.md')
-rw-r--r-- | awk/rawk/scratch/tests_old/stdlib/README.md | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/awk/rawk/scratch/tests_old/stdlib/README.md b/awk/rawk/scratch/tests_old/stdlib/README.md new file mode 100644 index 0000000..1b7b028 --- /dev/null +++ b/awk/rawk/scratch/tests_old/stdlib/README.md @@ -0,0 +1,89 @@ +# Standard Library Tests + +This directory contains tests for the built-in standard library functions. + +## Test Files + +### `test_stdlib_simple.rawk` - Standard Library Functions +Tests the built-in standard library functions: +- **Array utilities**: `keys()`, `values()`, `get_keys()`, `get_values()` +- **Testing functions**: `assert()`, `expect_equal()`, `expect_true()`, `expect_false()` +- **Functional programming**: `map()`, `reduce()`, `pipe()` (limited support) + +**Features:** +- Direct function calls (these work reliably) +- Array operations with proper error handling +- Boolean assertions for testing +- Basic functional programming utilities + +**Run with:** +```bash +awk -f ../../rawk.awk test_stdlib_simple.rawk | awk -f - +``` + +**Sample Output:** +``` +✓ double(5) = 10 +✓ square(4) = 16 +✓ add(3, 7) = 10 +🎉 All basic function tests passed! +``` + +## Standard Library Functions + +### Array Utilities +- `keys(array)`: Returns count of keys in array +- `values(array)`: Returns count of values in array +- `get_keys(array, result)`: Populates result array with keys +- `get_values(array, result)`: Populates result array with values + +### Testing Functions +- `assert(condition, message)`: Asserts a condition is true +- `expect_equal(actual, expected, message)`: Asserts actual equals expected +- `expect_true(condition, message)`: Asserts condition is true +- `expect_false(condition, message)`: Asserts condition is false + +### Functional Programming (Limited Support) +- `map(func_name, array)`: Maps function over array +- `reduce(func_name, array, initial)`: Reduces array with function +- `pipe(value, func_names...)`: Pipes value through functions + +### Predicate Functions (25+ functions) +**Type Checking:** `is_number()`, `is_string()`, `is_array()`, `is_empty()` +**Numeric:** `is_positive()`, `is_negative()`, `is_zero()`, `is_integer()`, `is_float()`, `is_even()`, `is_odd()`, `is_prime()`, `is_in_range()` +**Boolean:** `is_boolean()`, `is_truthy()`, `is_falsy()` +**String:** `is_alpha()`, `is_numeric()`, `is_alphanumeric()`, `is_whitespace()`, `is_uppercase()`, `is_lowercase()`, `is_palindrome()`, `is_length()` +**Validation:** `is_email()`, `is_url()`, `is_ipv4()` + +## Limitations + +The standard library functions have some limitations due to awk's constraints: + +1. **Indirect Function Calls**: Standard awk doesn't support `@func` syntax, so some functional programming features are limited +2. **Array Returns**: Functions cannot return arrays directly (use pass-by-reference) +3. **String-based Dispatch**: The `map` and `reduce` functions work with string function names but have limited support + +## Usage Examples + +### Array Operations +```rawk +data["a"] = 1 +data["b"] = 2 +data["c"] = 3 + +key_count = keys(data) # Returns 3 +get_keys(data, key_array) # Populates key_array with keys +``` + +### Testing +```rawk +result = add(2, 3) +expect_equal(result, 5, "add(2, 3) should return 5") +expect_true(result > 0, "result should be positive") +``` + +### Functional Programming +```rawk +numbers[1] = 1; numbers[2] = 2; numbers[3] = 3 +doubled = map("double", numbers) # Limited support +``` \ No newline at end of file |