aboutsummaryrefslogtreecommitdiff
path: root/tests/parser_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser_test.c')
-rw-r--r--tests/parser_test.c21
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);