From f03fe9939545df520c856b639c27dd40d8a09161 Mon Sep 17 00:00:00 2001 From: Jenessy Lustre Date: Thu, 7 Nov 2024 11:47:26 -0800 Subject: [PATCH] lab4 tests --- lab-4/main_test.c | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/lab-4/main_test.c b/lab-4/main_test.c index 29f238e..d82f3eb 100644 --- a/lab-4/main_test.c +++ b/lab-4/main_test.c @@ -14,7 +14,6 @@ extern int yylineno; UTEST_MAIN(); - UTEST(parser, math) { // Must include the null character to terminate input char string[] = "1+8/4-3;\0"; @@ -84,6 +83,32 @@ UTEST(parser, branching) { ASSERT_EQ(result, 0); } +UTEST(parser, looping) { + char string[] = "PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 MOVE I TO A(I)\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, sorting) { + // Read sample file as input + yyin = fopen("samples/sorting-snippet.cbl", "r"); + yyrestart(yyin); + ASSERT_TRUE(yyin); + + yylineno = 1; + int result = yyparse(); + + // Assert the result to test correctness + ASSERT_EQ(result, 0); +} + UTEST(parser, quadratic) { // Read sample file as input yyin = fopen("samples/quadratic-snippet.cbl", "r"); @@ -110,29 +135,3 @@ UTEST(parser, boolean) { // Assert the result to test correctness ASSERT_EQ(result, 0); } - -UTEST(parser, looping) { - char string[] = "PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 MOVE I TO A(I)\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, sorting) { - // Read sample file as input - yyin = fopen("samples/sorting-snippet.cbl", "r"); - yyrestart(yyin); - ASSERT_TRUE(yyin); - - yylineno = 1; - int result = yyparse(); - - // Assert the result to test correctness - ASSERT_EQ(result, 0); -}