- 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
51 lines
1.6 KiB
C
51 lines
1.6 KiB
C
// test_skip_block_comment.c
|
|
#include <lex_parser.h>
|
|
#include <utest/acutest.h>
|
|
|
|
void check_skip_block_comment(const char *str, const char *expect_remaining) {
|
|
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);
|
|
|
|
scc_lex_parse_skip_block_comment(stream, &pos);
|
|
|
|
// Check remaining content
|
|
char buffer[256] = {0};
|
|
int i = 0;
|
|
int ch;
|
|
while ((ch = scc_probe_stream_consume(stream)) != scc_stream_eof &&
|
|
i < 255) {
|
|
buffer[i++] = (char)ch;
|
|
}
|
|
|
|
if (expect_remaining) {
|
|
TEST_CHECK(strcmp(buffer, expect_remaining) == 0);
|
|
}
|
|
}
|
|
|
|
void test_simple_block_comment(void) {
|
|
TEST_CASE("simple block comments");
|
|
check_skip_block_comment("/* comment */", "");
|
|
check_skip_block_comment("/* comment */ int x;", " int x;");
|
|
}
|
|
|
|
void test_multiline_block_comment(void) {
|
|
TEST_CASE("multiline block comments");
|
|
check_skip_block_comment("/* line1\nline2 */", "");
|
|
check_skip_block_comment("/* line1\nline2 */ int x;", " int x;");
|
|
}
|
|
|
|
void test_nested_asterisk_block_comment(void) {
|
|
TEST_CASE("nested asterisk block comments");
|
|
check_skip_block_comment("/* *** */", "");
|
|
check_skip_block_comment("/* *** */ int x;", " int x;");
|
|
}
|
|
|
|
TEST_LIST = {
|
|
{"test_simple_block_comment", test_simple_block_comment},
|
|
{"test_multiline_block_comment", test_multiline_block_comment},
|
|
{"test_nested_asterisk_block_comment", test_nested_asterisk_block_comment},
|
|
{NULL, NULL},
|
|
}; |