Started lexer tests
This commit is contained in:
parent
cdfbab75c2
commit
78837fafd3
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
const char *TEST_FILE_NAME = "TEST_FILE.SLS";
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
uint8_t success;
|
uint8_t success;
|
||||||
|
|
@ -15,7 +17,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *section;
|
const char *section;
|
||||||
size_t tests;
|
size_t count;
|
||||||
TestResult* tests;
|
TestResult* tests;
|
||||||
} TestsReport;
|
} TestsReport;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,51 @@
|
||||||
// Lexer Tests
|
// Lexer Tests
|
||||||
// October 2025
|
// October 2025
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue