Convert codebase to C89 compatibility and update test scripts
This commit is contained in:
+29
-19
@@ -9,15 +9,19 @@ static void test_tokenstream_open_fail(void) {
|
||||
}
|
||||
|
||||
static void test_tokenstream_simple_keyword(void) {
|
||||
TokenStream* ts = tokenstream_open("test.c", "module");
|
||||
TokenStream* ts;
|
||||
Token t;
|
||||
Token eof;
|
||||
|
||||
Token t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_MODULE) fail("expected TOKEN_MODULE");
|
||||
ts = tokenstream_open("test.c", "module");
|
||||
|
||||
Token eof = tokenstream_next(ts);
|
||||
if (eof.token != TOKEN_EOF) fail("expected EOF");
|
||||
t = tokenstream_next(ts);
|
||||
if (t.token != TOKEN_MODULE) fail("expected TOKEN_MODULE");
|
||||
|
||||
tokenstream_close(ts);
|
||||
eof = tokenstream_next(ts);
|
||||
if (eof.token != TOKEN_EOF) fail("expected EOF");
|
||||
|
||||
tokenstream_close(ts);
|
||||
}
|
||||
|
||||
static void test_tokenstream_keywords_and_symbols(void) {
|
||||
@@ -93,29 +97,35 @@ static void test_tokenstream_unknown_token(void) {
|
||||
}
|
||||
|
||||
static void test_tokenstream_info(void) {
|
||||
TokenStream* ts = tokenstream_open("test.c", "module main;");
|
||||
TokenStream* ts;
|
||||
Token t1;
|
||||
Token t2;
|
||||
char* buf1;
|
||||
char* buf2;
|
||||
|
||||
Token t1 = tokenstream_next(ts);
|
||||
if (t1.token != TOKEN_MODULE) fail("expected TOKEN_MODULE");
|
||||
|
||||
char* buf1 = malloc((size_t)t1.text.length + 1);
|
||||
ts = tokenstream_open("test.c", "module main;");
|
||||
|
||||
t1 = tokenstream_next(ts);
|
||||
if (t1.token != TOKEN_MODULE) fail("expected TOKEN_MODULE");
|
||||
|
||||
buf1 = malloc((size_t)t1.text.length + 1);
|
||||
if (!buf1) fail("out of memory");
|
||||
memcpy(buf1, t1.text.data, t1.text.length);
|
||||
buf1[t1.text.length] = '\0';
|
||||
assert_str("module", buf1, "info: expected 'module'");
|
||||
if (t1.location.line != 1) fail("expected line 1");
|
||||
if (t1.location.column_start != 1) fail("expected column 1");
|
||||
if (t1.location.line != 1) fail("expected line 1");
|
||||
if (t1.location.column_start != 1) fail("expected column 1");
|
||||
|
||||
Token t2 = tokenstream_next(ts);
|
||||
if (t2.token != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER");
|
||||
|
||||
char* buf2 = malloc((size_t)t2.text.length + 1);
|
||||
t2 = tokenstream_next(ts);
|
||||
if (t2.token != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER");
|
||||
|
||||
buf2 = malloc((size_t)t2.text.length + 1);
|
||||
if (!buf2) { free(buf1); fail("out of memory"); }
|
||||
memcpy(buf2, t2.text.data, t2.text.length);
|
||||
buf2[t2.text.length] = '\0';
|
||||
assert_str("main", buf2, "info: expected 'main'");
|
||||
if (t2.location.line != 1) fail("expected line 1");
|
||||
if (t2.location.column_start != 8) fail("expected column 8");
|
||||
if (t2.location.line != 1) fail("expected line 1");
|
||||
if (t2.location.column_start != 8) fail("expected column 8");
|
||||
|
||||
free(buf1);
|
||||
free(buf2);
|
||||
|
||||
Reference in New Issue
Block a user