diff options
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/run_basic_tests.sh')
-rwxr-xr-x | js/scripting-lang/baba-yaga-c/run_basic_tests.sh | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/js/scripting-lang/baba-yaga-c/run_basic_tests.sh b/js/scripting-lang/baba-yaga-c/run_basic_tests.sh new file mode 100755 index 0000000..aff459f --- /dev/null +++ b/js/scripting-lang/baba-yaga-c/run_basic_tests.sh @@ -0,0 +1,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 "$@" \ No newline at end of file |