adding hello_test
This commit is contained in:
parent
3866859c3f
commit
052152c251
|
|
@ -18,57 +18,52 @@ struct token_st {
|
||||||
char *p;
|
char *p;
|
||||||
};
|
};
|
||||||
|
|
||||||
UTEST(scanner, identifier) {
|
// UTEST(scanner, identifier) {
|
||||||
token_t t;
|
// token_t t;
|
||||||
// Must include the null character to terminate input
|
// // Must include the null character to terminate input
|
||||||
char string[] = "test\0";
|
// char string[] = "test\0";
|
||||||
YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string));
|
// YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string));
|
||||||
|
|
||||||
ASSERT_EQ(TOKEN_IDENT, (t = yylex()));
|
// ASSERT_EQ(TOKEN_EOF, (t = yylex()));
|
||||||
ASSERT_STREQ("test", yytext);
|
// ASSERT_STREQ("", yytext);
|
||||||
|
|
||||||
ASSERT_EQ(TOKEN_EOF, (t = yylex()));
|
// yy_delete_buffer(buffer);
|
||||||
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));
|
||||||
|
|
||||||
UTEST(scanner, assignment) {
|
// ASSERT_EQ(TOKEN_EOF, (t = yylex()));
|
||||||
token_t t;
|
// ASSERT_STREQ("", yytext);
|
||||||
// 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()));
|
// yy_delete_buffer(buffer);
|
||||||
ASSERT_STREQ("=", yytext);
|
// }
|
||||||
|
|
||||||
ASSERT_EQ(TOKEN_EOF, (t = yylex()));
|
|
||||||
ASSERT_STREQ("", yytext);
|
|
||||||
|
|
||||||
yy_delete_buffer(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
UTEST(scanner, hello) {
|
UTEST(scanner, hello) {
|
||||||
struct token_st tokens[] = {
|
struct token_st tokens[] = {
|
||||||
{TOKEN_IDENTIFICATION, "IDENTIFICATION"},
|
{TOKEN_IDENTIFICATION, "IDENTIFICATION"},
|
||||||
{TOKEN_PROGRAM_ID, "PROGRAM-ID. HELLO-WORLD."}
|
{TOKEN_KEYWORD_DIVISION, "DIVISION"},
|
||||||
{TOKEN_PROCEDURE_DIVISION, "PROCEDURE DIVISION."},
|
{TOKEN_DOT, "."},
|
||||||
{TOKEN_STRING, "Hello World!"},
|
{TOKEN_PROGRAM_ID, "PROGRAM-ID"},
|
||||||
{TOKEN_KEYWORD_PRINT, "DISPLAY"},
|
{TOKEN_DOT, "."},
|
||||||
{TOKEN_EOF, "STOP RUN."},
|
{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);
|
yyrestart(yyin);
|
||||||
ASSERT_TRUE(yyin);
|
ASSERT_TRUE(yyin);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue