adding hello_test

This commit is contained in:
Josh 2024-10-23 20:44:51 -07:00
parent 3866859c3f
commit 052152c251
1 changed files with 34 additions and 39 deletions

View File

@ -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);