diff options
| author | hachem <im@hachem.wtf> | 2026-08-30 13:42:31 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-30 13:42:31 +0200 |
| commit | deed096e783fca21b1773fa84c28be139a3c57ad (patch) | |
| tree | 6ea3743f5d26a130c25c2df1af1d33a0c916348e /tests/parser_test.c | |
| parent | 9e979a49b041a9d0e8ba6f8fee50bd11520169af (diff) | |
add: parse conditional expressions
Diffstat (limited to 'tests/parser_test.c')
| -rw-r--r-- | tests/parser_test.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/parser_test.c b/tests/parser_test.c index a0013a7..8856f4c 100644 --- a/tests/parser_test.c +++ b/tests/parser_test.c @@ -131,6 +131,25 @@ static void test_parse_expressions(struct TestContext* context) free_program(&program); } +static void test_parse_if(struct TestContext* context) +{ + struct Lexer lexer = create_lexer("proc main\n{\nif rax != 0\ngoto loop\n}\n"); + struct Program program; + + check(context, parse_program(&lexer, &program)); + check(context, program.procs[0].body_count == 1); + + struct Statement branch = program.procs[0].body[0]; + check(context, branch.kind == STATEMENT_IF); + check(context, primary_is(branch.branch.left, "rax")); + check(context, text_is(branch.branch.comparison, "!=")); + check(context, primary_is(branch.branch.right, "0")); + check(context, branch.branch.body->kind == STATEMENT_GOTO); + check(context, text_is(branch.branch.body->jump.label, "loop")); + + free_program(&program); +} + static void test_parse_errors(struct TestContext* context) { struct Program program; @@ -156,5 +175,6 @@ void run_parser_tests(struct TestContext* context) test_parse_proc_body(context); test_parse_simple_statements(context); test_parse_expressions(context); + test_parse_if(context); test_parse_errors(context); } |
