So i did what the last commit said, also fixed parse_expr because it was still using malloc for allocating new nodes so i made it use arena_alloc like it should, did the very first tests so it's all good, i think is readdy to merge.
33 lines
674 B
C
33 lines
674 B
C
#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);
|
|
ParseResult result = parse(&context);
|
|
int64_t value = evaluate(result);
|
|
|
|
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;
|
|
}
|