From ac108c6bc8dfd84cc658e6634aee6308277b63ca Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 31 Oct 2024 09:05:35 -0700 Subject: [PATCH] adding print and branch --- lab-4/main_test.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lab-4/main_test.c b/lab-4/main_test.c index c567091..057bed9 100644 --- a/lab-4/main_test.c +++ b/lab-4/main_test.c @@ -55,4 +55,31 @@ UTEST(parser, hello) { // Assert the result to test correctness ASSERT_EQ(result, 0); } - \ No newline at end of file + +UTEST(parser, print) { + // Must include the null character to terminate input + char string[] = "DISPLAY 'Hello World!'\0"; + YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); + + yylineno = 1; + int result = yyparse(); + + yy_delete_buffer(buffer); + + // Assert the result to test correctness + ASSERT_EQ(result, 0); +} + +UTEST(parser, branching) { + // Must include the null character to terminate input + char string[] = "IF A > B THEN DISPLAY 'A is greater than B' ELSE DISPLAY 'B is greater than A'\0"; + YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); + + yylineno = 1; + int result = yyparse(); + + yy_delete_buffer(buffer); + + // Assert the result to test correctness + ASSERT_EQ(result, 0); +} \ No newline at end of file