From d04c690652ef79910c7afcc12c5391e63c55d4a1 Mon Sep 17 00:00:00 2001 From: Riley Smith Date: Thu, 24 Oct 2024 11:20:41 -0700 Subject: [PATCH] fix tests --- lab-3/main.c | 2 +- lab-3/main_test.c | 45 ++------------------------------------------- lab-3/scanner.flex | 1 - lab-3/token.h | 1 + 4 files changed, 4 insertions(+), 45 deletions(-) diff --git a/lab-3/main.c b/lab-3/main.c index 0970031..59ddc86 100644 --- a/lab-3/main.c +++ b/lab-3/main.c @@ -8,7 +8,7 @@ extern char *yytext; int main(int argc, char *argv[]) { FILE *file; - const char *filename = "samples/quadratic-snippet.cbl"; // Default filename + const char *filename = "samples/hello-world.cbl"; // Default filename // Check if a filename is provided as a command-line argument if (argc > 1) { diff --git a/lab-3/main_test.c b/lab-3/main_test.c index 5407c9f..ac25b7e 100644 --- a/lab-3/main_test.c +++ b/lab-3/main_test.c @@ -18,36 +18,6 @@ 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)); - - ASSERT_EQ(TOKEN_IDENT, (t = yylex())); - ASSERT_STREQ("test", yytext); - - ASSERT_EQ(TOKEN_EOF, (t = yylex())); - ASSERT_STREQ("", yytext); - - 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)); - - ASSERT_EQ(TOKEN_ASSIGNMENT, (t = yylex())); - ASSERT_STREQ("=", yytext); - - ASSERT_EQ(TOKEN_EOF, (t = yylex())); - ASSERT_STREQ("", yytext); - - yy_delete_buffer(buffer); -} - UTEST(scanner, hello) { struct token_st tokens[] = { {TOKEN_IDENTIFICATION, "IDENTIFICATION"}, @@ -68,23 +38,12 @@ UTEST(scanner, hello) { {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"); - yyrestart(yyin); + yyin = fopen("samples/hello-world.cbl", "r"); ASSERT_TRUE(yyin); - int index = 0; token_t t; do { + printf("index: %d token: %d text: %s\n", index, t, yytext); ASSERT_EQ(tokens[index].t, (t = yylex())); ASSERT_STREQ(tokens[index].p, yytext); ++index; diff --git a/lab-3/scanner.flex b/lab-3/scanner.flex index e290bfc..4a3e7e4 100644 --- a/lab-3/scanner.flex +++ b/lab-3/scanner.flex @@ -3,7 +3,6 @@ %} NAME [a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])? DIGIT [0-9]+ - %% (" "|\t|\n) /* skip whitespace */ diff --git a/lab-3/token.h b/lab-3/token.h index 85bf604..8b40b70 100644 --- a/lab-3/token.h +++ b/lab-3/token.h @@ -31,6 +31,7 @@ typedef enum { // Identifiers TOKEN_IDENT, + // Data types TOKEN_STRING, TOKEN_INTEGER,