From 052152c251cc1e5a183d43b7b0a898125d1e1322 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 23 Oct 2024 20:44:51 -0700 Subject: [PATCH] adding hello_test --- lab-3/main_test.c | 73 ++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/lab-3/main_test.c b/lab-3/main_test.c index 32a4bbf..946a6bd 100644 --- a/lab-3/main_test.c +++ b/lab-3/main_test.c @@ -18,57 +18,52 @@ struct token_st { char *p; }; -UTEST(scanner, identifier) { - token_t t; - // Must include the null character to terminate input - char string[] = "test\0"; - YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); +// UTEST(scanner, identifier) { +// token_t t; +// // Must include the null character to terminate input +// char string[] = "test\0"; +// YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); - ASSERT_EQ(TOKEN_IDENT, (t = yylex())); - ASSERT_STREQ("test", yytext); +// ASSERT_EQ(TOKEN_EOF, (t = yylex())); +// ASSERT_STREQ("", yytext); - ASSERT_EQ(TOKEN_EOF, (t = yylex())); - ASSERT_STREQ("", yytext); +// yy_delete_buffer(buffer); +// } - yy_delete_buffer(buffer); -} +// UTEST(scanner, assignment) { +// token_t t; +// // Must include the null character to terminate input +// char string[] = "=\0"; +// YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); -UTEST(scanner, assignment) { - token_t t; - // Must include the null character to terminate input - char string[] = "=\0"; - YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string)); +// ASSERT_EQ(TOKEN_EOF, (t = yylex())); +// ASSERT_STREQ("", yytext); - ASSERT_EQ(TOKEN_ASSIGNMENT, (t = yylex())); - ASSERT_STREQ("=", yytext); - - ASSERT_EQ(TOKEN_EOF, (t = yylex())); - ASSERT_STREQ("", yytext); - - yy_delete_buffer(buffer); -} +// yy_delete_buffer(buffer); +// } UTEST(scanner, hello) { struct token_st tokens[] = { {TOKEN_IDENTIFICATION, "IDENTIFICATION"}, - {TOKEN_PROGRAM_ID, "PROGRAM-ID. HELLO-WORLD."} - {TOKEN_PROCEDURE_DIVISION, "PROCEDURE DIVISION."}, - {TOKEN_STRING, "Hello World!"}, - {TOKEN_KEYWORD_PRINT, "DISPLAY"}, - {TOKEN_EOF, "STOP RUN."}, + {TOKEN_KEYWORD_DIVISION, "DIVISION"}, + {TOKEN_DOT, "."}, + {TOKEN_PROGRAM_ID, "PROGRAM-ID"}, + {TOKEN_DOT, "."}, + {TOKEN_IDENT, "HELLO-WORLD"}, + {TOKEN_DOT, "."}, + {TOKEN_PROCEDURE, "PROCEDURE"}, + {TOKEN_KEYWORD_DIVISION, "DIVISION"}, + {TOKEN_DOT, "."}, + {TOKEN_DISPLAY, "DISPLAY"}, + {TOKEN_STRING, "'Hello World!'"}, + {TOKEN_STOP, "STOP"}, + {TOKEN_RUN, "RUN"}, + {TOKEN_DOT, "."}, + {TOKEN_EOF, ""}, }; -UTEST(scanner, sample) { - struct token_st tokens[] = { - {TOKEN_IDENT, "answer"}, - {TOKEN_ASSIGNMENT, "="}, - {TOKEN_NUMBER, "2020"}, - {TOKEN_ADD, "+"}, - {TOKEN_NUMBER, "4"}, - {TOKEN_EOF, ""} - }; - yyin = fopen("samples/program.c", "r"); + yyin = fopen("samples/hello-world.cbl", "r"); yyrestart(yyin); ASSERT_TRUE(yyin);