| Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 2 | # -*- mode: python -*- | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 3 |  | 
| Guido van Rossum | 8430c58 | 1998-04-03 21:47:12 +0000 | [diff] [blame] | 4 | # Re test suite and benchmark suite v1.5 | 
| Guido van Rossum | 8e0ce30 | 1997-07-11 19:34:44 +0000 | [diff] [blame] | 5 |  | 
|  | 6 | # The 3 possible outcomes for each pattern | 
|  | 7 | [SUCCEED, FAIL, SYNTAX_ERROR] = range(3) | 
|  | 8 |  | 
|  | 9 | # Benchmark suite (needs expansion) | 
|  | 10 | # | 
|  | 11 | # The benchmark suite does not test correctness, just speed.  The | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 12 | # first element of each tuple is the regex pattern; the second is a | 
| Guido van Rossum | 8e0ce30 | 1997-07-11 19:34:44 +0000 | [diff] [blame] | 13 | # string to match it against.  The benchmarking code will embed the | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 14 | # second string inside several sizes of padding, to test how regex | 
| Guido van Rossum | 8e0ce30 | 1997-07-11 19:34:44 +0000 | [diff] [blame] | 15 | # matching performs on large strings. | 
|  | 16 |  | 
|  | 17 | benchmarks = [ | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 18 |  | 
|  | 19 | # test common prefix | 
|  | 20 | ('Python|Perl', 'Perl'),    # Alternation | 
|  | 21 | ('(Python|Perl)', 'Perl'),  # Grouped alternation | 
|  | 22 |  | 
|  | 23 | ('Python|Perl|Tcl', 'Perl'),        # Alternation | 
|  | 24 | ('(Python|Perl|Tcl)', 'Perl'),      # Grouped alternation | 
|  | 25 |  | 
|  | 26 | ('(Python)\\1', 'PythonPython'),    # Backreference | 
|  | 27 | ('([0a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # Disable the fastmap optimization | 
|  | 28 | ('([a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # A few sets | 
|  | 29 |  | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 30 | ('Python', 'Python'),               # Simple text literal | 
|  | 31 | ('.*Python', 'Python'),             # Bad text literal | 
|  | 32 | ('.*Python.*', 'Python'),           # Worse text literal | 
|  | 33 | ('.*(Python)', 'Python'),           # Bad text literal with grouping | 
|  | 34 |  | 
| Guido van Rossum | 8e0ce30 | 1997-07-11 19:34:44 +0000 | [diff] [blame] | 35 | ] | 
|  | 36 |  | 
|  | 37 | # Test suite (for verifying correctness) | 
|  | 38 | # | 
|  | 39 | # The test suite is a list of 5- or 3-tuples.  The 5 parts of a | 
|  | 40 | # complete tuple are: | 
|  | 41 | # element 0: a string containing the pattern | 
|  | 42 | #         1: the string to match against the pattern | 
|  | 43 | #         2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR) | 
|  | 44 | #         3: a string that will be eval()'ed to produce a test string. | 
|  | 45 | #            This is an arbitrary Python expression; the available | 
|  | 46 | #            variables are "found" (the whole match), and "g1", "g2", ... | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 47 | #            up to "g99" contain the contents of each group, or the | 
|  | 48 | #            string 'None' if the group wasn't given a value, or the | 
|  | 49 | #            string 'Error' if the group index was out of range; | 
|  | 50 | #            also "groups", the return value of m.group() (a tuple). | 
| Guido van Rossum | 8e0ce30 | 1997-07-11 19:34:44 +0000 | [diff] [blame] | 51 | #         4: The expected result of evaluating the expression. | 
|  | 52 | #            If the two don't match, an error is reported. | 
|  | 53 | # | 
|  | 54 | # If the regex isn't expected to work, the latter two elements can be omitted. | 
|  | 55 |  | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 56 | tests = [ | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 57 | # Test ?P< and ?P= extensions | 
|  | 58 | ('(?P<foo_123', '', SYNTAX_ERROR),      # Unterminated group identifier | 
|  | 59 | ('(?P<1>a)', '', SYNTAX_ERROR),         # Begins with a digit | 
|  | 60 | ('(?P<!>a)', '', SYNTAX_ERROR),         # Begins with an illegal char | 
|  | 61 | ('(?P<foo!>a)', '', SYNTAX_ERROR),      # Begins with an illegal char | 
|  | 62 |  | 
|  | 63 | # Same tests, for the ?P= form | 
|  | 64 | ('(?P<foo_123>a)(?P=foo_123', 'aa', SYNTAX_ERROR), | 
|  | 65 | ('(?P<foo_123>a)(?P=1)', 'aa', SYNTAX_ERROR), | 
|  | 66 | ('(?P<foo_123>a)(?P=!)', 'aa', SYNTAX_ERROR), | 
|  | 67 | ('(?P<foo_123>a)(?P=foo_124', 'aa', SYNTAX_ERROR),  # Backref to undefined group | 
|  | 68 |  | 
|  | 69 | ('(?P<foo_123>a)', 'a', SUCCEED, 'g1', 'a'), | 
|  | 70 | ('(?P<foo_123>a)(?P=foo_123)', 'aa', SUCCEED, 'g1', 'a'), | 
| Guido van Rossum | 8430c58 | 1998-04-03 21:47:12 +0000 | [diff] [blame] | 71 |  | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 72 | # Test octal escapes | 
| Guido van Rossum | 8430c58 | 1998-04-03 21:47:12 +0000 | [diff] [blame] | 73 | ('\\1', 'a', SYNTAX_ERROR),    # Backreference | 
|  | 74 | ('[\\1]', '\1', SUCCEED, 'found', '\1'),  # Character | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 75 | ('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'), | 
|  | 76 | ('\\141', 'a', SUCCEED, 'found', 'a'), | 
|  | 77 | ('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'), | 
|  | 78 |  | 
| Guido van Rossum | 8430c58 | 1998-04-03 21:47:12 +0000 | [diff] [blame] | 79 | # Test \0 is handled everywhere | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 80 | (r'\0', '\0', SUCCEED, 'found', '\0'), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 81 | (r'[\0a]', '\0', SUCCEED, 'found', '\0'), | 
|  | 82 | (r'[a\0]', '\0', SUCCEED, 'found', '\0'), | 
|  | 83 | (r'[^a\0]', '\0', FAIL), | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 84 |  | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 85 | # Test various letter escapes | 
|  | 86 | (r'\a[\b]\f\n\r\t\v', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'), | 
|  | 87 | (r'[\a][\b][\f][\n][\r][\t][\v]', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 88 | # NOTE: not an error under PCRE/PRE: | 
| Serhiy Storchaka | 9cba989 | 2014-12-01 11:06:45 +0200 | [diff] [blame] | 89 | (r'\u', '', SYNTAX_ERROR),    # A Perl escape | 
| Serhiy Storchaka | a54aae0 | 2015-03-24 22:58:14 +0200 | [diff] [blame] | 90 | # (r'\c\e\g\h\i\j\k\m\o\p\q\y\z', 'ceghijkmopqyz', SUCCEED, 'found', 'ceghijkmopqyz'), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 91 | # new \x semantics | 
|  | 92 | (r'\x00ffffffffffffff', '\377', FAIL, 'found', chr(255)), | 
|  | 93 | (r'\x00f', '\017', FAIL, 'found', chr(15)), | 
|  | 94 | (r'\x00fe', '\376', FAIL, 'found', chr(254)), | 
|  | 95 | # (r'\x00ffffffffffffff', '\377', SUCCEED, 'found', chr(255)), | 
|  | 96 | # (r'\x00f', '\017', SUCCEED, 'found', chr(15)), | 
|  | 97 | # (r'\x00fe', '\376', SUCCEED, 'found', chr(254)), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 98 |  | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 99 | (r"^\w+=(\\[\000-\277]|[^\n\\])*", "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c", | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 100 | SUCCEED, 'found', "SRC=eval.c g.c blah blah blah \\\\"), | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 101 |  | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 102 | # Test that . only matches \n in DOTALL mode | 
|  | 103 | ('a.b', 'acb', SUCCEED, 'found', 'acb'), | 
|  | 104 | ('a.b', 'a\nb', FAIL), | 
|  | 105 | ('a.*b', 'acc\nccb', FAIL), | 
|  | 106 | ('a.{4,5}b', 'acc\nccb', FAIL), | 
|  | 107 | ('a.b', 'a\rb', SUCCEED, 'found', 'a\rb'), | 
| Serhiy Storchaka | bd48d27 | 2016-09-11 12:50:02 +0300 | [diff] [blame] | 108 | ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'), | 
|  | 109 | ('(?s)a.*b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 110 | ('(?s)a.{4,5}b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'), | 
| MakDon | ded4737 | 2019-04-04 18:38:42 +0800 | [diff] [blame] | 111 | ('(?s)a.b', 'a\rb', SUCCEED, 'found', 'a\rb'), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 112 |  | 
| Guido van Rossum | 8430c58 | 1998-04-03 21:47:12 +0000 | [diff] [blame] | 113 | (')', '', SYNTAX_ERROR),           # Unmatched right bracket | 
|  | 114 | ('', '', SUCCEED, 'found', ''),    # Empty pattern | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 115 | ('abc', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 116 | ('abc', 'xbc', FAIL), | 
|  | 117 | ('abc', 'axc', FAIL), | 
|  | 118 | ('abc', 'abx', FAIL), | 
|  | 119 | ('abc', 'xabcy', SUCCEED, 'found', 'abc'), | 
|  | 120 | ('abc', 'ababc', SUCCEED, 'found', 'abc'), | 
|  | 121 | ('ab*c', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 122 | ('ab*bc', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 123 | ('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'), | 
|  | 124 | ('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
|  | 125 | ('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'), | 
|  | 126 | ('ab+bc', 'abc', FAIL), | 
|  | 127 | ('ab+bc', 'abq', FAIL), | 
|  | 128 | ('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
|  | 129 | ('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'), | 
|  | 130 | ('ab?bc', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 131 | ('ab?bc', 'abbbbc', FAIL), | 
|  | 132 | ('ab?c', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 133 | ('^abc$', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 134 | ('^abc$', 'abcc', FAIL), | 
|  | 135 | ('^abc', 'abcc', SUCCEED, 'found', 'abc'), | 
|  | 136 | ('^abc$', 'aabc', FAIL), | 
|  | 137 | ('abc$', 'aabc', SUCCEED, 'found', 'abc'), | 
|  | 138 | ('^', 'abc', SUCCEED, 'found+"-"', '-'), | 
|  | 139 | ('$', 'abc', SUCCEED, 'found+"-"', '-'), | 
|  | 140 | ('a.c', 'abc', SUCCEED, 'found', 'abc'), | 
|  | 141 | ('a.c', 'axc', SUCCEED, 'found', 'axc'), | 
|  | 142 | ('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'), | 
|  | 143 | ('a.*c', 'axyzd', FAIL), | 
|  | 144 | ('a[bc]d', 'abc', FAIL), | 
|  | 145 | ('a[bc]d', 'abd', SUCCEED, 'found', 'abd'), | 
|  | 146 | ('a[b-d]e', 'abd', FAIL), | 
|  | 147 | ('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'), | 
|  | 148 | ('a[b-d]', 'aac', SUCCEED, 'found', 'ac'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 149 | ('a[-b]', 'a-', SUCCEED, 'found', 'a-'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 150 | ('a[\\-b]', 'a-', SUCCEED, 'found', 'a-'), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 151 | # NOTE: not an error under PCRE/PRE: | 
|  | 152 | # ('a[b-]', 'a-', SYNTAX_ERROR), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 153 | ('a[]b', '-', SYNTAX_ERROR), | 
|  | 154 | ('a[', '-', SYNTAX_ERROR), | 
|  | 155 | ('a\\', '-', SYNTAX_ERROR), | 
|  | 156 | ('abc)', '-', SYNTAX_ERROR), | 
|  | 157 | ('(abc', '-', SYNTAX_ERROR), | 
|  | 158 | ('a]', 'a]', SUCCEED, 'found', 'a]'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 159 | ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'), | 
| R David Murray | 44b548d | 2016-09-08 13:59:53 -0400 | [diff] [blame] | 160 | ('a[\\]]b', 'a]b', SUCCEED, 'found', 'a]b'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 161 | ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'), | 
|  | 162 | ('a[^bc]d', 'abd', FAIL), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 163 | ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'), | 
|  | 164 | ('a[^-b]c', 'a-c', FAIL), | 
|  | 165 | ('a[^]b]c', 'a]c', FAIL), | 
|  | 166 | ('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 167 | ('\\ba\\b', 'a-', SUCCEED, '"-"', '-'), | 
|  | 168 | ('\\ba\\b', '-a', SUCCEED, '"-"', '-'), | 
|  | 169 | ('\\ba\\b', '-a-', SUCCEED, '"-"', '-'), | 
|  | 170 | ('\\by\\b', 'xy', FAIL), | 
|  | 171 | ('\\by\\b', 'yz', FAIL), | 
|  | 172 | ('\\by\\b', 'xyz', FAIL), | 
| Guido van Rossum | cf00505 | 1997-08-15 15:44:58 +0000 | [diff] [blame] | 173 | ('x\\b', 'xyz', FAIL), | 
|  | 174 | ('x\\B', 'xyz', SUCCEED, '"-"', '-'), | 
|  | 175 | ('\\Bz', 'xyz', SUCCEED, '"-"', '-'), | 
|  | 176 | ('z\\B', 'xyz', FAIL), | 
|  | 177 | ('\\Bx', 'xyz', FAIL), | 
|  | 178 | ('\\Ba\\B', 'a-', FAIL, '"-"', '-'), | 
|  | 179 | ('\\Ba\\B', '-a', FAIL, '"-"', '-'), | 
|  | 180 | ('\\Ba\\B', '-a-', FAIL, '"-"', '-'), | 
|  | 181 | ('\\By\\B', 'xy', FAIL), | 
|  | 182 | ('\\By\\B', 'yz', FAIL), | 
|  | 183 | ('\\By\\b', 'xy', SUCCEED, '"-"', '-'), | 
|  | 184 | ('\\by\\B', 'yz', SUCCEED, '"-"', '-'), | 
|  | 185 | ('\\By\\B', 'xyz', SUCCEED, '"-"', '-'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 186 | ('ab|cd', 'abc', SUCCEED, 'found', 'ab'), | 
|  | 187 | ('ab|cd', 'abcd', SUCCEED, 'found', 'ab'), | 
|  | 188 | ('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'), | 
|  | 189 | ('$b', 'b', FAIL), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 190 | ('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 191 | ('a\\(*b', 'ab', SUCCEED, 'found', 'ab'), | 
|  | 192 | ('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'), | 
|  | 193 | ('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'), | 
|  | 194 | ('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'), | 
|  | 195 | ('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'), | 
|  | 196 | ('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'), | 
|  | 197 | ('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), | 
|  | 198 | ('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), | 
|  | 199 | ('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'), | 
|  | 200 | (')(', '-', SYNTAX_ERROR), | 
|  | 201 | ('[^ab]*', 'cde', SUCCEED, 'found', 'cde'), | 
|  | 202 | ('abc', '', FAIL), | 
|  | 203 | ('a*', '', SUCCEED, 'found', ''), | 
|  | 204 | ('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'), | 
|  | 205 | ('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'), | 
|  | 206 | ('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'), | 
|  | 207 | ('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'), | 
|  | 208 | ('ab*', 'xayabbbz', SUCCEED, 'found', 'a'), | 
|  | 209 | ('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'), | 
|  | 210 | ('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 211 | ('^(ab|cd)e', 'abcde', FAIL, 'xg1y', 'xy'), | 
| Guido van Rossum | 337c6d4 | 1997-07-15 18:42:58 +0000 | [diff] [blame] | 212 | ('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'), | 
|  | 213 | ('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'), | 
|  | 214 | ('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'), | 
|  | 215 | ('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'), | 
|  | 216 | ('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), | 
|  | 217 | ('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'), | 
|  | 218 | ('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'), | 
|  | 219 | ('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'), | 
|  | 220 | ('a[bcd]+dcdcde', 'adcdcde', FAIL), | 
|  | 221 | ('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'), | 
|  | 222 | ('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'), | 
|  | 223 | ('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'), | 
|  | 224 | ('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'), | 
|  | 225 | ('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), | 
|  | 226 | ('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'), | 
|  | 227 | ('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL), | 
|  | 228 | ('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL), | 
|  | 229 | ('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'), | 
|  | 230 | ('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'), | 
|  | 231 | ('multiple words of text', 'uh-uh', FAIL), | 
|  | 232 | ('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'), | 
|  | 233 | ('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'), | 
|  | 234 | ('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'), | 
|  | 235 | ('[k]', 'ab', FAIL), | 
|  | 236 | ('a[-]?c', 'ac', SUCCEED, 'found', 'ac'), | 
|  | 237 | ('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), | 
|  | 238 | ('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'), | 
|  | 239 | ('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'), | 
|  | 240 | ('(a+).\\1$', 'aaaaa', SUCCEED, 'found+"-"+g1', 'aaaaa-aa'), | 
|  | 241 | ('^(a+).\\1$', 'aaaa', FAIL), | 
|  | 242 | ('(abc)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), | 
|  | 243 | ('([a-c]+)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), | 
|  | 244 | ('(a)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), | 
|  | 245 | ('(a+)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), | 
|  | 246 | ('(a+)+\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'), | 
|  | 247 | ('(a).+\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'), | 
|  | 248 | ('(a)ba*\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'), | 
|  | 249 | ('(aa|a)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), | 
|  | 250 | ('(a|aa)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), | 
|  | 251 | ('(a+)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'), | 
|  | 252 | ('([abc]*)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'), | 
|  | 253 | ('(a)(b)c|ab', 'ab', SUCCEED, 'found+"-"+g1+"-"+g2', 'ab-None-None'), | 
|  | 254 | ('(a)+x', 'aaax', SUCCEED, 'found+"-"+g1', 'aaax-a'), | 
|  | 255 | ('([ac])+x', 'aacx', SUCCEED, 'found+"-"+g1', 'aacx-c'), | 
|  | 256 | ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'), | 
|  | 257 | ('([^.]*)\\.([^:]*):[T ]+(.*)', 'track1.title:TBlah blah blah', SUCCEED, 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'), | 
|  | 258 | ('([^N]*N)+', 'abNNxyzN', SUCCEED, 'found+"-"+g1', 'abNNxyzN-xyzN'), | 
|  | 259 | ('([^N]*N)+', 'abNNxyz', SUCCEED, 'found+"-"+g1', 'abNN-N'), | 
|  | 260 | ('([abc]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'abcx-abc'), | 
|  | 261 | ('([abc]*)x', 'abc', FAIL), | 
|  | 262 | ('([xyz]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'x-'), | 
|  | 263 | ('(a)+b|aac', 'aac', SUCCEED, 'found+"-"+g1', 'aac-None'), | 
|  | 264 |  | 
|  | 265 | # Test symbolic groups | 
|  | 266 |  | 
|  | 267 | ('(?P<i d>aaa)a', 'aaaa', SYNTAX_ERROR), | 
|  | 268 | ('(?P<id>aaa)a', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aaa'), | 
|  | 269 | ('(?P<id>aa)(?P=id)', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aa'), | 
|  | 270 | ('(?P<id>aa)(?P=xd)', 'aaaa', SYNTAX_ERROR), | 
|  | 271 |  | 
|  | 272 | # Test octal escapes/memory references | 
|  | 273 |  | 
|  | 274 | ('\\1', 'a', SYNTAX_ERROR), | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 275 |  | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 276 | # All tests from Perl | 
|  | 277 |  | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 278 | ('ab{0,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 279 | ('ab{1,}bc', 'abq', FAIL), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 280 | ('ab{1,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
|  | 281 | ('ab{1,3}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
|  | 282 | ('ab{3,4}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'), | 
|  | 283 | ('ab{4,5}bc', 'abbbbc', FAIL), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 284 | ('ab{0,1}bc', 'abc', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 285 | ('ab{0,1}c', 'abc', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 286 | ('^', 'abc', SUCCEED, 'found', ''), | 
|  | 287 | ('$', 'abc', SUCCEED, 'found', ''), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 288 | ('a[b-]', 'a-', SUCCEED, 'found', 'a-'), | 
|  | 289 | ('a[b-a]', '-', SYNTAX_ERROR), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 290 | ('*a', '-', SYNTAX_ERROR), | 
|  | 291 | ('(*)b', '-', SYNTAX_ERROR), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 292 | ('a{1,}b{1,}c', 'aabbabc', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 293 | ('a**', '-', SYNTAX_ERROR), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 294 | ('a.+?c', 'abcabc', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 295 | ('(a+|b){0,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 296 | ('(a+|b){1,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 297 | ('(a+|b){0,1}', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 298 | ('([abc])*d', 'abbbcd', SUCCEED, 'found+"-"+g1', 'abbbcd-c'), | 
|  | 299 | ('([abc])*bcd', 'abcd', SUCCEED, 'found+"-"+g1', 'abcd-a'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 300 | ('^(ab|cd)e', 'abcde', FAIL), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 301 | ('((((((((((a))))))))))', 'a', SUCCEED, 'g10', 'a'), | 
|  | 302 | ('((((((((((a))))))))))\\10', 'aa', SUCCEED, 'found', 'aa'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 303 | # Python does not have the same rules for \\41 so this is a syntax error | 
|  | 304 | #    ('((((((((((a))))))))))\\41', 'aa', FAIL), | 
|  | 305 | #    ('((((((((((a))))))))))\\41', 'a!', SUCCEED, 'found', 'a!'), | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 306 | ('((((((((((a))))))))))\\41', '', SYNTAX_ERROR), | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 307 | ('(?i)((((((((((a))))))))))\\41', '', SYNTAX_ERROR), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 308 | ('(?i)abc', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 309 | ('(?i)abc', 'XBC', FAIL), | 
|  | 310 | ('(?i)abc', 'AXC', FAIL), | 
|  | 311 | ('(?i)abc', 'ABX', FAIL), | 
|  | 312 | ('(?i)abc', 'XABCY', SUCCEED, 'found', 'ABC'), | 
|  | 313 | ('(?i)abc', 'ABABC', SUCCEED, 'found', 'ABC'), | 
|  | 314 | ('(?i)ab*c', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 315 | ('(?i)ab*bc', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 316 | ('(?i)ab*bc', 'ABBC', SUCCEED, 'found', 'ABBC'), | 
|  | 317 | ('(?i)ab*?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 318 | ('(?i)ab{0,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 319 | ('(?i)ab+?bc', 'ABBC', SUCCEED, 'found', 'ABBC'), | 
|  | 320 | ('(?i)ab+bc', 'ABC', FAIL), | 
|  | 321 | ('(?i)ab+bc', 'ABQ', FAIL), | 
|  | 322 | ('(?i)ab{1,}bc', 'ABQ', FAIL), | 
|  | 323 | ('(?i)ab+bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 324 | ('(?i)ab{1,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 325 | ('(?i)ab{1,3}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 326 | ('(?i)ab{3,4}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'), | 
|  | 327 | ('(?i)ab{4,5}?bc', 'ABBBBC', FAIL), | 
|  | 328 | ('(?i)ab??bc', 'ABBC', SUCCEED, 'found', 'ABBC'), | 
|  | 329 | ('(?i)ab??bc', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 330 | ('(?i)ab{0,1}?bc', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 331 | ('(?i)ab??bc', 'ABBBBC', FAIL), | 
|  | 332 | ('(?i)ab??c', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 333 | ('(?i)ab{0,1}?c', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 334 | ('(?i)^abc$', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 335 | ('(?i)^abc$', 'ABCC', FAIL), | 
|  | 336 | ('(?i)^abc', 'ABCC', SUCCEED, 'found', 'ABC'), | 
|  | 337 | ('(?i)^abc$', 'AABC', FAIL), | 
|  | 338 | ('(?i)abc$', 'AABC', SUCCEED, 'found', 'ABC'), | 
|  | 339 | ('(?i)^', 'ABC', SUCCEED, 'found', ''), | 
|  | 340 | ('(?i)$', 'ABC', SUCCEED, 'found', ''), | 
|  | 341 | ('(?i)a.c', 'ABC', SUCCEED, 'found', 'ABC'), | 
|  | 342 | ('(?i)a.c', 'AXC', SUCCEED, 'found', 'AXC'), | 
|  | 343 | ('(?i)a.*?c', 'AXYZC', SUCCEED, 'found', 'AXYZC'), | 
|  | 344 | ('(?i)a.*c', 'AXYZD', FAIL), | 
|  | 345 | ('(?i)a[bc]d', 'ABC', FAIL), | 
|  | 346 | ('(?i)a[bc]d', 'ABD', SUCCEED, 'found', 'ABD'), | 
|  | 347 | ('(?i)a[b-d]e', 'ABD', FAIL), | 
|  | 348 | ('(?i)a[b-d]e', 'ACE', SUCCEED, 'found', 'ACE'), | 
|  | 349 | ('(?i)a[b-d]', 'AAC', SUCCEED, 'found', 'AC'), | 
|  | 350 | ('(?i)a[-b]', 'A-', SUCCEED, 'found', 'A-'), | 
|  | 351 | ('(?i)a[b-]', 'A-', SUCCEED, 'found', 'A-'), | 
|  | 352 | ('(?i)a[b-a]', '-', SYNTAX_ERROR), | 
|  | 353 | ('(?i)a[]b', '-', SYNTAX_ERROR), | 
|  | 354 | ('(?i)a[', '-', SYNTAX_ERROR), | 
|  | 355 | ('(?i)a]', 'A]', SUCCEED, 'found', 'A]'), | 
|  | 356 | ('(?i)a[]]b', 'A]B', SUCCEED, 'found', 'A]B'), | 
|  | 357 | ('(?i)a[^bc]d', 'AED', SUCCEED, 'found', 'AED'), | 
|  | 358 | ('(?i)a[^bc]d', 'ABD', FAIL), | 
|  | 359 | ('(?i)a[^-b]c', 'ADC', SUCCEED, 'found', 'ADC'), | 
|  | 360 | ('(?i)a[^-b]c', 'A-C', FAIL), | 
|  | 361 | ('(?i)a[^]b]c', 'A]C', FAIL), | 
|  | 362 | ('(?i)a[^]b]c', 'ADC', SUCCEED, 'found', 'ADC'), | 
|  | 363 | ('(?i)ab|cd', 'ABC', SUCCEED, 'found', 'AB'), | 
|  | 364 | ('(?i)ab|cd', 'ABCD', SUCCEED, 'found', 'AB'), | 
|  | 365 | ('(?i)()ef', 'DEF', SUCCEED, 'found+"-"+g1', 'EF-'), | 
|  | 366 | ('(?i)*a', '-', SYNTAX_ERROR), | 
|  | 367 | ('(?i)(*)b', '-', SYNTAX_ERROR), | 
|  | 368 | ('(?i)$b', 'B', FAIL), | 
|  | 369 | ('(?i)a\\', '-', SYNTAX_ERROR), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 370 | ('(?i)a\\(b', 'A(B', SUCCEED, 'found+"-"+g1', 'A(B-Error'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 371 | ('(?i)a\\(*b', 'AB', SUCCEED, 'found', 'AB'), | 
|  | 372 | ('(?i)a\\(*b', 'A((B', SUCCEED, 'found', 'A((B'), | 
|  | 373 | ('(?i)a\\\\b', 'A\\B', SUCCEED, 'found', 'A\\B'), | 
|  | 374 | ('(?i)abc)', '-', SYNTAX_ERROR), | 
|  | 375 | ('(?i)(abc', '-', SYNTAX_ERROR), | 
|  | 376 | ('(?i)((a))', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'A-A-A'), | 
|  | 377 | ('(?i)(a)b(c)', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABC-A-C'), | 
|  | 378 | ('(?i)a+b+c', 'AABBABC', SUCCEED, 'found', 'ABC'), | 
|  | 379 | ('(?i)a{1,}b{1,}c', 'AABBABC', SUCCEED, 'found', 'ABC'), | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 380 | ('(?i)a**', '-', SYNTAX_ERROR), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 381 | ('(?i)a.+?c', 'ABCABC', SUCCEED, 'found', 'ABC'), | 
|  | 382 | ('(?i)a.*?c', 'ABCABC', SUCCEED, 'found', 'ABC'), | 
|  | 383 | ('(?i)a.{0,5}?c', 'ABCABC', SUCCEED, 'found', 'ABC'), | 
|  | 384 | ('(?i)(a+|b)*', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), | 
|  | 385 | ('(?i)(a+|b){0,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), | 
|  | 386 | ('(?i)(a+|b)+', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), | 
|  | 387 | ('(?i)(a+|b){1,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'), | 
|  | 388 | ('(?i)(a+|b)?', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'), | 
|  | 389 | ('(?i)(a+|b){0,1}', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 390 | ('(?i)(a+|b){0,1}?', 'AB', SUCCEED, 'found+"-"+g1', '-None'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 391 | ('(?i))(', '-', SYNTAX_ERROR), | 
|  | 392 | ('(?i)[^ab]*', 'CDE', SUCCEED, 'found', 'CDE'), | 
|  | 393 | ('(?i)abc', '', FAIL), | 
|  | 394 | ('(?i)a*', '', SUCCEED, 'found', ''), | 
|  | 395 | ('(?i)([abc])*d', 'ABBBCD', SUCCEED, 'found+"-"+g1', 'ABBBCD-C'), | 
|  | 396 | ('(?i)([abc])*bcd', 'ABCD', SUCCEED, 'found+"-"+g1', 'ABCD-A'), | 
|  | 397 | ('(?i)a|b|c|d|e', 'E', SUCCEED, 'found', 'E'), | 
|  | 398 | ('(?i)(a|b|c|d|e)f', 'EF', SUCCEED, 'found+"-"+g1', 'EF-E'), | 
|  | 399 | ('(?i)abcd*efg', 'ABCDEFG', SUCCEED, 'found', 'ABCDEFG'), | 
|  | 400 | ('(?i)ab*', 'XABYABBBZ', SUCCEED, 'found', 'AB'), | 
|  | 401 | ('(?i)ab*', 'XAYABBBZ', SUCCEED, 'found', 'A'), | 
|  | 402 | ('(?i)(ab|cd)e', 'ABCDE', SUCCEED, 'found+"-"+g1', 'CDE-CD'), | 
|  | 403 | ('(?i)[abhgefdc]ij', 'HIJ', SUCCEED, 'found', 'HIJ'), | 
|  | 404 | ('(?i)^(ab|cd)e', 'ABCDE', FAIL), | 
|  | 405 | ('(?i)(abc|)ef', 'ABCDEF', SUCCEED, 'found+"-"+g1', 'EF-'), | 
|  | 406 | ('(?i)(a|b)c*d', 'ABCD', SUCCEED, 'found+"-"+g1', 'BCD-B'), | 
|  | 407 | ('(?i)(ab|ab*)bc', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-A'), | 
|  | 408 | ('(?i)a([bc]*)c*', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-BC'), | 
|  | 409 | ('(?i)a([bc]*)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'), | 
|  | 410 | ('(?i)a([bc]+)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'), | 
|  | 411 | ('(?i)a([bc]*)(c+d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-B-CD'), | 
|  | 412 | ('(?i)a[bcd]*dcdcde', 'ADCDCDE', SUCCEED, 'found', 'ADCDCDE'), | 
|  | 413 | ('(?i)a[bcd]+dcdcde', 'ADCDCDE', FAIL), | 
|  | 414 | ('(?i)(ab|a)b*c', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-AB'), | 
|  | 415 | ('(?i)((a)(b)c)(d)', 'ABCD', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'ABC-A-B-D'), | 
|  | 416 | ('(?i)[a-zA-Z_][a-zA-Z0-9_]*', 'ALPHA', SUCCEED, 'found', 'ALPHA'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 417 | ('(?i)^a(bc+|b[eh])g|.h$', 'ABH', SUCCEED, 'found+"-"+g1', 'BH-None'), | 
|  | 418 | ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 419 | ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'IJ', SUCCEED, 'found+"-"+g1+"-"+g2', 'IJ-IJ-J'), | 
|  | 420 | ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFG', FAIL), | 
|  | 421 | ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'BCDD', FAIL), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 422 | ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'REFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 423 | ('(?i)((((((((((a))))))))))', 'A', SUCCEED, 'g10', 'A'), | 
|  | 424 | ('(?i)((((((((((a))))))))))\\10', 'AA', SUCCEED, 'found', 'AA'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 425 | #('(?i)((((((((((a))))))))))\\41', 'AA', FAIL), | 
|  | 426 | #('(?i)((((((((((a))))))))))\\41', 'A!', SUCCEED, 'found', 'A!'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 427 | ('(?i)(((((((((a)))))))))', 'A', SUCCEED, 'found', 'A'), | 
|  | 428 | ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))', 'A', SUCCEED, 'g1', 'A'), | 
|  | 429 | ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))', 'C', SUCCEED, 'g1', 'C'), | 
|  | 430 | ('(?i)multiple words of text', 'UH-UH', FAIL), | 
|  | 431 | ('(?i)multiple words', 'MULTIPLE WORDS, YEAH', SUCCEED, 'found', 'MULTIPLE WORDS'), | 
|  | 432 | ('(?i)(.*)c(.*)', 'ABCDE', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCDE-AB-DE'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 433 | ('(?i)\\((.*), (.*)\\)', '(A, B)', SUCCEED, 'g2+"-"+g1', 'B-A'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 434 | ('(?i)[k]', 'AB', FAIL), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 435 | #    ('(?i)abcd', 'ABCD', SUCCEED, 'found+"-"+\\found+"-"+\\\\found', 'ABCD-$&-\\ABCD'), | 
|  | 436 | #    ('(?i)a(bc)d', 'ABCD', SUCCEED, 'g1+"-"+\\g1+"-"+\\\\g1', 'BC-$1-\\BC'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 437 | ('(?i)a[-]?c', 'AC', SUCCEED, 'found', 'AC'), | 
|  | 438 | ('(?i)(abc)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'), | 
|  | 439 | ('(?i)([a-c]*)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 440 | ('a(?!b).', 'abad', SUCCEED, 'found', 'ad'), | 
|  | 441 | ('a(?=d).', 'abad', SUCCEED, 'found', 'ad'), | 
|  | 442 | ('a(?=c|d).', 'abad', SUCCEED, 'found', 'ad'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 443 | ('a(?:b|c|d)(.)', 'ace', SUCCEED, 'g1', 'e'), | 
|  | 444 | ('a(?:b|c|d)*(.)', 'ace', SUCCEED, 'g1', 'e'), | 
|  | 445 | ('a(?:b|c|d)+?(.)', 'ace', SUCCEED, 'g1', 'e'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 446 | ('a(?:b|(c|e){1,2}?|d)+?(.)', 'ace', SUCCEED, 'g1 + g2', 'ce'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 447 |  | 
| Neal Norwitz | bb18441 | 2003-02-13 03:01:18 +0000 | [diff] [blame] | 448 | # lookbehind: split by : but not if it is escaped by -. | 
|  | 449 | ('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ), | 
|  | 450 | # escaping with \ as we know it | 
| R David Murray | 44b548d | 2016-09-08 13:59:53 -0400 | [diff] [blame] | 451 | ('(?<!\\\\):(.*?)(?<!\\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ), | 
| Neal Norwitz | bb18441 | 2003-02-13 03:01:18 +0000 | [diff] [blame] | 452 | # terminating with ' and escaping with ? as in edifact | 
| Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 453 | ("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ), | 
| Neal Norwitz | bb18441 | 2003-02-13 03:01:18 +0000 | [diff] [blame] | 454 |  | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 455 | # Comments using the (?#...) syntax | 
|  | 456 |  | 
|  | 457 | ('w(?# comment', 'w', SYNTAX_ERROR), | 
|  | 458 | ('w(?# comment 1)xy(?# comment 2)z', 'wxyz', SUCCEED, 'found', 'wxyz'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 459 |  | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 460 | # Check odd placement of embedded pattern modifiers | 
|  | 461 |  | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 462 | # not an error under PCRE/PRE: | 
| Serhiy Storchaka | bd48d27 | 2016-09-11 12:50:02 +0300 | [diff] [blame] | 463 | ('(?i)w', 'W', SUCCEED, 'found', 'W'), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 464 | # ('w(?i)', 'W', SYNTAX_ERROR), | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 465 |  | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 466 | # Comments using the x embedded pattern modifier | 
|  | 467 |  | 
|  | 468 | ("""(?x)w# comment 1 | 
|  | 469 | x y | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 470 | # comment 2 | 
|  | 471 | z""", 'wxyz', SUCCEED, 'found', 'wxyz'), | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 472 |  | 
|  | 473 | # using the m embedded pattern modifier | 
|  | 474 |  | 
|  | 475 | ('^abc', """jkl | 
|  | 476 | abc | 
|  | 477 | xyz""", FAIL), | 
|  | 478 | ('(?m)^abc', """jkl | 
|  | 479 | abc | 
|  | 480 | xyz""", SUCCEED, 'found', 'abc'), | 
|  | 481 |  | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 482 | ('(?m)abc$', """jkl | 
|  | 483 | xyzabc | 
|  | 484 | 123""", SUCCEED, 'found', 'abc'), | 
| Fredrik Lundh | 2643b55 | 2000-08-08 16:52:51 +0000 | [diff] [blame] | 485 |  | 
| Guido van Rossum | a0e4c1b | 1997-07-17 14:52:48 +0000 | [diff] [blame] | 486 |  | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 487 |  | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 488 | # test \w, etc. both inside and outside character classes | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 489 |  | 
|  | 490 | ('\\w+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'), | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 491 | ('[\\w]+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'), | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 492 | ('\\D+', '1234abc5678', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 493 | ('[\\D]+', '1234abc5678', SUCCEED, 'found', 'abc'), | 
| Guido van Rossum | 06c0ec9 | 1997-07-17 22:36:39 +0000 | [diff] [blame] | 494 | ('[\\da-fA-F]+', '123abc', SUCCEED, 'found', '123abc'), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 495 | # not an error under PCRE/PRE: | 
|  | 496 | # ('[\\d-x]', '-', SYNTAX_ERROR), | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 497 | (r'([\s]*)([\S]*)([\s]*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '), | 
|  | 498 | (r'(\s*)(\S*)(\s*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '), | 
|  | 499 |  | 
|  | 500 | (r'\xff', '\377', SUCCEED, 'found', chr(255)), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 501 | # new \x semantics | 
| Fredrik Lundh | 2e24044 | 2001-01-15 18:28:14 +0000 | [diff] [blame] | 502 | (r'\x00ff', '\377', FAIL), | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 503 | # (r'\x00ff', '\377', SUCCEED, 'found', chr(255)), | 
| Serhiy Storchaka | a54aae0 | 2015-03-24 22:58:14 +0200 | [diff] [blame] | 504 | (r'\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', '\t\n\v\r\f\a'), | 
|  | 505 | ('\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', '\t\n\v\r\f\a'), | 
| Guido van Rossum | 95e8053 | 1997-08-13 22:34:14 +0000 | [diff] [blame] | 506 | (r'\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)), | 
| Guido van Rossum | dfa6790 | 1997-12-08 17:12:06 +0000 | [diff] [blame] | 507 | (r'[\t][\n][\v][\r][\f][\b]', '\t\n\v\r\f\b', SUCCEED, 'found', '\t\n\v\r\f\b'), | 
| Fredrik Lundh | 8e6d571 | 2000-08-08 17:06:53 +0000 | [diff] [blame] | 508 |  | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 509 | # | 
|  | 510 | # post-1.5.2 additions | 
| Fredrik Lundh | 8e6d571 | 2000-08-08 17:06:53 +0000 | [diff] [blame] | 511 |  | 
|  | 512 | # xmllib problem | 
|  | 513 | (r'(([a-z]+):)?([a-z]+)$', 'smil', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-smil'), | 
| Fredrik Lundh | 2e24044 | 2001-01-15 18:28:14 +0000 | [diff] [blame] | 514 | # bug 110866: reference to undefined group | 
|  | 515 | (r'((.)\1+)', '', SYNTAX_ERROR), | 
|  | 516 | # bug 111869: search (PRE/PCRE fails on this one, SRE doesn't) | 
| Fredrik Lundh | 0c4fdba | 2000-08-31 22:57:55 +0000 | [diff] [blame] | 517 | (r'.*d', 'abc\nabd', SUCCEED, 'found', 'abd'), | 
| Fredrik Lundh | d11b5e5 | 2000-10-03 19:22:26 +0000 | [diff] [blame] | 518 | # bug 112468: various expected syntax errors | 
| Fredrik Lundh | 2e24044 | 2001-01-15 18:28:14 +0000 | [diff] [blame] | 519 | (r'(', '', SYNTAX_ERROR), | 
|  | 520 | (r'[\41]', '!', SUCCEED, 'found', '!'), | 
| Fredrik Lundh | 13ac992 | 2000-10-07 17:38:23 +0000 | [diff] [blame] | 521 | # bug 114033: nothing to repeat | 
|  | 522 | (r'(x?)?', 'x', SUCCEED, 'found', 'x'), | 
| Fredrik Lundh | d11b5e5 | 2000-10-03 19:22:26 +0000 | [diff] [blame] | 523 | # bug 115040: rescan if flags are modified inside pattern | 
| Serhiy Storchaka | bd48d27 | 2016-09-11 12:50:02 +0300 | [diff] [blame] | 524 | (r'(?x) foo ', 'foo', SUCCEED, 'found', 'foo'), | 
| Fredrik Lundh | d11b5e5 | 2000-10-03 19:22:26 +0000 | [diff] [blame] | 525 | # bug 115618: negative lookahead | 
| Fredrik Lundh | 65d4bc6 | 2000-10-03 16:29:23 +0000 | [diff] [blame] | 526 | (r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'), | 
| Fredrik Lundh | 025468d | 2000-10-07 10:16:19 +0000 | [diff] [blame] | 527 | # bug 116251: character class bug | 
|  | 528 | (r'[\w-]+', 'laser_beam', SUCCEED, 'found', 'laser_beam'), | 
| Fredrik Lundh | 2e24044 | 2001-01-15 18:28:14 +0000 | [diff] [blame] | 529 | # bug 123769+127259: non-greedy backtracking bug | 
|  | 530 | (r'.*?\S *:', 'xx:', SUCCEED, 'found', 'xx:'), | 
|  | 531 | (r'a[ ]*?\ (\d+).*', 'a   10', SUCCEED, 'found', 'a   10'), | 
|  | 532 | (r'a[ ]*?\ (\d+).*', 'a    10', SUCCEED, 'found', 'a    10'), | 
|  | 533 | # bug 127259: \Z shouldn't depend on multiline mode | 
|  | 534 | (r'(?ms).*?x\s*\Z(.*)','xx\nx\n', SUCCEED, 'g1', ''), | 
|  | 535 | # bug 128899: uppercase literals under the ignorecase flag | 
|  | 536 | (r'(?i)M+', 'MMM', SUCCEED, 'found', 'MMM'), | 
|  | 537 | (r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'), | 
|  | 538 | (r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'), | 
|  | 539 | (r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'), | 
| Fredrik Lundh | c0c7ee3 | 2001-02-18 21:04:48 +0000 | [diff] [blame] | 540 | # bug 130748: ^* should be an error (nothing to repeat) | 
|  | 541 | (r'^*', '', SYNTAX_ERROR), | 
| Fredrik Lundh | 82b2307 | 2001-12-09 16:13:15 +0000 | [diff] [blame] | 542 | # bug 133283: minimizing repeat problem | 
|  | 543 | (r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\""'), | 
|  | 544 | # bug 477728: minimizing repeat problem | 
|  | 545 | (r'^.*?$', 'one\ntwo\nthree\n', FAIL), | 
|  | 546 | # bug 483789: minimizing repeat problem | 
|  | 547 | (r'a[^>]*?b', 'a>b', FAIL), | 
|  | 548 | # bug 490573: minimizing repeat problem | 
|  | 549 | (r'^a*?$', 'foo', FAIL), | 
| Gustavo Niemeyer | 4e7be06 | 2002-11-06 14:06:53 +0000 | [diff] [blame] | 550 | # bug 470582: nested groups problem | 
|  | 551 | (r'^((a)c)?(ab)$', 'ab', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-ab'), | 
| Gustavo Niemeyer | be733ee | 2003-04-20 07:35:44 +0000 | [diff] [blame] | 552 | # another minimizing repeat problem (capturing groups in assertions) | 
|  | 553 | ('^([ab]*?)(?=(b)?)c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), | 
|  | 554 | ('^([ab]*?)(?!(b))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), | 
|  | 555 | ('^([ab]*?)(?<!(a))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), | 
| Guido van Rossum | 16bd0ff | 1997-07-15 18:45:20 +0000 | [diff] [blame] | 556 | ] | 
| Fredrik Lundh | b25e1ad | 2001-03-22 15:50:10 +0000 | [diff] [blame] | 557 |  | 
| Antoine Pitrou | 22628c4 | 2008-07-22 17:53:22 +0000 | [diff] [blame] | 558 | u = '\N{LATIN CAPITAL LETTER A WITH DIAERESIS}' | 
|  | 559 | tests.extend([ | 
| Fredrik Lundh | b25e1ad | 2001-03-22 15:50:10 +0000 | [diff] [blame] | 560 | # bug 410271: \b broken under locales | 
|  | 561 | (r'\b.\b', 'a', SUCCEED, 'found', 'a'), | 
|  | 562 | (r'(?u)\b.\b', u, SUCCEED, 'found', u), | 
| Guido van Rossum | 577fb5a | 2003-02-24 01:18:35 +0000 | [diff] [blame] | 563 | (r'(?u)\w', u, SUCCEED, 'found', u), | 
| Antoine Pitrou | fd03645 | 2008-08-19 17:56:33 +0000 | [diff] [blame] | 564 | ]) |