fix tests
This commit is contained in:
parent
d20a11d829
commit
d04c690652
|
|
@ -8,7 +8,7 @@ extern char *yytext;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
FILE *file;
|
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
|
// Check if a filename is provided as a command-line argument
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
|
|
||||||
|
|
@ -18,36 +18,6 @@ struct token_st {
|
||||||
char *p;
|
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) {
|
UTEST(scanner, hello) {
|
||||||
struct token_st tokens[] = {
|
struct token_st tokens[] = {
|
||||||
{TOKEN_IDENTIFICATION, "IDENTIFICATION"},
|
{TOKEN_IDENTIFICATION, "IDENTIFICATION"},
|
||||||
|
|
@ -68,23 +38,12 @@ UTEST(scanner, hello) {
|
||||||
{TOKEN_EOF, ""},
|
{TOKEN_EOF, ""},
|
||||||
};
|
};
|
||||||
|
|
||||||
UTEST(scanner, sample) {
|
yyin = fopen("samples/hello-world.cbl", "r");
|
||||||
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);
|
|
||||||
ASSERT_TRUE(yyin);
|
ASSERT_TRUE(yyin);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
token_t t;
|
token_t t;
|
||||||
do {
|
do {
|
||||||
|
printf("index: %d token: %d text: %s\n", index, t, yytext);
|
||||||
ASSERT_EQ(tokens[index].t, (t = yylex()));
|
ASSERT_EQ(tokens[index].t, (t = yylex()));
|
||||||
ASSERT_STREQ(tokens[index].p, yytext);
|
ASSERT_STREQ(tokens[index].p, yytext);
|
||||||
++index;
|
++index;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
%}
|
%}
|
||||||
NAME [a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?
|
NAME [a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?
|
||||||
DIGIT [0-9]+
|
DIGIT [0-9]+
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
(" "|\t|\n) /* skip whitespace */
|
(" "|\t|\n) /* skip whitespace */
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ typedef enum {
|
||||||
|
|
||||||
// Identifiers
|
// Identifiers
|
||||||
TOKEN_IDENT,
|
TOKEN_IDENT,
|
||||||
|
|
||||||
// Data types
|
// Data types
|
||||||
TOKEN_STRING,
|
TOKEN_STRING,
|
||||||
TOKEN_INTEGER,
|
TOKEN_INTEGER,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue