diff --git a/v0/test_token.c b/v0/test_token.c index af8c14b..81d9325 100644 --- a/v0/test_token.c +++ b/v0/test_token.c @@ -1,30 +1,14 @@ #include "test.h" #include "token.h" -#include -#include -#include - -/* Helper to create a test file with content */ -static void write_test_file(const char* filename, const char* content) { - FILE* f = fopen(filename, "w"); - if (f) { - fputs(content, f); - fclose(f); - } -} static void test_tokenstream_open_fail(void) { - Buffer* buf = buffer_open_file("v0/does_not_exist.c2"); - if (buf != NULL) fail("expected NULL for non-existent file"); - - TokenStream* ts = tokenstream_open(buf); + TokenStream* ts = tokenstream_open(NULL); if (ts != NULL) fail("expected NULL for NULL buffer"); } static void test_tokenstream_simple_keyword(void) { - write_test_file("v0/test_token_tmp.c2", "module"); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string("module"); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream"); @@ -39,9 +23,8 @@ static void test_tokenstream_simple_keyword(void) { } static void test_tokenstream_keywords_and_symbols(void) { - write_test_file("v0/test_token_tmp.c2", "module main; import stdio;"); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string("module main; import stdio;"); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream"); @@ -58,9 +41,8 @@ static void test_tokenstream_keywords_and_symbols(void) { } static void test_tokenstream_parentheses_and_brackets(void) { - write_test_file("v0/test_token_tmp.c2", "()[]"); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string("()[]"); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream"); @@ -75,9 +57,8 @@ static void test_tokenstream_parentheses_and_brackets(void) { } static void test_tokenstream_comma(void) { - write_test_file("v0/test_token_tmp.c2", "a,b,c"); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string("a,b,c"); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream"); @@ -93,9 +74,8 @@ static void test_tokenstream_comma(void) { } static void test_tokenstream_whitespace_ignored(void) { - write_test_file("v0/test_token_tmp.c2", " module \n\t import ; "); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string(" module \n\t import ; "); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream"); @@ -109,9 +89,8 @@ static void test_tokenstream_whitespace_ignored(void) { } static void test_tokenstream_void_function_signature(void) { - write_test_file("v0/test_token_tmp.c2", "void main()"); - Buffer* buf = buffer_open_file("v0/test_token_tmp.c2"); - if (buf == NULL) fail("could not open file"); + Buffer* buf = buffer_open_string("void main()"); + if (buf == NULL) fail("could not create buffer"); TokenStream* ts = tokenstream_open(buf); if (ts == NULL) fail("could not create tokenstream");