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>
This commit is contained in:
@@ -8,10 +8,7 @@ static void test_tokenstream_open_fail(void) {
|
|||||||
|
|
||||||
static void test_tokenstream_simple_keyword(void) {
|
static void test_tokenstream_simple_keyword(void) {
|
||||||
Buffer* buf = buffer_open_string("module");
|
Buffer* buf = buffer_open_string("module");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
TokenStream* ts = tokenstream_open(buf);
|
||||||
if (ts == NULL) fail("could not create tokenstream");
|
|
||||||
|
|
||||||
Token t = tokenstream_next(ts);
|
Token t = tokenstream_next(ts);
|
||||||
if (t != TOKEN_MODULE) fail("expected TOKEN_MODULE");
|
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) {
|
static void test_tokenstream_keywords_and_symbols(void) {
|
||||||
Buffer* buf = buffer_open_string("module main; import stdio;");
|
Buffer* buf = buffer_open_string("module main; import stdio;");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
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_MODULE) fail("expected TOKEN_MODULE");
|
||||||
if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER (main)");
|
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) {
|
static void test_tokenstream_parentheses_and_brackets(void) {
|
||||||
Buffer* buf = buffer_open_string("()[]");
|
Buffer* buf = buffer_open_string("()[]");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
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_OPEN) fail("expected TOKEN_PARENT_OPEN");
|
||||||
if (tokenstream_next(ts) != TOKEN_PARENT_CLOSE) fail("expected TOKEN_PARENT_CLOSE");
|
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) {
|
static void test_tokenstream_comma(void) {
|
||||||
Buffer* buf = buffer_open_string("a,b,c");
|
Buffer* buf = buffer_open_string("a,b,c");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
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_IDENTIFIER) fail("expected a");
|
||||||
if (tokenstream_next(ts) != TOKEN_COMMA) fail("expected comma");
|
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) {
|
static void test_tokenstream_whitespace_ignored(void) {
|
||||||
Buffer* buf = buffer_open_string(" module \n\t import ; ");
|
Buffer* buf = buffer_open_string(" module \n\t import ; ");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
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_MODULE) fail("expected TOKEN_MODULE");
|
||||||
if (tokenstream_next(ts) != TOKEN_IMPORT) fail("expected TOKEN_IMPORT");
|
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) {
|
static void test_tokenstream_void_function_signature(void) {
|
||||||
Buffer* buf = buffer_open_string("void main()");
|
Buffer* buf = buffer_open_string("void main()");
|
||||||
if (buf == NULL) fail("could not create buffer");
|
|
||||||
|
|
||||||
TokenStream* ts = tokenstream_open(buf);
|
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_VOID) fail("expected TOKEN_VOID");
|
||||||
if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER");
|
if (tokenstream_next(ts) != TOKEN_IDENTIFIER) fail("expected TOKEN_IDENTIFIER");
|
||||||
|
|||||||
Reference in New Issue
Block a user