diff options
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/test_interpreter.c')
-rw-r--r-- | js/scripting-lang/baba-yaga-c/test_interpreter.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/js/scripting-lang/baba-yaga-c/test_interpreter.c b/js/scripting-lang/baba-yaga-c/test_interpreter.c new file mode 100644 index 0000000..eb09e52 --- /dev/null +++ b/js/scripting-lang/baba-yaga-c/test_interpreter.c @@ -0,0 +1,99 @@ +/** + * @file test_interpreter.c + * @brief Test program for interpreter implementation + * @author eli_oat + * @version 0.0.1 + * @date 2025 + * + * This file tests the interpreter implementation for the Baba Yaga language. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "baba_yaga.h" + +int main(void) { + printf("Testing Baba Yaga Interpreter\n"); + printf("============================\n\n"); + + /* Set debug level */ + baba_yaga_set_debug_level(DEBUG_INFO); + + /* Create interpreter */ + Interpreter* interp = baba_yaga_create(); + if (interp == NULL) { + printf("Failed to create interpreter\n"); + return 1; + } + + printf("ā Interpreter created successfully\n"); + + /* Test basic arithmetic */ + printf("\nTesting basic arithmetic:\n"); + const char* source1 = "5 + 3"; + ExecResult result1; + Value value1 = baba_yaga_execute(interp, source1, strlen(source1), &result1); + + if (result1 == EXEC_SUCCESS) { + char* str1 = baba_yaga_value_to_string(&value1); + printf(" %s = %s\n", source1, str1); + free(str1); + baba_yaga_value_destroy(&value1); + } else { + printf(" Failed to execute: %s\n", source1); + } + + /* Test variable declaration */ + printf("\nTesting variable declaration:\n"); + const char* source2 = "x = 42"; + ExecResult result2; + Value value2 = baba_yaga_execute(interp, source2, strlen(source2), &result2); + + if (result2 == EXEC_SUCCESS) { + char* str2 = baba_yaga_value_to_string(&value2); + printf(" %s = %s\n", source2, str2); + free(str2); + baba_yaga_value_destroy(&value2); + } else { + printf(" Failed to execute: %s\n", source2); + } + + /* Test variable access */ + printf("\nTesting variable access:\n"); + const char* source3 = "x"; + ExecResult result3; + Value value3 = baba_yaga_execute(interp, source3, strlen(source3), &result3); + + if (result3 == EXEC_SUCCESS) { + char* str3 = baba_yaga_value_to_string(&value3); + printf(" %s = %s\n", source3, str3); + free(str3); + baba_yaga_value_destroy(&value3); + } else { + printf(" Failed to execute: %s\n", source3); + } + + /* Test standard library functions */ + printf("\nTesting standard library functions:\n"); + const char* source4 = "out(42)"; + ExecResult result4; + Value value4 = baba_yaga_execute(interp, source4, strlen(source4), &result4); + + if (result4 == EXEC_SUCCESS) { + char* str4 = baba_yaga_value_to_string(&value4); + printf(" %s = %s\n", source4, str4); + free(str4); + baba_yaga_value_destroy(&value4); + } else { + printf(" Failed to execute: %s\n", source4); + } + + /* Cleanup */ + baba_yaga_destroy(interp); + printf("\nā Interpreter destroyed successfully\n"); + + printf("\nā All interpreter tests completed!\n"); + return 0; +} |