diff options
| author | hachem <im@hachem.wtf> | 2026-09-08 12:16:51 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-08 12:16:51 +0200 |
| commit | 60c0e084b159801a45570b56f152f0f5e9193d72 (patch) | |
| tree | ad6c72d6782ab5d9edff336e1e852ca7b995bcdc /tests/parser_test.c | |
| parent | 9d47486aac9cd1a4422b78ee273b7a27bf7b733a (diff) | |
feat: add while loops
Diffstat (limited to 'tests/parser_test.c')
| -rw-r--r-- | tests/parser_test.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/parser_test.c b/tests/parser_test.c index b51093e..88e32a1 100644 --- a/tests/parser_test.c +++ b/tests/parser_test.c @@ -225,6 +225,26 @@ static void test_parse_else_if(struct TestContext* context) free_program(&program); } +static void test_parse_while(struct TestContext* context) +{ + struct Lexer lexer = create_lexer( + "proc main\n{\nwhile rcx > 0\n{\nrbx += rcx\nrcx -= 1\n}\n}\n"); + struct Program program; + + check(context, parse_program(&lexer, &program)); + check(context, program.procs[0].body_count == 1); + + struct Statement loop = program.procs[0].body[0]; + check(context, loop.kind == STATEMENT_WHILE); + check(context, primary_is(loop.loop.left, "rcx")); + check(context, text_is(loop.loop.comparison, ">")); + check(context, primary_is(loop.loop.right, "0")); + check(context, loop.loop.body_count == 2); + check(context, text_is(loop.loop.body[1].assign.target, "rcx")); + + free_program(&program); +} + static void test_parse_call(struct TestContext* context) { struct Lexer lexer = create_lexer("proc main\n{\nprint_number(r12)\nf(a, b)\n}\n"); @@ -396,6 +416,7 @@ void run_parser_tests(struct TestContext* context) test_parse_if(context); test_parse_if_block(context); test_parse_else_if(context); + test_parse_while(context); test_parse_call(context); test_parse_stack(context); test_parse_sized_deref(context); |
