Adjust the behaviour of mpc_eoi so that it only is successful in matching the end of input once.
This commit is contained in:
@@ -10,7 +10,7 @@ static int check_is(mpc_val_t** x, void* t) {
|
||||
}
|
||||
|
||||
void test_check(void) {
|
||||
int success;
|
||||
int success;
|
||||
mpc_result_t r;
|
||||
mpc_parser_t* p = mpc_check(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is_a, "Expected 'a'");
|
||||
|
||||
@@ -28,9 +28,9 @@ void test_check(void) {
|
||||
}
|
||||
|
||||
void test_check_with(void) {
|
||||
int success;
|
||||
int success;
|
||||
mpc_result_t r;
|
||||
mpc_parser_t* p = mpc_check_with(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is, "a", "Expected 'a'");
|
||||
mpc_parser_t* p = mpc_check_with(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is, (void*)"a", "Expected 'a'");
|
||||
|
||||
success = mpc_parse("test", "a", p, &r);
|
||||
PT_ASSERT(success);
|
||||
@@ -46,7 +46,7 @@ void test_check_with(void) {
|
||||
}
|
||||
|
||||
void test_checkf(void) {
|
||||
int success;
|
||||
int success;
|
||||
mpc_result_t r;
|
||||
mpc_parser_t* p = mpc_checkf(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is_a, "Expected '%s'", "a");
|
||||
|
||||
@@ -64,9 +64,9 @@ void test_checkf(void) {
|
||||
}
|
||||
|
||||
void test_check_withf(void) {
|
||||
int success;
|
||||
int success;
|
||||
mpc_result_t r;
|
||||
mpc_parser_t* p = mpc_check_withf(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is, "a", "Expected '%s'", "a");
|
||||
mpc_parser_t* p = mpc_check_withf(mpc_or(2, mpc_char('a'), mpc_char('b')), check_is, (void*)"a", "Expected '%s'", "a");
|
||||
|
||||
success = mpc_parse("test", "a", p, &r);
|
||||
PT_ASSERT(success);
|
||||
|
34
tests/core.c
34
tests/core.c
@@ -152,10 +152,44 @@ void test_copy(void) {
|
||||
|
||||
}
|
||||
|
||||
static int line_count = 0;
|
||||
|
||||
static void* read_line(void* line) {
|
||||
line_count++;
|
||||
return line;
|
||||
}
|
||||
|
||||
void test_reader(void) {
|
||||
|
||||
mpc_parser_t* Line = mpc_many(
|
||||
mpcf_strfold,
|
||||
mpc_apply(mpc_re("[^\\n]*(\\n|$)"), read_line));
|
||||
|
||||
line_count = 0;
|
||||
|
||||
PT_ASSERT(mpc_test_pass(Line,
|
||||
"hello\nworld\n\nthis\nis\ndan",
|
||||
"hello\nworld\n\nthis\nis\ndan", streq, free, strprint));
|
||||
|
||||
PT_ASSERT(line_count == 6);
|
||||
|
||||
line_count = 0;
|
||||
|
||||
PT_ASSERT(mpc_test_pass(Line,
|
||||
"abcHVwufvyuevuy3y436782\n\n\nrehre\nrew\n-ql.;qa\neg",
|
||||
"abcHVwufvyuevuy3y436782\n\n\nrehre\nrew\n-ql.;qa\neg", streq, free, strprint));
|
||||
|
||||
PT_ASSERT(line_count == 7);
|
||||
|
||||
mpc_delete(Line);
|
||||
|
||||
}
|
||||
|
||||
void suite_core(void) {
|
||||
pt_add_test(test_ident, "Test Ident", "Suite Core");
|
||||
pt_add_test(test_maths, "Test Maths", "Suite Core");
|
||||
pt_add_test(test_strip, "Test Strip", "Suite Core");
|
||||
pt_add_test(test_repeat, "Test Repeat", "Suite Core");
|
||||
pt_add_test(test_copy, "Test Copy", "Suite Core");
|
||||
pt_add_test(test_reader, "Test Reader", "Suite Core");
|
||||
}
|
||||
|
@@ -120,10 +120,23 @@ void test_regex_lisp_comment(void) {
|
||||
|
||||
}
|
||||
|
||||
void test_regex_newline(void) {
|
||||
|
||||
mpc_parser_t *re0 = mpc_re("[a-z]*");
|
||||
|
||||
PT_ASSERT(regex_test_pass(re0, "hi", "hi"));
|
||||
PT_ASSERT(regex_test_pass(re0, "hi\nk", "hi"));
|
||||
PT_ASSERT(regex_test_fail(re0, "hi\nk", "hi\nk"));
|
||||
|
||||
mpc_delete(re0);
|
||||
|
||||
}
|
||||
|
||||
void suite_regex(void) {
|
||||
pt_add_test(test_regex_basic, "Test Regex Basic", "Suite Regex");
|
||||
pt_add_test(test_regex_range, "Test Regex Range", "Suite Regex");
|
||||
pt_add_test(test_regex_string, "Test Regex String", "Suite Regex");
|
||||
pt_add_test(test_regex_lisp_comment, "Test Regex Lisp Comment", "Suite Regex");
|
||||
pt_add_test(test_regex_boundary, "Test Regex Boundary", "Suite Regex");
|
||||
pt_add_test(test_regex_newline, "Test Regex Newline", "Suite Regex");
|
||||
}
|
||||
|
Reference in New Issue
Block a user