- Change header guard from `__SMCC_LEX_PARSER_H__` to `__SCC_LEX_PARSER_H__` - Prefix all lexer functions with `scc_` (e.g., `lex_parse_char` → `scc_lex_parse_char`) - Add new helper function `scc_lex_parse_is_identifier_header` - Update references in source and test files to use new function names - Replace `core_stream_eof` with `scc_stream_eof` for consistency
61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
// test_char.c
|
|
#include <lex_parser.h>
|
|
#include <utest/acutest.h>
|
|
|
|
cbool check_char(const char *str, int expect, int *output) {
|
|
log_set_level(&__default_logger_root, 0);
|
|
scc_pos_t pos = scc_pos_init();
|
|
scc_mem_probe_stream_t mem_stream;
|
|
scc_probe_stream_t *stream =
|
|
scc_mem_probe_stream_init(&mem_stream, str, scc_strlen(str), false);
|
|
*output = scc_lex_parse_char(stream, &pos);
|
|
return *output == expect;
|
|
}
|
|
|
|
#define CHECK_CHAR_VALID(str, expect) \
|
|
do { \
|
|
int _output; \
|
|
cbool ret = check_char(str, expect, &_output); \
|
|
TEST_CHECK(ret == true); \
|
|
} while (0)
|
|
|
|
#define CHECK_CHAR_INVALID(str) \
|
|
do { \
|
|
int _output; \
|
|
check_char(str, scc_stream_eof, &_output); \
|
|
TEST_CHECK(_output == scc_stream_eof); \
|
|
} while (0)
|
|
|
|
void test_simple_char(void) {
|
|
TEST_CASE("simple chars");
|
|
CHECK_CHAR_VALID("'a'", 'a');
|
|
CHECK_CHAR_VALID("'Z'", 'Z');
|
|
CHECK_CHAR_VALID("'0'", '0');
|
|
CHECK_CHAR_VALID("' '", ' ');
|
|
}
|
|
|
|
void test_escape_char(void) {
|
|
TEST_CASE("escape chars");
|
|
CHECK_CHAR_VALID("'\\n'", '\n');
|
|
CHECK_CHAR_VALID("'\\t'", '\t');
|
|
CHECK_CHAR_VALID("'\\r'", '\r');
|
|
CHECK_CHAR_VALID("'\\\\'", '\\');
|
|
CHECK_CHAR_VALID("'\\''", '\'');
|
|
CHECK_CHAR_VALID("'\\\"'", '\"');
|
|
}
|
|
|
|
void test_invalid_char(void) {
|
|
TEST_CASE("invalid chars");
|
|
CHECK_CHAR_INVALID("'");
|
|
CHECK_CHAR_INVALID("''");
|
|
CHECK_CHAR_INVALID("'ab'");
|
|
CHECK_CHAR_INVALID("'\\'");
|
|
}
|
|
|
|
TEST_LIST = {
|
|
{"test_simple_char", test_simple_char},
|
|
{"test_escape_char", test_escape_char},
|
|
{"test_invalid_char", test_invalid_char},
|
|
{NULL, NULL},
|
|
};
|