about summary refs log tree commit diff stats
path: root/js/scripting-lang/baba-yaga-c/run_basic_tests.sh
blob: aff459f3515ccdd0603fb65a7f2871f2e479c7a8 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash

# Baba Yaga C Implementation - Basic Test Runner
# This script tests only the features that are currently working

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Configuration
BABA_YAGA_BIN="./bin/baba-yaga"
TEMP_DIR="./temp_test_output"

# Statistics
total_tests=0
passed_tests=0
failed_tests=0

# Function to print header
print_header() {
    echo -e "${BLUE}========================================${NC}"
    echo -e "${BLUE}  Baba Yaga C Implementation - Basic Tests${NC}"
    echo -e "${BLUE}========================================${NC}"
    echo ""
}

# Function to run a single test
run_test() {
    local test_name="$1"
    local test_code="$2"
    local expected_output="$3"
    
    total_tests=$((total_tests + 1))
    
    echo -n "Testing $test_name... "
    
    # Run the test
    local output
    output=$($BABA_YAGA_BIN "$test_code" 2>/dev/null || echo "ERROR")
    
    # Check if output matches expected
    if [ "$output" = "$expected_output" ]; then
        echo -e "${GREEN}PASS${NC}"
        passed_tests=$((passed_tests + 1))
    else
        echo -e "${RED}FAIL${NC}"
        echo "  Expected: '$expected_output'"
        echo "  Got: '$output'"
        failed_tests=$((failed_tests + 1))
    fi
}

# Function to print section header
print_section() {
    echo -e "${YELLOW}$1${NC}"
    echo -e "${YELLOW}$(printf '=%.0s' {1..${#1}})${NC}"
    echo ""
}

# Function to print summary
print_summary() {
    echo -e "${BLUE}========================================${NC}"
    echo -e "${BLUE}  Test Summary${NC}"
    echo -e "${BLUE}========================================${NC}"
    echo ""
    echo -e "Total tests: $total_tests"
    echo -e "${GREEN}Passed: $passed_tests${NC}"
    echo -e "${RED}Failed: $failed_tests${NC}"
    
    if [ $failed_tests -eq 0 ]; then
        echo -e "${GREEN}All tests passed! 🎉${NC}"
        exit 0
    else
        echo -e "${RED}Some tests failed.${NC}"
        exit 1
    fi
}

# Main execution
main() {
    # Setup
    print_header
    
    # Check if baba-yaga binary exists
    if [ ! -f "$BABA_YAGA_BIN" ]; then
        echo -e "${RED}Error: $BABA_YAGA_BIN not found. Please build the project first.${NC}"
        exit 1
    fi
    
    # Create temp directory
    mkdir -p "$TEMP_DIR"
    
    # Basic Tests
    print_section "Basic Tests"
    
    run_test "Number literal" "42" "42"
    run_test "String literal" '"hello"' "hello"
    run_test "Boolean true" "true" "true"
    run_test "Boolean false" "false" "false"
    run_test "Variable assignment" "x : 42; x" "42"
    run_test "Multiple statements" "a : 5; b : 3; add a b" "8"
    
    # Arithmetic Tests
    print_section "Arithmetic Tests"
    
    run_test "Addition operator" "5 + 3" "8"
    run_test "Subtraction operator" "10 - 3" "7"
    run_test "Multiplication operator" "6 * 7" "42"
    run_test "Division operator" "15 / 3" "5"
    run_test "Modulo operator" "7 % 3" "1"
    run_test "Power operator" "2 ^ 3" "8"
    run_test "Unary minus" "negate 5" "-5"
    run_test "Complex expression" "(5 + 3) * 2" "16"
    
    # Function Tests
    print_section "Function Tests"
    
    run_test "Add function" "add 5 3" "8"
    run_test "Multiply function" "multiply 4 5" "20"
    run_test "Function reference" "@add" "<function>"
    run_test "Apply function" "apply add 5 3" "8"
    run_test "Compose function" "compose add 5 multiply 2" "15"
    
    # Comparison Tests
    print_section "Comparison Tests"
    
    run_test "Equals operator" "5 = 5" "true"
    run_test "Not equals operator" "5 != 3" "true"
    run_test "Less than operator" "3 < 5" "true"
    run_test "Greater than operator" "5 > 3" "true"
    run_test "Less equal operator" "5 <= 5" "true"
    run_test "Greater equal operator" "5 >= 5" "true"
    
    # Logical Tests
    print_section "Logical Tests"
    
    run_test "And operator" "and true true" "true"
    run_test "Or operator" "or true false" "true"
    run_test "Not operator" "not false" "true"
    run_test "Xor operator" "xor true false" "true"
    
    # IO Tests
    print_section "IO Tests"
    
    run_test "Output function" "..out 42" "42"
    run_test "Assert true" "..assert true" "true"
    run_test "Assert false" "..assert false" "false"
    
    # Print summary
    print_summary
}

# Run main function
main "$@"