diff --git a/SLS_C/include/tests/tests.h b/SLS_C/include/tests/tests.h index a9933a9..023330a 100644 --- a/SLS_C/include/tests/tests.h +++ b/SLS_C/include/tests/tests.h @@ -8,6 +8,8 @@ #include +const char *TEST_FILE_NAME = "TEST_FILE.SLS"; + typedef struct { const char *name; uint8_t success; @@ -15,7 +17,7 @@ typedef struct { typedef struct { const char *section; - size_t tests; + size_t count; TestResult* tests; } TestsReport; diff --git a/SLS_C/tests/lexer_tests.c b/SLS_C/tests/lexer_tests.c index af92fce..548c61a 100644 --- a/SLS_C/tests/lexer_tests.c +++ b/SLS_C/tests/lexer_tests.c @@ -3,4 +3,51 @@ // Lexer Tests // October 2025 +#include +#include +#include "sls/sls_errors.h" +#include "sls/lexer.h" +#include "tests/tests.h" + +static const size_t NUM_OF_TESTS = 1; + +static LexerInfo start_up_test(const char *code) { + LexerInfo lexer_info; + lexer_init(&lexer_info, TEST_FILE_NAME, code); + return lexer_info; +} + +static void clean_up_test(LexerResult result) { + if (result.type == SLS_RESULT) + clean_token_result(result.result); +} + +static TestResult test_add_statement() { + TestResult test_result = (TestResult){ .name = "test_add_statement", .success = 0 }; + LexerInfo lexer_info = start_up_test("3 4 +"); + + LexerResult result = lexical_analysis(&lexer_info); + + if (result.type == SLS_ERROR) { + clean_up_test(result); + return test_result; + } + // TODO: Finish Test + + clean_up_test(result); + test_result.success = 1; + return test_result; +} + +TestsReport run_lexer_tests() { + TestsReport test_report = (TestsReport){ + .section = "lexer_tests", + .count = NUM_OF_TESTS, + .tests = malloc(sizeof(TestResult) * NUM_OF_TESTS), + }; + + test_report.tests[0] = test_add_statement(); + + return test_report; +}