Files
scc/libs/lex_parser/tests/test_char.c
zzy d88fa3b8d3 feat: rename core types to scc prefix for consistency
Updated type names from `core_*` to `scc_*` across lex_parser and stream modules to maintain naming consistency within the SCC codebase. This includes changes to function signatures and internal usage of types like `core_probe_stream_t`, `core_pos_t`, and `cstring_t` to their `scc_*` counterparts.
2025-12-11 13:00:29 +08:00

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 = 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, core_stream_eof, &_output); \
TEST_CHECK(_output == core_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},
};