Commit | Line | Data |
---|---|---|
b45f050a JF |
1 | #!./perl -w |
2 | ||
21adcf33 KW |
3 | $|=1; # outherwise things get mixed up in output |
4 | ||
b45f050a JF |
5 | BEGIN { |
6 | chdir 't' if -d 't'; | |
cc7e6304 | 7 | @INC = qw '../lib ../ext/re'; |
cb79f740 | 8 | require './test.pl'; |
2b08d1e2 | 9 | skip_all_without_unicode_tables(); |
cb79f740 | 10 | eval 'require Config'; # assume defaults if this fails |
b45f050a JF |
11 | } |
12 | ||
cb79f740 | 13 | use strict; |
c1d900c3 | 14 | use open qw(:utf8 :std); |
b45f050a JF |
15 | |
16 | ## | |
17 | ## If the markers used are changed (search for "MARKER1" in regcomp.c), | |
cb79f740 | 18 | ## update only these two regexs, and leave the {#} in the @death/@warning |
b45f050a JF |
19 | ## arrays below. The {#} is a meta-marker -- it marks where the marker should |
20 | ## go. | |
cb79f740 | 21 | ## |
af01601c KW |
22 | ## Returns empty string if that is what is expected. Otherwise, handles |
23 | ## either a scalar, turning it into a single element array; or a ref to an | |
24 | ## array, adjusting each element. If called in array context, returns an | |
25 | ## array, otherwise the join of all elements | |
26 | ||
cb79f740 | 27 | sub fixup_expect { |
af01601c | 28 | my $expect_ref = shift; |
63374c78 | 29 | return "" if $expect_ref eq ""; |
af01601c KW |
30 | |
31 | my @expect; | |
32 | if (ref $expect_ref) { | |
33 | @expect = @$expect_ref; | |
34 | } | |
35 | else { | |
36 | @expect = $expect_ref; | |
37 | } | |
38 | ||
39 | foreach my $element (@expect) { | |
6d24e9d4 | 40 | $element =~ s/{\#}/in regex; marked by <-- HERE in/; |
af01601c KW |
41 | $element =~ s/{\#}/ <-- HERE /; |
42 | $element .= " at "; | |
43 | } | |
44 | return wantarray ? @expect : join "", @expect; | |
cb79f740 | 45 | } |
b45f050a | 46 | |
c1d900c3 | 47 | ## Because we don't "use utf8" in this file, we need to do some extra legwork |
b0e1d434 KW |
48 | ## for the utf8 tests: Prepend 'use utf8' to the pattern, and mark the strings |
49 | ## to check against as UTF-8, but for this all to work properly, the character | |
50 | ## 'ネ' (U+30CD) is required in each pattern somewhere as a marker. | |
4cabb89a BF |
51 | ## |
52 | ## This also creates a second variant of the tests to check if the | |
b0e1d434 KW |
53 | ## latin1 error messages are working correctly. Because we don't 'use utf8', |
54 | ## we can't tell if something is UTF-8 or Latin1, so you need the suffix | |
55 | ## '; no latin1' to not have the second variant. | |
4cabb89a BF |
56 | my $l1 = "\x{ef}"; |
57 | my $utf8 = "\x{30cd}"; | |
58 | utf8::encode($utf8); | |
59 | ||
c1d900c3 BF |
60 | sub mark_as_utf8 { |
61 | my @ret; | |
67cdf558 KW |
62 | for (my $i = 0; $i < @_; $i += 2) { |
63 | my $pat = $_[$i]; | |
64 | my $msg = $_[$i+1]; | |
4cabb89a BF |
65 | my $l1_pat = $pat =~ s/$utf8/$l1/gr; |
66 | my $l1_msg; | |
c1d900c3 | 67 | $pat = "use utf8; $pat"; |
b0e1d434 | 68 | |
c1d900c3 | 69 | if (ref $msg) { |
4cabb89a BF |
70 | $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ]; |
71 | @$msg = map { my $c = $_; utf8::decode($c); $c } @$msg; | |
c1d900c3 BF |
72 | } |
73 | else { | |
4cabb89a | 74 | $l1_msg = $msg =~ s/$utf8/$l1/gr; |
c1d900c3 BF |
75 | utf8::decode($msg); |
76 | } | |
77 | push @ret, $pat => $msg; | |
b0e1d434 | 78 | |
4cabb89a | 79 | push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/; |
c1d900c3 BF |
80 | } |
81 | return @ret; | |
82 | } | |
83 | ||
cb79f740 NC |
84 | my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1; |
85 | my $inf_p1 = $inf_m1 + 2; | |
b45f050a | 86 | |
c877af1b KW |
87 | my $B_hex = sprintf("\\x%02X", ord "B"); |
88 | my $low_mixed_alpha = ('A' lt 'a') ? 'A' : 'a'; | |
89 | my $high_mixed_alpha = ('A' lt 'a') ? 'a' : 'A'; | |
90 | my $low_mixed_digit = ('A' lt '0') ? 'A' : '0'; | |
91 | my $high_mixed_digit = ('A' lt '0') ? '0' : 'A'; | |
92 | ||
b45f050a JF |
93 | ## |
94 | ## Key-value pairs of code/error of code that should have fatal errors. | |
95 | ## | |
96 | my @death = | |
97 | ( | |
6d24e9d4 | 98 | '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/', |
b45f050a | 99 | |
58e23c8d | 100 | '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/', |
b45f050a | 101 | |
58e23c8d | 102 | '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/', |
b45f050a | 103 | |
6d24e9d4 | 104 | '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/', |
b45f050a | 105 | |
9da1dd8f | 106 | '/(?{ 1/' => 'Missing right curly or square bracket', |
b45f050a | 107 | |
6d24e9d4 | 108 | '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/', |
311cc1ad | 109 | '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/', |
b45f050a | 110 | |
8fb0127d YO |
111 | '/(?(1)/' => 'Switch (?(condition)... not terminated {#} m/(?(1){#}/', |
112 | '/(?(1)x/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x{#}/', | |
113 | '/(?(1)x|y/' => 'Switch (?(condition)... not terminated {#} m/(?(1)x|y{#}/', | |
6d24e9d4 | 114 | '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/', |
b45f050a | 115 | |
c1d900c3 | 116 | '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/', |
10380cb3 FC |
117 | '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/', |
118 | '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/', | |
b45f050a | 119 | |
6d24e9d4 | 120 | '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/', |
b45f050a | 121 | |
6d24e9d4 KW |
122 | '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/', |
123 | '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/', | |
124 | '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/', | |
125 | '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/', | |
126 | '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/', | |
127 | '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/', | |
128 | '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/', | |
129 | '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/', | |
130 | '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/', | |
131 | '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/', | |
132 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
133 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/', | |
134 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/', | |
135 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/', | |
136 | '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/', | |
137 | '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/', | |
138 | '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/', | |
139 | '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/', | |
140 | '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/', | |
141 | '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/', | |
32d02813 KW |
142 | '/a\b{cde/' => 'Use "\b\{" instead of "\b{" {#} m/a\{#}b{cde/', |
143 | '/a\B{cde/' => 'Use "\B\{" instead of "\B{" {#} m/a\{#}B{cde/', | |
cc74c5bd | 144 | |
6d24e9d4 | 145 | '/((x)/' => 'Unmatched ( {#} m/({#}(x)/', |
b45f050a | 146 | |
6d24e9d4 | 147 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/", |
b45f050a | 148 | |
b45f050a | 149 | |
6d24e9d4 | 150 | '/x**/' => 'Nested quantifiers {#} m/x**{#}/', |
b45f050a | 151 | |
6d24e9d4 | 152 | '/x[/' => 'Unmatched [ {#} m/x[{#}/', |
b45f050a | 153 | |
6d24e9d4 | 154 | '/*/', => 'Quantifier follows nothing {#} m/*{#}/', |
b45f050a | 155 | |
6d24e9d4 | 156 | '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/', |
b45f050a | 157 | |
6d24e9d4 | 158 | '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/', |
b45f050a | 159 | |
6d24e9d4 | 160 | '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/', |
b45f050a | 161 | |
779fedd7 | 162 | '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/', |
76cccc4d KW |
163 | '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/', |
164 | ||
40809656 | 165 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 166 | |
6d24e9d4 KW |
167 | '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/', |
168 | '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/', | |
169 | ||
170 | '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/', | |
171 | '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/', | |
172 | ||
173 | '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/', | |
174 | '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/', | |
175 | ||
176 | '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/', | |
177 | '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/', | |
178 | ||
179 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/', | |
180 | ||
181 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/', | |
182 | ||
183 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/', | |
184 | ||
185 | '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/', | |
186 | ||
187 | '/\p/' => 'Empty \p{} {#} m/\p{#}/', | |
188 | ||
189 | '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/', | |
190 | '/(?[[[:word]]])/' => "Unmatched ':' in POSIX class {#} m/(?[[[:word{#}]]])/", | |
191 | '/(?[[:word]])/' => "Unmatched ':' in POSIX class {#} m/(?[[:word{#}]])/", | |
192 | '/(?[[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[[:digit:{#} ])/", | |
193 | '/(?[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[:digit:{#} ])/", | |
194 | '/(?[[[::]]])/' => "POSIX class [::] unknown {#} m/(?[[[::]{#}]])/", | |
195 | '/(?[[[:w:]]])/' => "POSIX class [:w:] unknown {#} m/(?[[[:w:]{#}]])/", | |
196 | '/(?[[:w:]])/' => "POSIX class [:w:] unknown {#} m/(?[[:w:]{#}])/", | |
197 | '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/', | |
198 | '/(?[\t])/l' => '(?[...]) not valid in locale {#} m/(?[{#}\t])/', | |
199 | '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/', | |
200 | '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/', | |
201 | '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/', | |
202 | '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/', | |
203 | '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/', | |
204 | '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/', | |
205 | '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/', | |
206 | '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/', | |
207 | '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/', | |
208 | '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/', | |
209 | '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/', | |
210 | '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/', | |
211 | '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/', | |
212 | '/(?[ \p{foo} ])/' => 'Property \'foo\' is unknown {#} m/(?[ \p{foo}{#} ])/', | |
213 | '/(?[ \p{ foo = bar } ])/' => 'Property \'foo = bar\' is unknown {#} m/(?[ \p{ foo = bar }{#} ])/', | |
214 | '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/', | |
3f4fde43 KW |
215 | '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/', |
216 | '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/', | |
217 | '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/', | |
218 | '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/', | |
219 | '/(?[ \t + \e # This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # This was supposed to be a comment ])/', | |
6d24e9d4 KW |
220 | '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/', |
221 | 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/', | |
222 | 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/', | |
223 | 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/', | |
224 | 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/', | |
8f0cd35a | 225 | 'm/(?[[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/(?[[^\N{U+100.300{#}}]])/', |
b5864679 KW |
226 | 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/', |
227 | 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/', | |
6d24e9d4 KW |
228 | 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/', |
229 | 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/', | |
230 | 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/', | |
231 | 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/', | |
232 | 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/', | |
233 | 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/', | |
234 | 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
f1e1b256 YO |
235 | 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/', |
236 | 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/', | |
237 | 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/', | |
07ea66ee FC |
238 | 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/', |
239 | 'm/(?&a/' => 'Sequence (?&... not terminated {#} m/(?&a{#}/', | |
75839571 FC |
240 | 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/', |
241 | "m/(?'/" => "Sequence (?'... not terminated {#} m/(?'{#}/", | |
242 | "m/(?</" => "Sequence (?<... not terminated {#} m/(?<{#}/", | |
243 | 'm/(?&/' => 'Sequence (?&... not terminated {#} m/(?&{#}/', | |
244 | 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/', | |
245 | "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/", | |
246 | 'm/\g{/' => 'Sequence \g{... not terminated {#} m/\g{{#}/', | |
247 | 'm/\k</' => 'Sequence \k<... not terminated {#} m/\k<{#}/', | |
9b8f4e92 | 248 | 'm/\cß/' => "Character following \"\\c\" must be printable ASCII", |
cd209d9d KW |
249 | '/((?# This is a comment in the middle of a token)?:foo)/' => 'In \'(?...)\', the \'(\' and \'?\' must be adjacent {#} m/((?# This is a comment in the middle of a token)?{#}:foo)/', |
250 | '/((?# This is a comment in the middle of a token)*FAIL)/' => 'In \'(*VERB...)\', the \'(\' and \'*\' must be adjacent {#} m/((?# This is a comment in the middle of a token)*{#}FAIL)/', | |
b45f050a | 251 | ); |
c1d900c3 | 252 | |
67cdf558 KW |
253 | # These are messages that are warnings when not strict; death under 'use re |
254 | # "strict". See comment before @warnings as to why some have a \x{100} in | |
255 | # them. This array has 3 elements per construct. [0] is the regex to use; | |
256 | # [1] is the message under no strict, and [2] is under strict. | |
257 | my @death_only_under_strict = ( | |
258 | 'm/\xABC/' => "", | |
259 | => 'Use \x{...} for more than two hex characters {#} m/\xABC{#}/', | |
260 | 'm/[\xABC]/' => "", | |
261 | => 'Use \x{...} for more than two hex characters {#} m/[\xABC{#}]/', | |
262 | ||
263 | # XXX This is a confusing error message. The G isn't ignored; it just | |
264 | # terminates the \x. Also some messages below are missing the <-- HERE, | |
265 | # aren't all category 'regexp'. (Hence we have to turn off 'digit' | |
266 | # messages as well below) | |
267 | 'm/\xAG/' => 'Illegal hexadecimal digit \'G\' ignored', | |
268 | => 'Non-hex character {#} m/\xAG{#}/', | |
269 | 'm/[\xAG]/' => 'Illegal hexadecimal digit \'G\' ignored', | |
270 | => 'Non-hex character {#} m/[\xAG{#}]/', | |
271 | 'm/\o{789}/' => 'Non-octal character \'8\'. Resolved as "\o{7}"', | |
272 | => 'Non-octal character {#} m/\o{78{#}9}/', | |
273 | 'm/[\o{789}]/' => 'Non-octal character \'8\'. Resolved as "\o{7}"', | |
274 | => 'Non-octal character {#} m/[\o{78{#}9}]/', | |
275 | 'm/\x{}/' => "", | |
276 | => 'Number with no digits {#} m/\x{}{#}/', | |
277 | 'm/[\x{}]/' => "", | |
278 | => 'Number with no digits {#} m/[\x{}{#}]/', | |
279 | 'm/\x{ABCDEFG}/' => 'Illegal hexadecimal digit \'G\' ignored', | |
280 | => 'Non-hex character {#} m/\x{ABCDEFG{#}}/', | |
281 | 'm/[\x{ABCDEFG}]/' => 'Illegal hexadecimal digit \'G\' ignored', | |
282 | => 'Non-hex character {#} m/[\x{ABCDEFG{#}}]/', | |
283 | 'm/[[:ascii]]/' => "", | |
284 | => 'Unmatched \':\' in POSIX class {#} m/[[:ascii{#}]]/', | |
285 | 'm/[\N{}]/' => 'Ignoring zero length \\N{} in character class {#} m/[\\N{}{#}]/', | |
286 | => 'Zero length \\N{} {#} m/[\\N{}]{#}/', | |
287 | "m'[\\y]\\x{100}'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]\x{100}/', | |
288 | => 'Unrecognized escape \y in character class {#} m/[\y{#}]\x{100}/', | |
289 | 'm/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
290 | => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
291 | 'm/[\w-x]\x{100}/' => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/', | |
292 | => 'False [] range "\w-" {#} m/[\w-{#}x]\x{100}/', | |
293 | 'm/[a-\pM]\x{100}/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/', | |
294 | => 'False [] range "a-\pM" {#} m/[a-\pM{#}]\x{100}/', | |
295 | 'm/[\pM-x]\x{100}/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/', | |
296 | => 'False [] range "\pM-" {#} m/[\pM-{#}x]\x{100}/', | |
297 | 'm/[^\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[^\N{U+100.300}{#}]/', | |
298 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[^\N{U+100.300{#}}]/', | |
299 | 'm/[\x03-\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\x03-\N{U+100.300}{#}]/', | |
300 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\x03-\N{U+100.300{#}}]/', | |
301 | 'm/[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}-\x{10FFFF}]/' => 'Using just the first character returned by \N{} in character class {#} m/[\N{U+100.300}{#}-\x{10FFFF}]/', | |
302 | => '\N{} in inverted character class or as a range end-point is restricted to one character {#} m/[\N{U+100.300{#}}-\x{10FFFF}]/', | |
303 | '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/', | |
304 | => 'Need exactly 3 octal digits {#} m/[\08{#}]/', | |
305 | '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/', | |
306 | => 'Need exactly 3 octal digits {#} m/[\018{#}]/', | |
307 | '/[\_\0]/' => "", | |
308 | => 'Need exactly 3 octal digits {#} m/[\_\0]{#}/', | |
309 | '/[\07]/' => "", | |
310 | => 'Need exactly 3 octal digits {#} m/[\07]{#}/', | |
311 | '/[\0005]/' => "", | |
312 | => 'Need exactly 3 octal digits {#} m/[\0005]{#}/', | |
313 | '/[\8\9]\x{100}/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]\x{100}/', | |
314 | 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]\x{100}/', | |
315 | ], | |
316 | => 'Unrecognized escape \8 in character class {#} m/[\8{#}\9]\x{100}/', | |
317 | '/[a-\d]\x{100}/' => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
318 | => 'False [] range "a-\d" {#} m/[a-\d{#}]\x{100}/', | |
319 | '/[\d-b]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/', | |
320 | => 'False [] range "\d-" {#} m/[\d-{#}b]\x{100}/', | |
321 | '/[\s-\d]\x{100}/' => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/', | |
322 | => 'False [] range "\s-" {#} m/[\s-{#}\d]\x{100}/', | |
323 | '/[\d-\s]\x{100}/' => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/', | |
324 | => 'False [] range "\d-" {#} m/[\d-{#}\s]\x{100}/', | |
325 | '/[a-[:digit:]]\x{100}/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/', | |
326 | => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]\x{100}/', | |
327 | '/[[:digit:]-b]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/', | |
328 | => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]\x{100}/', | |
329 | '/[[:alpha:]-[:digit:]]\x{100}/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/', | |
330 | => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]\x{100}/', | |
331 | '/[[:digit:]-[:alpha:]]\x{100}/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/', | |
332 | => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]\x{100}/', | |
333 | '/[a\zb]\x{100}/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]\x{100}/', | |
334 | => 'Unrecognized escape \z in character class {#} m/[a\z{#}b]\x{100}/', | |
335 | ); | |
336 | ||
b0e1d434 | 337 | # These need the character 'ネ' as a marker for mark_as_utf8() |
c1d900c3 BF |
338 | my @death_utf8 = mark_as_utf8( |
339 | '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/', | |
340 | '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/', | |
341 | ||
342 | '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/', | |
343 | ||
344 | '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/', | |
345 | ||
476afc4b | 346 | '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/', |
c1d900c3 BF |
347 | |
348 | '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/', | |
349 | ||
350 | '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/', | |
351 | ||
352 | '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/', | |
353 | ||
354 | '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/', | |
355 | '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/', | |
356 | '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/', | |
357 | '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/', | |
358 | '/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/', | |
359 | '/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/', | |
360 | '/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/', | |
361 | ||
362 | '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/', | |
363 | ||
364 | "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/", | |
365 | ||
366 | ||
367 | '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/', | |
368 | ||
369 | '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/', | |
370 | ||
371 | '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/', | |
372 | ||
373 | '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/', | |
374 | ||
375 | '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/', | |
376 | ||
4cabb89a | 377 | '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/', |
c1d900c3 BF |
378 | |
379 | 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/', | |
380 | ||
381 | '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/', | |
382 | '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/', | |
383 | '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/', | |
384 | ||
385 | '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/', | |
386 | '/ネ[[:ネ:]]ネ/' => 'POSIX class [:ネ:] unknown {#} m/ネ[[:ネ:]{#}]ネ/', | |
387 | ||
388 | '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/', | |
389 | ||
390 | '/ネ[[.ネ.]]ネ/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/ネ[[.ネ.]{#}]ネ/', | |
391 | ||
392 | '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/', | |
393 | ||
394 | '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/', | |
395 | ||
396 | '/ネ(?[[[:ネ]]])ネ/' => "Unmatched ':' in POSIX class {#} m/ネ(?[[[:ネ{#}]]])ネ/", | |
397 | '/ネ(?[[[:ネ: ])ネ/' => "Unmatched '[' in POSIX class {#} m/ネ(?[[[:ネ:{#} ])ネ/", | |
398 | '/ネ(?[[[::]]])ネ/' => "POSIX class [::] unknown {#} m/ネ(?[[[::]{#}]])ネ/", | |
399 | '/ネ(?[[[:ネ:]]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[[:ネ:]{#}]])ネ/", | |
400 | '/ネ(?[[:ネ:]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[:ネ:]{#}])ネ/", | |
401 | '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/', | |
402 | '/ネ(?[ネ])/l' => '(?[...]) not valid in locale {#} m/ネ(?[{#}ネ])/', | |
403 | '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/', | |
404 | '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/', | |
405 | '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/', | |
406 | '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/', | |
407 | '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/', | |
408 | '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/', | |
409 | '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/', | |
410 | '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/', | |
411 | '/(?[ \p{ネ} ])/' => 'Property \'ネ\' is unknown {#} m/(?[ \p{ネ}{#} ])/', | |
412 | '/(?[ \p{ ネ = bar } ])/' => 'Property \'ネ = bar\' is unknown {#} m/(?[ \p{ ネ = bar }{#} ])/', | |
413 | '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/', | |
414 | '/(?[ \t + \e # ネ This was supposed to be a comment ])/' => 'Syntax error in (?[...]) in regex m/(?[ \t + \e # ネ This was supposed to be a comment ])/', | |
9b8f4e92 KW |
415 | 'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>, |
416 | '/\cネ/' => "Character following \"\\c\" must be printable ASCII", | |
c1d900c3 BF |
417 | ); |
418 | push @death, @death_utf8; | |
419 | ||
67cdf558 KW |
420 | my @death_utf8_only_under_strict = ( |
421 | "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/', | |
422 | => 'Unrecognized escape \y in character class {#} m/ネ[\y{#}]ネ/', | |
423 | 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/', | |
424 | => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/', | |
425 | 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/', | |
426 | => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/', | |
427 | 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/', | |
428 | => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/', | |
429 | '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/', | |
430 | => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/', | |
431 | '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/', | |
432 | => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/', | |
433 | '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/', | |
434 | => 'Unrecognized escape \z in character class {#} m/ネ[a\z{#}b]ネ/', | |
435 | ); | |
902994e4 | 436 | # Tests involving a user-defined charnames translator are in pat_advanced.t |
b45f050a | 437 | |
af01601c KW |
438 | # In the following arrays of warnings, the value can be an array of things to |
439 | # expect. If the empty string, it means no warning should be raised. | |
440 | ||
6d24e9d4 | 441 | |
499333dc KW |
442 | # Key-value pairs of code/error of code that should have non-fatal regexp |
443 | # warnings. Most currently have \x{100} appended to them to force them to be | |
444 | # upgraded to UTF-8, and the first pass restarted. Previously this would | |
445 | # cause some warnings to be output twice. This tests that that behavior has | |
446 | # been fixed. | |
6d24e9d4 | 447 | |
499333dc KW |
448 | my @warning = ( |
449 | 'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/', | |
450 | 'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/', | |
499333dc | 451 | "m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/', |
6d24e9d4 KW |
452 | '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/', |
453 | '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/', | |
454 | '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/', | |
6d24e9d4 KW |
455 | '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/', |
456 | 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/', | |
457 | '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/', | |
499333dc | 458 | |
e1729dc6 FC |
459 | # These two tests do not include the marker, because regcomp.c no |
460 | # longer knows where it goes by the time this warning is emitted. | |
461 | # See [perl #122680] regcomp warning gives wrong position of | |
499333dc | 462 | # problem. |
e1729dc6 FC |
463 | '/(?=a){1,3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(?=a){1,3}\x{100}/', |
464 | '/(a|b)(?=a){3}\x{100}/' => 'Quantifier unexpected on zero-length expression in regex m/(a|b)(?=a){3}\x{100}/', | |
499333dc | 465 | |
63fbd1cb | 466 | '/\_/' => "", |
63fbd1cb | 467 | '/[\006]/' => "", |
499333dc KW |
468 | '/[:alpha:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}\x{100}/', |
469 | '/[:zog:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:zog:]{#}\x{100}/', | |
470 | '/[.zog.]\x{100}/' => 'POSIX syntax [. .] belongs inside character classes {#} m/[.zog.]{#}\x{100}/', | |
63fbd1cb | 471 | '/[a-b]/' => "", |
499333dc KW |
472 | '/(?c)\x{100}/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})\x{100}/', |
473 | '/(?-c)\x{100}/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})\x{100}/', | |
474 | '/(?g)\x{100}/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})\x{100}/', | |
475 | '/(?-g)\x{100}/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})\x{100}/', | |
476 | '/(?o)\x{100}/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})\x{100}/', | |
477 | '/(?-o)\x{100}/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})\x{100}/', | |
478 | '/(?g-o)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)\x{100}/', | |
479 | 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})\x{100}/', | |
63fbd1cb | 480 | ], |
499333dc KW |
481 | '/(?g-c)\x{100}/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)\x{100}/', |
482 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})\x{100}/', | |
63fbd1cb KW |
483 | ], |
484 | # (?c) means (?g) error won't be thrown | |
499333dc KW |
485 | '/(?o-cg)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)\x{100}/', |
486 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)\x{100}/', | |
63fbd1cb | 487 | ], |
499333dc KW |
488 | '/(?ogc)\x{100}/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)\x{100}/', |
489 | 'Useless (?g) - use /g modifier {#} m/(?og{#}c)\x{100}/', | |
490 | 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})\x{100}/', | |
63fbd1cb | 491 | ], |
499333dc KW |
492 | '/a{1,1}?\x{100}/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}\x{100}/', |
493 | '/b{3} +\x{100}/x' => 'Useless use of greediness modifier \'+\' {#} m/b{3} +{#}\x{100}/', | |
c877af1b KW |
494 | "/(?[ [ % - % ] ])/" => "", |
495 | "/(?[ [ $B_hex - C ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $B_hex - C {#}] ])/", | |
496 | "/(?[ [ A - $B_hex ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ A - $B_hex {#}] ])/", | |
497 | "/(?[ [ $low_mixed_alpha - $high_mixed_alpha ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_alpha - $high_mixed_alpha {#}] ])/", | |
498 | "/(?[ [ $low_mixed_digit - $high_mixed_digit ] ])/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/(?[ [ $low_mixed_digit - $high_mixed_digit {#}] ])/", | |
499333dc | 499 | ); # See comments before this for why '\x{100}' is generally needed |
6fe2934b | 500 | |
b0e1d434 | 501 | # These need the character 'ネ' as a marker for mark_as_utf8() |
c1d900c3 BF |
502 | my @warnings_utf8 = mark_as_utf8( |
503 | 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/', | |
504 | '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/', | |
505 | 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes {#} m/ネ[:foo:]{#}ネ/', | |
b0e1d434 | 506 | '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/', |
c1d900c3 BF |
507 | '/utf8 ネ (?ogc) ネ/' => [ |
508 | 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/', | |
509 | 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/', | |
510 | 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/', | |
511 | ], | |
512 | ||
513 | ); | |
514 | ||
515 | push @warning, @warnings_utf8; | |
516 | ||
63374c78 | 517 | my @warning_only_under_strict = ( |
b927b7e9 KW |
518 | '/[\N{U+00}-\x01]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+00}-\x01{#}]\x{100}/', |
519 | '/[\x00-\N{SOH}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\x00-\N{U+01}{#}]\x{100}/', | |
520 | '/[\N{DEL}-\o{377}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\o{377}{#}]\x{100}/', | |
521 | '/[\o{0}-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\o{0}-\N{U+01}{#}]\x{100}/', | |
522 | '/[\000-\N{U+01}]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\000-\N{U+01}{#}]\x{100}/', | |
523 | '/[\N{DEL}-\377]\x{100}/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+7F}-\377{#}]\x{100}/', | |
c877af1b KW |
524 | '/[\N{U+00}-A]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[\N{U+00}-A{#}]\x{100}/', |
525 | '/[a-\N{U+FF}]\x{100}/' => 'Ranges of ASCII printables should be some subset of "0-9", "A-Z", or "a-z" {#} m/[a-\N{U+FF}{#}]\x{100}/', | |
b927b7e9 KW |
526 | '/[\N{U+00}-\a]\x{100}/' => "", |
527 | '/[\a-\N{U+FF}]\x{100}/' => "", | |
528 | '/[\N{U+FF}-\x{100}]/' => 'Both or neither range ends should be Unicode {#} m/[\N{U+FF}-\x{100}{#}]/', | |
529 | '/[\N{U+100}-\x{101}]/' => "", | |
c877af1b KW |
530 | "/[%-%]/" => "", |
531 | "/[$B_hex-C]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$B_hex-C{#}]/", | |
532 | "/[A-$B_hex]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[A-$B_hex\{#}]/", | |
533 | "/[$low_mixed_alpha-$high_mixed_alpha]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_alpha-$high_mixed_alpha\{#}]/", | |
534 | "/[$low_mixed_digit-$high_mixed_digit]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_digit-$high_mixed_digit\{#}]/", | |
535 | ); | |
536 | ||
537 | my @warning_utf8_only_under_strict = mark_as_utf8( | |
538 | '/ネ[᪉-᪐]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᪉-᪐{#}]/", | |
539 | '/ネ(?[ [ ᪉ - ᪐ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᪉ - ᪐ {#}] ])/", | |
540 | '/ネ[᧙-᧚]/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ[᧙-᧚{#}]/", | |
541 | '/ネ(?[ [ ᧙ - ᧚ ] ])/; #no latin1' => "Ranges of digits should be from the same group of 10 {#} m/ネ(?[ [ ᧙ - ᧚ {#}] ])/", | |
63374c78 KW |
542 | ); |
543 | ||
c877af1b KW |
544 | push @warning_only_under_strict, @warning_utf8_only_under_strict; |
545 | ||
6fe2934b | 546 | my @experimental_regex_sets = ( |
6d24e9d4 | 547 | '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/', |
c1d900c3 BF |
548 | 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' }, |
549 | '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/', | |
b45f050a JF |
550 | ); |
551 | ||
63fbd1cb | 552 | my @deprecated = ( |
412f55bb KW |
553 | '/\w{/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/\w{{#}/', |
554 | '/\q{/' => [ | |
555 | 'Unrecognized escape \q{ passed through {#} m/\q{{#}/', | |
556 | 'Unescaped left brace in regex is deprecated, passed through {#} m/\q{{#}/' | |
557 | ], | |
558 | '/:{4,a}/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/:{{#}4,a}/', | |
cc4d09e1 KW |
559 | '/abc/xix' => 'Having more than one /x regexp modifier is deprecated', |
560 | '/(?xmsixp:abc)/' => 'Having more than one /x regexp modifier is deprecated', | |
561 | '/(?xmsixp)abc/' => 'Having more than one /x regexp modifier is deprecated', | |
562 | '/(?xxxx:abc)/' => 'Having more than one /x regexp modifier is deprecated', | |
63fbd1cb KW |
563 | ); |
564 | ||
67cdf558 KW |
565 | for my $strict ("", "use re 'strict';") { |
566 | ||
567 | # First time just use @death; but under strict we add the things that fail | |
568 | # there. Doing it this way makes sure that 'strict' doesnt change the | |
569 | # things that are already fatal when not under strict. | |
570 | if ($strict) { | |
571 | for (my $i = 0; $i < @death_only_under_strict; $i += 3) { | |
572 | push @death, $death_only_under_strict[$i], # The regex | |
573 | $death_only_under_strict[$i+2]; # The fatal msg | |
574 | } | |
575 | for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) { | |
576 | ||
577 | # Same with the utf8 versions | |
578 | push @death, mark_as_utf8($death_utf8_only_under_strict[$i], | |
579 | $death_utf8_only_under_strict[$i+2]); | |
580 | } | |
581 | } | |
d6609144 KW |
582 | for (my $i = 0; $i < @death; $i += 2) { |
583 | my $regex = $death[$i]; | |
584 | my $expect = fixup_expect($death[$i+1]); | |
585 | no warnings 'experimental::regex_sets'; | |
586 | no warnings 'experimental::re_strict'; | |
d6609144 KW |
587 | |
588 | warning_is(sub { | |
589 | my $eval_string = "$strict $regex"; | |
590 | $_ = "x"; | |
591 | eval $eval_string; | |
592 | like($@, qr/\Q$expect/, $eval_string); | |
593 | }, undef, "... and died without any other warnings"); | |
594 | } | |
67cdf558 | 595 | } |
b45f050a | 596 | |
63374c78 KW |
597 | for my $strict ("", "no warnings 'experimental::re_strict'; use re 'strict';") { |
598 | my @warning_tests = @warning; | |
67cdf558 | 599 | |
63374c78 KW |
600 | # Build the tests for @warning. Use the strict/non-strict versions |
601 | # appropriately. | |
602 | if ($strict) { | |
603 | push @warning_tests, @warning_only_under_strict; | |
604 | } | |
605 | else { | |
606 | for (my $i = 0; $i < @warning_only_under_strict; $i += 2) { | |
607 | if ($warning_only_under_strict[$i] =~ /\Q(?[/) { | |
608 | push @warning_tests, $warning_only_under_strict[$i], # The regex | |
609 | $warning_only_under_strict[$i+1]; | |
610 | } | |
611 | else { | |
612 | push @warning_tests, $warning_only_under_strict[$i], # The regex | |
613 | ""; # No warning because not strict | |
614 | } | |
615 | } | |
67cdf558 | 616 | for (my $i = 0; $i < @death_only_under_strict; $i += 3) { |
63374c78 KW |
617 | push @warning_tests, $death_only_under_strict[$i], # The regex |
618 | $death_only_under_strict[$i+1]; # The warning | |
67cdf558 KW |
619 | } |
620 | for (my $i = 0; $i < @death_utf8_only_under_strict; $i += 3) { | |
63374c78 | 621 | push @warning_tests, mark_as_utf8($death_utf8_only_under_strict[$i], |
d6609144 | 622 | $death_utf8_only_under_strict[$i+1]); |
67cdf558 KW |
623 | } |
624 | } | |
d6609144 | 625 | |
63374c78 | 626 | foreach my $ref (\@warning_tests, \@experimental_regex_sets, \@deprecated) { |
d6609144 | 627 | my $warning_type; |
63374c78 | 628 | my $turn_off_warnings = ""; |
d6609144 | 629 | my $default_on; |
63374c78 | 630 | if ($ref == \@warning_tests) { |
d6609144 | 631 | $warning_type = 'regexp, digit'; |
63374c78 | 632 | $turn_off_warnings = "no warnings 'experimental::regex_sets';"; |
d6609144 | 633 | $default_on = $strict; |
af01601c | 634 | } |
d6609144 KW |
635 | elsif ($ref == \@deprecated) { |
636 | $warning_type = 'regexp, deprecated'; | |
637 | $default_on = 1; | |
638 | } | |
639 | else { | |
640 | $warning_type = 'experimental::regex_sets'; | |
641 | $default_on = 1; | |
642 | } | |
643 | for (my $i = 0; $i < @$ref; $i += 2) { | |
644 | my $regex = $ref->[$i]; | |
645 | my @expect = fixup_expect($ref->[$i+1]); | |
63374c78 KW |
646 | |
647 | # A length-1 array with an empty warning means no warning gets | |
648 | # generated at all. | |
649 | undef @expect if @expect == 1 && $expect[0] eq ""; | |
650 | ||
d6609144 KW |
651 | { |
652 | $_ = "x"; | |
653 | eval "$strict no warnings; $regex"; | |
af01601c | 654 | } |
d6609144 KW |
655 | if (is($@, "", "$strict $regex did not die")) { |
656 | my @got = capture_warnings(sub { | |
657 | $_ = "x"; | |
63374c78 | 658 | eval "$strict $turn_off_warnings $regex" }); |
d6609144 KW |
659 | my $count = @expect; |
660 | if (! is(scalar @got, scalar @expect, | |
661 | "... and gave expected number ($count) of warnings")) | |
662 | { | |
663 | if (@got < @expect) { | |
664 | $count = @got; | |
665 | note "Expected warnings not gotten:\n\t" . join "\n\t", | |
666 | @expect[$count .. $#expect]; | |
667 | } | |
668 | else { | |
669 | note "Unexpected warnings gotten:\n\t" . join("\n\t", | |
670 | @got[$count .. $#got]); | |
671 | } | |
b0b90d25 | 672 | } |
d6609144 KW |
673 | foreach my $i (0 .. $count - 1) { |
674 | if (! like($got[$i], qr/\Q$expect[$i]/, | |
675 | "... and gave expected warning")) | |
676 | { | |
677 | chomp($got[$i]); | |
678 | chomp($expect[$i]); | |
679 | diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'"); | |
67cdf558 KW |
680 | } |
681 | else { | |
d6609144 KW |
682 | ok (0 == capture_warnings(sub { |
683 | $_ = "x"; | |
684 | eval "$strict no warnings '$warning_type'; $regex;" } | |
685 | ), | |
686 | "... and turning off '$warning_type' warnings suppressed it"); | |
687 | ||
688 | # Test that whether the warning is on by default is | |
689 | # correct. This test relies on the fact that we | |
690 | # are outside the scope of any ‘use warnings’. | |
691 | local $^W; | |
692 | my @warns = capture_warnings(sub { $_ = "x"; | |
693 | eval "$strict $regex" }); | |
63374c78 KW |
694 | # Warning should be on as well if is testing |
695 | # '(?[...])' which turns on strict | |
696 | if ($default_on || grep { $_ =~ /\Q(?[/ } @expect ) { | |
d6609144 KW |
697 | ok @warns > 0, "... and the warning is on by default"; |
698 | } | |
699 | else { | |
700 | ok @warns == 0, "... and the warning is off by default"; | |
701 | } | |
67cdf558 | 702 | } |
af01601c KW |
703 | } |
704 | } | |
b42857f3 | 705 | } |
6fe2934b KW |
706 | } |
707 | } | |
b45f050a | 708 | |
cb79f740 | 709 | done_testing(); |