diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_back.c | 6 | ||||
-rw-r--r-- | test/test_options.c | 4 | ||||
-rw-r--r-- | test/test_syntax.c | 56 | ||||
-rw-r--r-- | test/test_utf8.c | 24 | ||||
-rw-r--r-- | test/testc.c | 2 | ||||
-rw-r--r-- | test/testp.c | 2 |
6 files changed, 80 insertions, 14 deletions
diff --git a/test/test_back.c b/test/test_back.c index 9a6e4a8..52f2e58 100644 --- a/test/test_back.c +++ b/test/test_back.c @@ -1,6 +1,6 @@ /* * test_back.c - * Copyright (c) 2020-2021 K.Kosako + * Copyright (c) 2020-2024 K.Kosako */ #ifdef ONIG_ESCAPE_UCHAR_COLLISION #undef ONIG_ESCAPE_UCHAR_COLLISION @@ -64,7 +64,7 @@ static void xx(char* pattern, char* str, int from, int to, int mem, int not, r = onig_search(reg, (UChar* )str, (UChar* )(str + SLEN(str)), (UChar* )(str + SLEN(str)), (UChar* )str, region, ONIG_OPTION_NONE); - if (r < ONIG_MISMATCH) { + if (r < ONIG_MISMATCH || error_no < ONIG_MISMATCH) { char s[ONIG_MAX_ERROR_MESSAGE_LEN]; if (error_no == 0) { @@ -609,7 +609,7 @@ extern int main(int argc, char* argv[]) n("\\A(a|b\\g<1>c)\\k<1+3>\\z", "bbaccb"); x2("(?i)\\A(a|b\\g<1>c)\\k<1+2>\\z", "bBACcbac", 0, 8); x2("(?i)(?<X>aa)|(?<X>bb)\\k<X>", "BBbb", 0, 4); - x2("(?:\\k'+1'B|(A)C)*", "ACAB", 4, 4); // relative backref by postitive number + x2("(?:\\k'+1'B|(A)C)*", "ACAB", 4, 4); // relative backref by positive number x2("\\g<+2>(abc)(ABC){0}", "ABCabc", 0, 6); // relative call by positive number x2("A\\g'0'|B()", "AAAAB", 4, 5); x3("(A\\g'0')|B", "AAAAB", -1, -1, 1); diff --git a/test/test_options.c b/test/test_options.c index ce92ee1..9aa2538 100644 --- a/test/test_options.c +++ b/test/test_options.c @@ -1,6 +1,6 @@ /* * test_options.c - * Copyright (c) 2020-2021 K.Kosako + * Copyright (c) 2020-2024 K.Kosako */ #ifdef ONIG_ESCAPE_UCHAR_COLLISION #undef ONIG_ESCAPE_UCHAR_COLLISION @@ -64,7 +64,7 @@ static void xx(OnigOptionType options, char* pattern, char* str, r = onig_search(reg, (UChar* )str, (UChar* )(str + SLEN(str)), (UChar* )str, (UChar* )(str + SLEN(str)), region, options); - if (r < ONIG_MISMATCH) { + if (r < ONIG_MISMATCH || error_no < ONIG_MISMATCH) { char s[ONIG_MAX_ERROR_MESSAGE_LEN]; if (error_no == 0) { diff --git a/test/test_syntax.c b/test/test_syntax.c index b07fe67..4dcecf8 100644 --- a/test/test_syntax.c +++ b/test/test_syntax.c @@ -1,6 +1,6 @@ /* * test_syntax.c - * Copyright (c) 2019-2021 K.Kosako + * Copyright (c) 2019-2024 K.Kosako */ #ifdef ONIG_ESCAPE_UCHAR_COLLISION #undef ONIG_ESCAPE_UCHAR_COLLISION @@ -65,7 +65,7 @@ static void xx(char* pattern, char* str, int from, int to, int mem, int not, r = onig_search(reg, (UChar* )str, (UChar* )(str + SLEN(str)), (UChar* )str, (UChar* )(str + SLEN(str)), region, ONIG_OPTION_NONE); - if (r < ONIG_MISMATCH) { + if (r < ONIG_MISMATCH || error_no < ONIG_MISMATCH) { char s[ONIG_MAX_ERROR_MESSAGE_LEN]; if (error_no == 0) { @@ -205,6 +205,16 @@ static int test_look_behind() x2("(?<=a|b)c", "abc", 2, 3); x2("(?<=a|(.))\\1", "abcc", 3, 4); + // #295 + n("(?<!RMA)X", "123RMAX"); + x2("(?<=RMA)X", "123RMAX", 6, 7); + n("(?<!RMA)$", "123RMA"); + x2("(?<=RMA)$", "123RMA", 6, 6); + n("(?<!RMA)\\Z", "123RMA"); + x2("(?<=RMA)\\Z", "123RMA", 6, 6); + n("(?<!RMA)\\z", "123RMA"); + x2("(?<=RMA)\\z", "123RMA", 6, 6); + // following is not match in Perl and Java //x2("(?<=a|(.))\\1", "aa", 1, 2); @@ -213,6 +223,20 @@ static int test_look_behind() return 0; } +static int test_char_class() +{ + x2("[\\w\\-%]", "a", 0, 1); + x2("[\\w\\-%]", "%", 0, 1); + x2("[\\w\\-%]", "-", 0, 1); + + //e("[\\w-%]", "-", ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS); + x2("[\\w-%]", "a", 0, 1); + x2("[\\w-%]", "%", 0, 1); + x2("[\\w-%]", "-", 0, 1); + + return 0; +} + static int test_python_option_ascii() { x2("(?a)\\w", "a", 0, 1); @@ -301,6 +325,7 @@ extern int main(int argc, char* argv[]) test_isolated_option(); test_prec_read(); test_look_behind(); + test_char_class(); e("(?<=ab|(.))\\1", "abb", ONIGERR_INVALID_LOOK_BEHIND_PATTERN); // Variable length lookbehind not implemented in Perl 5.26.1 x3("()", "abc", 0, 0, 1); @@ -315,6 +340,10 @@ extern int main(int argc, char* argv[]) test_isolated_option(); test_prec_read(); test_look_behind(); + test_char_class(); + + n("[[:digit:]]", "1"); + x2("[[:digit:]]", "g", 0, 1); x2("(?<=ab|(.))\\1", "abb", 2, 3); n("(?<!ab|b)c", "bbc"); n("(?<!b|ab)c", "bbc"); @@ -325,6 +354,9 @@ extern int main(int argc, char* argv[]) test_python_option_ascii(); test_python_z(); test_python_single_multi(); + + n("[[:digit:]]", "1"); + x2("[[:digit:]]", "g]", 0, 2); x2("(?P<name>abc)", "abc", 0, 3); x2("(?P<name>abc)(?P=name)", "abcabc", 0, 6); x2("(?P<name>abc){0}(?P>name)", "abc", 0, 3); @@ -340,6 +372,26 @@ extern int main(int argc, char* argv[]) test_BRE_anchors(); x2("zz\\|^ab", "ab", 0, 2); x2("ab$\\|zz", "ab", 0, 2); + x2("*", "*", 0, 1); + x2("^*", "*", 0, 1); + x2("abc\\|?", "?", 0, 1); + x2("\\{1\\}", "{1}", 0, 3); + x2("^\\{1\\}", "{1}", 0, 3); + x2("\\(\\{1\\}\\)", "{1}", 0, 3); + x2("^\\(\\{1\\}\\)", "{1}", 0, 3); + x2("{1}", "{1}", 0, 3); + x2("^{1}", "{1}", 0, 3); + x2("\\({1}\\)", "{1}", 0, 3); + x2("^\\({1}\\)", "{1}", 0, 3); + x2("{1,2}", "{1,2}", 0, 5); + x2("^{1,2}", "{1,2}", 0, 5); + x2("\\({1,2}\\)", "{1,2}", 0, 5); + x2("^\\({1,2}\\)", "{1,2}", 0, 5); + + Syntax = ONIG_SYNTAX_EMACS; + x2("\\(abc\\)", "abc", 0, 3); + x2("\\(?:abc\\)", "abc", 0, 3); + x3("\\(?:abc\\)\\(xyz\\)", "abcxyz", 3, 6, 1); Syntax = ONIG_SYNTAX_PERL_NG; diff --git a/test/test_utf8.c b/test/test_utf8.c index 77149d7..01c0a5c 100644 --- a/test/test_utf8.c +++ b/test/test_utf8.c @@ -1,6 +1,6 @@ /* * test_utf8.c - * Copyright (c) 2019-2022 K.Kosako + * Copyright (c) 2019-2024 K.Kosako */ #ifdef ONIG_ESCAPE_UCHAR_COLLISION #undef ONIG_ESCAPE_UCHAR_COLLISION @@ -64,7 +64,7 @@ static void xx(char* pattern, char* str, int from, int to, int mem, int not, r = onig_search(reg, (UChar* )str, (UChar* )(str + SLEN(str)), (UChar* )str, (UChar* )(str + SLEN(str)), region, ONIG_OPTION_NONE); - if (r < ONIG_MISMATCH) { + if (r < ONIG_MISMATCH || error_no < ONIG_MISMATCH) { char s[ONIG_MAX_ERROR_MESSAGE_LEN]; if (error_no == 0) { @@ -752,7 +752,7 @@ extern int main(int argc, char* argv[]) n("\\A(a|b\\g<1>c)\\k<1+3>\\z", "bbaccb"); x2("(?i)\\A(a|b\\g<1>c)\\k<1+2>\\z", "bBACcbac", 0, 8); x2("(?i)(?<X>aa)|(?<X>bb)\\k<X>", "BBbb", 0, 4); - x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by postitive number + x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by positive number x2("\\g<+2>(abc)(ABC){0}", "ABCabc", 0, 6); // relative call by positive number x2("A\\g'0'|B()", "AAAAB", 0, 5); x3("(A\\g'0')|B", "AAAAB", 0, 5, 1); @@ -1481,6 +1481,15 @@ extern int main(int argc, char* argv[]) n("(\\k<2>)|(?<=(\\k<1>))", ""); x2("(a|\\k<2>)|(?<=(\\k<1>))", "a", 0, 1); x2("(a|\\k<2>)|(?<=b(\\k<1>))", "ba", 1, 2); + // #295 + n("(?<!RMA)X", "123RMAX"); + x2("(?<=RMA)X", "123RMAX", 6, 7); + n("(?<!RMA)$", "123RMA"); + x2("(?<=RMA)$", "123RMA", 6, 6); + n("(?<!RMA)\\Z", "123RMA"); + x2("(?<=RMA)\\Z", "123RMA", 6, 6); + n("(?<!RMA)\\z", "123RMA"); + x2("(?<=RMA)\\z", "123RMA", 6, 6); x2("((?(a)\\g<1>|b))", "aab", 0, 3); x2("((?(a)\\g<1>))", "aab", 0, 2); @@ -1639,8 +1648,8 @@ extern int main(int argc, char* argv[]) e("()(?Ii)", "", ONIGERR_INVALID_GROUP_OPTION); e("(?:)(?Ii)", "", ONIGERR_INVALID_GROUP_OPTION); e("^(?Ii)", "", ONIGERR_INVALID_GROUP_OPTION); - e("(?Ii)$", "", ONIGERR_INVALID_GROUP_OPTION); - e("(?Ii)|", "", ONIGERR_INVALID_GROUP_OPTION); + x2("(?Ii)$", "", 0, 0); + x2("(?Ii)|", "", 0, 0); e("(?Ii)|(?Ii)", "", ONIGERR_INVALID_GROUP_OPTION); x2("a*", "aabcaaa", 0, 2); x2("(?L)a*", "aabcaaa", 4, 7); @@ -1652,6 +1661,10 @@ extern int main(int argc, char* argv[]) e("(?C)(..)\\1", "abab", ONIGERR_INVALID_BACKREF); e("(?-C)", "", ONIGERR_INVALID_GROUP_OPTION); e("(?C)(.)(.)(.)(?<name>.)\\1", "abcdd", ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED); + x2("(?L)z|a\\g<0>a", "aazaa", 0, 5); + x2("(?Li)z|a\\g<0>a", "aazAA", 0, 5); + x2("(?Li:z|a\\g<0>a)", "aazAA", 0, 5); + x2("(?L)z|a\\g<0>a", "aazaaaazaaaa", 3, 12); // Issue #264 n("(?iI)s", "\xc5\xbf"); @@ -1749,6 +1762,7 @@ extern int main(int argc, char* argv[]) e("(?m:*)", "abc", ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED); x2("(?:)*", "abc", 0, 0); e("^*", "abc", ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID); + e("abc|?", "", ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED); fprintf(stdout, "\nRESULT SUCC: %4d, FAIL: %d, ERROR: %d (by Oniguruma %s)\n", diff --git a/test/testc.c b/test/testc.c index 5f7c4f0..6c4125c 100644 --- a/test/testc.c +++ b/test/testc.c @@ -520,7 +520,7 @@ extern int main(int argc, char* argv[]) n("[0-9-a]", ":"); // PR#44 x3("(\\(((?:[^(]|\\g<1>)*)\\))", "(abc)(abc)", 1, 4, 2); // PR#43 x2("\\o{101}", "A", 0, 1); - x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by postitive number + x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by positive number x2("\\g<+2>(abc)(ABC){0}", "ABCabc", 0, 6); // relative call by positive number x2("A\\g'0'|B()", "AAAAB", 0, 5); x3("(A\\g'0')|B", "AAAAB", 0, 5, 1); diff --git a/test/testp.c b/test/testp.c index 3158925..de577a2 100644 --- a/test/testp.c +++ b/test/testp.c @@ -503,7 +503,7 @@ extern int main(int argc, char* argv[]) n("[0-9-a]", ":"); // PR#44 x3("(\\(((?:[^(]|\\g<1>)*)\\))", "(abc)(abc)", 1, 4, 2); // PR#43 x2("\\o{101}", "A", 0, 1); - x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by postitive number + x2("(?:\\k'+1'B|(A)C)*", "ACAB", 0, 4); // relative backref by positive number x2("\\g<+2>(abc)(ABC){0}", "ABCabc", 0, 6); // relative call by positive number x2("A\\g'0'|B()", "AAAAB", 0, 5); x3("(A\\g'0')|B", "AAAAB", 0, 5, 1); |