Implement token.c with comprehensive tests and easy-to-modify token mapping
- Created token-to-string mapping array parallel to Token enum in token.c - Implemented TokenStream with lookahead buffering for proper tokenization - Implemented tokenstream_open/close/next functions with support for: - Keywords (module, import, void) - Symbols (parentheses, brackets, comma, semicolon) - Identifiers (alphanumeric starting with letter or underscore) - Comment skipping (// style) - Whitespace handling - Added token_to_string function to token.h for token inspection - Created comprehensive test suite (15 tests) covering all token types and edge cases - All tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@ typedef struct {
|
||||
} TestCase;
|
||||
|
||||
#include "test_buffer.c"
|
||||
#include "test_token.c"
|
||||
|
||||
static int s_totalTests;
|
||||
static int s_greenTests;
|
||||
@@ -27,8 +28,19 @@ static TestCase s_tests[] = {
|
||||
{"buffer_string_eof_after_content", test_buffer_string_eof_after_content},
|
||||
{"buffer_file_reads_chars", test_buffer_file_reads_chars},
|
||||
{"buffer_file_open_fail", test_buffer_file_open_fail},
|
||||
{"token_to_string_keywords", test_token_to_string_keywords},
|
||||
{"token_to_string_symbols", test_token_to_string_symbols},
|
||||
{"token_to_string_identifier", test_token_to_string_identifier},
|
||||
{"tokenstream_open_fail", test_tokenstream_open_fail},
|
||||
{"tokenstream_simple_keyword", test_tokenstream_simple_keyword},
|
||||
{"tokenstream_keywords_and_symbols", test_tokenstream_keywords_and_symbols},
|
||||
{"tokenstream_parentheses_and_brackets", test_tokenstream_parentheses_and_brackets},
|
||||
{"tokenstream_comma", test_tokenstream_comma},
|
||||
{"tokenstream_whitespace_ignored", test_tokenstream_whitespace_ignored},
|
||||
{"tokenstream_void_function_signature", test_tokenstream_void_function_signature},
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
Reference in New Issue
Block a user