- Replace `scc_probe_stream_consume` with `scc_probe_stream_next` for consistent stream advancement - Remove redundant `scc_probe_stream_reset` calls before peeking, as `next` and `peek` handle state - Update `scc_cstring_new` to `scc_cstring_create` and `scc_pos_init` to `scc_pos_create` for naming consistency - Change `scc_pp_macro_get` parameter to `const scc_cstring_t*` for better const-correctness - Improves code clarity and maintains proper stream position tracking
51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
// test_skip_line.c
|
|
#include <lex_parser.h>
|
|
#include <utest/acutest.h>
|
|
|
|
void check_skip_line(const char *str, const char *expect_remaining) {
|
|
log_set_level(&__default_logger_root, 0);
|
|
scc_pos_t pos = scc_pos_create();
|
|
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_line(stream, &pos);
|
|
scc_probe_stream_sync(stream);
|
|
|
|
// 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_line_comment(void) {
|
|
TEST_CASE("simple line comments");
|
|
check_skip_line("// comment\n", "");
|
|
check_skip_line("// comment\nint x;", "int x;");
|
|
}
|
|
|
|
void test_crlf_line_comment(void) {
|
|
TEST_CASE("CRLF line comments");
|
|
check_skip_line("// comment\r\n", "");
|
|
check_skip_line("// comment\r\nint x;", "int x;");
|
|
}
|
|
|
|
void test_eof_line_comment(void) {
|
|
TEST_CASE("EOF line comments");
|
|
check_skip_line("// comment", "");
|
|
}
|
|
|
|
TEST_LIST = {
|
|
{"test_simple_line_comment", test_simple_line_comment},
|
|
{"test_crlf_line_comment", test_crlf_line_comment},
|
|
{"test_eof_line_comment", test_eof_line_comment},
|
|
{NULL, NULL},
|
|
}; |