Minimal build of the refstrings in the literal structure

This commit is contained in:
2022-11-23 12:52:49 +00:00
parent c7465e1204
commit 923cf70c06
21 changed files with 186 additions and 75 deletions

49
test/xtest_lexer.c Normal file
View File

@@ -0,0 +1,49 @@
#include "lexer.h"
#include "console_colors.h"
#include <stdio.h>
#include <string.h>
int main() {
{
//source
char* source = "print null;";
//test init & quit
Lexer lexer;
initLexer(&lexer, source);
//get each token
Token print = scanLexer(&lexer);
Token null = scanLexer(&lexer);
Token semi = scanLexer(&lexer);
Token eof = scanLexer(&lexer);
//test each token is correct
if (strncmp(print.lexeme, "print", print.length)) {
fprintf(stderr, ERROR "ERROR: print lexeme is wrong: %s" RESET, print.lexeme);
return -1;
}
if (strncmp(null.lexeme, "null", null.length)) {
fprintf(stderr, ERROR "ERROR: null lexeme is wrong: %s" RESET, null.lexeme);
return -1;
}
if (strncmp(semi.lexeme, ";", semi.length)) {
fprintf(stderr, ERROR "ERROR: semicolon lexeme is wrong: %s" RESET, semi.lexeme);
return -1;
}
if (eof.type != TOKEN_EOF) {
fprintf(stderr, ERROR "ERROR: Failed to find EOF token" RESET);
return -1;
}
}
printf(NOTICE "All good\n" RESET);
return 0;
}