aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-30 04:59:36 +0200
committerhachem <im@hachem.wtf>2026-08-30 04:59:36 +0200
commit4ffc0c48d0823bcc48bf88aed67324b6266810c5 (patch)
tree063423b929c62999c0413fd426664a2757b5683a /tests
parentdd6f0ff9bf51c4085bc9cde4955a2a6b5f83cde7 (diff)
add: parse assignment statements into procedures
Diffstat (limited to 'tests')
-rw-r--r--tests/parser_test.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/tests/parser_test.c b/tests/parser_test.c
index 14eacc9..85626a0 100644
--- a/tests/parser_test.c
+++ b/tests/parser_test.c
@@ -55,14 +55,30 @@ static void test_parse_proc_params(struct TestContext* context)
free_program(&program);
}
-static void test_parse_proc_body_skipped(struct TestContext* context)
+static void test_parse_proc_body(struct TestContext* context)
{
- struct Lexer lexer = create_lexer("proc main\n{\nrax = 1\nsyscall\n}\n");
+ struct Lexer lexer = create_lexer("proc main\n{\nrax = 1\nrcx -= 1\n^rsi = rdx\n}\n");
struct Program program;
check(context, parse_program(&lexer, &program));
check(context, program.proc_count == 1);
- check(context, program.procs[0].param_count == 0);
+ check(context, program.procs[0].body_count == 3);
+
+ struct Statement first = program.procs[0].body[0];
+ check(context, first.kind == STATEMENT_ASSIGN);
+ check(context, !first.assign.target_deref);
+ check(context, text_is(first.assign.target, "rax"));
+ check(context, text_is(first.assign.op, "="));
+ check(context, text_is(first.assign.value, "1"));
+
+ struct Statement second = program.procs[0].body[1];
+ check(context, text_is(second.assign.target, "rcx"));
+ check(context, text_is(second.assign.op, "-="));
+
+ struct Statement third = program.procs[0].body[2];
+ check(context, third.assign.target_deref);
+ check(context, text_is(third.assign.target, "rsi"));
+ check(context, text_is(third.assign.value, "rdx"));
free_program(&program);
}
@@ -89,6 +105,6 @@ void run_parser_tests(struct TestContext* context)
test_parse_consts(context);
test_parse_data(context);
test_parse_proc_params(context);
- test_parse_proc_body_skipped(context);
+ test_parse_proc_body(context);
test_parse_errors(context);
}