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
57
58
|
# Generated by rawk v2.0.0
# Source: test_basic.rawk
# --- Standard Library ---
function is_number(value) { return value == value + 0 }
function is_string(value) { return !(value == value + 0) }
function get_keys(array, result, i, count) { count = 0; for (i in array) { result[++count] = i }; return count }
function expect_equal(actual, expected, message) { if (actual != expected) { print "❌ Expected " expected " but got " actual " - " message > "/dev/stderr"; exit 1 } }
function expect_true(condition, message) { if (!condition) { print "❌ Expected true but got false - " message > "/dev/stderr"; exit 1 } }
function expect_false(condition, message) { if (condition) { print "❌ Expected false but got true - " message > "/dev/stderr"; exit 1 } }
# --- User Functions ---
# --- Main Script ---
BEGIN {
print "=== Basic Block-Based rawk Tests ==="
}
$multiply = (a, b) -> {
return a * b;
};
$greet = (name) -> {
return "Hello, " name "!";
};
$is_positive_num = (num) -> {
return num > 0;
};
}
{
# Test basic arithmetic
result1 = add(5, 3);
expect_equal(result1, 8, "add(5, 3) should return 8");
result2 = multiply(4, 7);
expect_equal(result2, 28, "multiply(4, 7) should return 28");
# Test string functions
greeting = greet("World");
expect_equal(greeting, "Hello, World!", "greet('World') should return 'Hello, World!'");
# Test boolean functions
expect_true(is_positive_num(10), "is_positive_num(10) should return true");
expect_false(is_positive_num(-5), "is_positive_num(-5) should return false");
print "All basic tests passed!";
exit 0;
}
# Rawk compilation summary:
# - Rawk Version: 2.0.0
# - Functions defined: 0
# - Source lines: 41
# - Standard library functions included: 3
|