hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/tests/lexer_test.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-12 11:41:05 +0200
committerhachem <im@hachem.wtf>2026-10-12 11:41:05 +0200
commit62636576bce8e8121a3d70f63547fae40a52f697 (patch)
tree077dfe4f04235cce63b7abb1b05bb539232ae74a /tests/lexer_test.c
parentc0f000ea166a24781fcdbf23c080b203cd9b8ed7 (diff)
chore: refactor
Diffstat (limited to 'tests/lexer_test.c')
-rw-r--r--tests/lexer_test.c111
1 files changed, 0 insertions, 111 deletions
diff --git a/tests/lexer_test.c b/tests/lexer_test.c
deleted file mode 100644
index 0810c3b..0000000
--- a/tests/lexer_test.c
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <string.h>
-#include <stdbool.h>
-
-#include "lexer.h"
-#include "tests.h"
-
-static bool token_matches(struct Token token, enum TokenType type, const char* text)
-{
- size_t length = strlen(text);
- return token.type == type
- && token.length == length
- && memcmp(token.start, text, length) == 0;
-}
-
-static void test_identifiers_and_integers(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("rax 42");
- check(context, token_matches(scan_token(&lexer), TOKEN_IDENTIFIER, "rax"));
- check(context, token_matches(scan_token(&lexer), TOKEN_INTEGER, "42"));
- check(context, scan_token(&lexer).type == TOKEN_EOF);
-}
-
-static void test_number_bases(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("42 0x1F 0b1010");
- check(context, token_matches(scan_token(&lexer), TOKEN_INTEGER, "42"));
- check(context, token_matches(scan_token(&lexer), TOKEN_INTEGER, "0x1F"));
- check(context, token_matches(scan_token(&lexer), TOKEN_INTEGER, "0b1010"));
-}
-
-static void test_float_literals(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("3.14 1.0 42");
- check(context, token_matches(scan_token(&lexer), TOKEN_FLOAT, "3.14"));
- check(context, token_matches(scan_token(&lexer), TOKEN_FLOAT, "1.0"));
- check(context, scan_token(&lexer).type == TOKEN_INTEGER);
-}
-
-static void test_operators(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("= == += != /");
- check(context, scan_token(&lexer).type == TOKEN_EQUAL);
- check(context, scan_token(&lexer).type == TOKEN_EQUAL_EQUAL);
- check(context, scan_token(&lexer).type == TOKEN_PLUS_EQUAL);
- check(context, scan_token(&lexer).type == TOKEN_BANG_EQUAL);
- check(context, scan_token(&lexer).type == TOKEN_SLASH);
-}
-
-static void test_literals(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("\"hi\\n\" '0'");
- check(context, token_matches(scan_token(&lexer), TOKEN_STRING, "\"hi\\n\""));
- check(context, token_matches(scan_token(&lexer), TOKEN_CHAR, "'0'"));
-}
-
-static void test_keywords(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("const proc mainly");
- check(context, scan_token(&lexer).type == TOKEN_CONST);
- check(context, scan_token(&lexer).type == TOKEN_PROC);
- check(context, scan_token(&lexer).type == TOKEN_IDENTIFIER);
-}
-
-static void test_size_keywords(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("byte word dword qword");
- check(context, scan_token(&lexer).type == TOKEN_BYTE);
- check(context, scan_token(&lexer).type == TOKEN_WORD);
- check(context, scan_token(&lexer).type == TOKEN_DWORD);
- check(context, scan_token(&lexer).type == TOKEN_QWORD);
-}
-
-static void test_enum_struct_keywords(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("enum struct");
- check(context, scan_token(&lexer).type == TOKEN_ENUM);
- check(context, scan_token(&lexer).type == TOKEN_STRUCT);
-}
-
-static void test_line_counting(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("a\nb\nc");
- check(context, scan_token(&lexer).line == 1);
- check(context, scan_token(&lexer).line == 2);
- check(context, scan_token(&lexer).line == 3);
-}
-
-static void test_comments(struct TestContext* context)
-{
- struct Lexer lexer = create_lexer("rax // line comment\n/* block\ncomment */ rbx");
- check(context, token_matches(scan_token(&lexer), TOKEN_IDENTIFIER, "rax"));
-
- struct Token second = scan_token(&lexer);
- check(context, token_matches(second, TOKEN_IDENTIFIER, "rbx"));
- check(context, second.line == 3);
- check(context, scan_token(&lexer).type == TOKEN_EOF);
-}
-
-void run_lexer_tests(struct TestContext* context)
-{
- test_identifiers_and_integers(context);
- test_number_bases(context);
- test_float_literals(context);
- test_operators(context);
- test_literals(context);
- test_keywords(context);
- test_size_keywords(context);
- test_enum_struct_keywords(context);
- test_line_counting(context);
- test_comments(context);
-}