From 422203fdab1d424eea0df74e1e35274bf3871412 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Fri, 24 Apr 2026 11:04:05 +0200 Subject: [PATCH] Remove unnecessary NULL checks from token tests Since buffer_open_string() always succeeds and tokenstream_open() always succeeds when given a valid buffer, the NULL checks are unnecessary. This simplifies the test code and makes it more readable. All 12 tests still pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- v0/test_token.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/v0/test_token.c b/v0/test_token.c index 81d9325..1b0eff4 100644 --- a/v0/test_token.c +++ b/v0/test_token.c @@ -8,10 +8,7 @@ static void test_tokenstream_open_fail(void) { static void test_tokenstream_simple_keyword(void) { 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"); Token t = tokenstream_next(ts); if (t != TOKEN_MODULE) fail("expected TOKEN_MODULE"); @@ -24,10 +21,7 @@ static void test_tokenstream_simple_keyword(void) { static void test_tokenstream_keywords_and_symbols(void) { 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"); if (tokenstream_next(ts) != TOKEN_MODULE) fail("expected TOKEN_MODULE"); if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER (main)"); @@ -42,10 +36,7 @@ static void test_tokenstream_keywords_and_symbols(void) { static void test_tokenstream_parentheses_and_brackets(void) { 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"); if (tokenstream_next(ts) != TOKEN_PARENT_OPEN) fail("expected TOKEN_PARENT_OPEN"); if (tokenstream_next(ts) != TOKEN_PARENT_CLOSE) fail("expected TOKEN_PARENT_CLOSE"); @@ -58,10 +49,7 @@ static void test_tokenstream_parentheses_and_brackets(void) { static void test_tokenstream_comma(void) { 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"); if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected a"); if (tokenstream_next(ts) != TOKEN_COMMA) fail("expected comma"); @@ -75,10 +63,7 @@ static void test_tokenstream_comma(void) { static void test_tokenstream_whitespace_ignored(void) { 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"); if (tokenstream_next(ts) != TOKEN_MODULE) fail("expected TOKEN_MODULE"); if (tokenstream_next(ts) != TOKEN_IMPORT) fail("expected TOKEN_IMPORT"); @@ -90,10 +75,7 @@ static void test_tokenstream_whitespace_ignored(void) { static void test_tokenstream_void_function_signature(void) { 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"); if (tokenstream_next(ts) != TOKEN_VOID) fail("expected TOKEN_VOID"); if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER");