summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lexer_test.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/test/lexer_test.c b/test/lexer_test.c
index 3c43342..87928b4 100644
--- a/test/lexer_test.c
+++ b/test/lexer_test.c
@@ -17,6 +17,7 @@
#define MUNIT_ENABLE_ASSERT_ALIASES
#include "lexer.h"
#include "munit.h"
+#include <stdio.h>
void
make_lexer_from_static_src(lexer_t *lexer, char *src)
@@ -88,17 +89,21 @@ test_tokenize_name(const MunitParameter params[], void *user_data_or_fixture)
}
static MunitResult
-test_tokenize_op(const MunitParameter params[], void *user_data_or_fixture)
+test_tokenize_basic_check(const MunitParameter params[], void *user_data_or_fixture)
{
assert_token_at(" + 2", 0, TOKEN_PLUS, "+");
assert_token_at(" - \n", 0, TOKEN_MINUS, "-");
assert_token_at(" * ;", 0, TOKEN_STAR, "*");
assert_token_at(" / ", 0, TOKEN_SLASH, "/");
- assert_token_at(" = ", 0, TOKEN_EQUAL, "=");
- assert_token_at("1 * 2", 0, TOKEN_NUMBER, "1");
- assert_token_at("1 * 2", 1, TOKEN_STAR, "*");
- assert_token_at("1 * 2", 2, TOKEN_NUMBER, "2");
+ for (size_t kind = TOKEN_OPAREN; kind < TOKEN_UNKNOWN; kind++) {
+ char source[128];
+ sprintf(source, "1 %s 2", token_kind_to_str(kind));
+
+ assert_token_at(source, 0, TOKEN_NUMBER, "1");
+ assert_token_at(source, 1, kind, token_kind_to_str(kind));
+ assert_token_at(source, 2, TOKEN_NUMBER, "2");
+ }
return MUNIT_OK;
}
@@ -134,7 +139,7 @@ static MunitTest tests[] = {
{ "/test_tokenize_digit", test_tokenize_number, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ "/test_tokenize_keywords", test_tokenize_keywords, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ "/test_tokenize_name", test_tokenize_name, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
- { "/test_tokenize_op", test_tokenize_op, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
+ { "/test_tokenize_basic_check", test_tokenize_basic_check, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ "/test_tokenize_unknown", test_tokenize_unknown, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ "/test_peek_next_token", test_peek_next_token, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }