It works, basic but works, need to move out logic to places, like ASTNode array shouldn't be on the lexer or future logic for fractions and error handling in the evaluator. Just the things at the top of my head

This commit is contained in:
2026-03-25 11:30:12 -06:00
parent 845673fb0e
commit 92d142b9cf
5 changed files with 67 additions and 28 deletions

32
test/test_evaluator.c Normal file
View File

@@ -0,0 +1,32 @@
#include "lexer.h"
#include "parser.h"
#include "evaluator.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
static void test_basic_evaluation(void** state) {
(void) state;
char expr[256] = "2 + 4 * 40 / 2";
ASTNodeArray context;
tokenize(expr, &context);
AST tree = parse(&context);
uint64_t value = evaluate(tree.head);
assert_int_equal(value, 82);
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_basic_evaluation),
};
cmocka_run_group_tests(tests, NULL, NULL);
return EXIT_SUCCESS;
}