Commit | Line | Data |
---|---|---|
b45f050a JF |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
cc7e6304 | 5 | @INC = qw '../lib ../ext/re'; |
cb79f740 | 6 | require './test.pl'; |
2b08d1e2 | 7 | skip_all_without_unicode_tables(); |
cb79f740 | 8 | eval 'require Config'; # assume defaults if this fails |
b45f050a JF |
9 | } |
10 | ||
cb79f740 | 11 | use strict; |
c1d900c3 | 12 | use open qw(:utf8 :std); |
b45f050a JF |
13 | |
14 | ## | |
15 | ## If the markers used are changed (search for "MARKER1" in regcomp.c), | |
cb79f740 | 16 | ## update only these two regexs, and leave the {#} in the @death/@warning |
b45f050a JF |
17 | ## arrays below. The {#} is a meta-marker -- it marks where the marker should |
18 | ## go. | |
cb79f740 | 19 | ## |
af01601c KW |
20 | ## Returns empty string if that is what is expected. Otherwise, handles |
21 | ## either a scalar, turning it into a single element array; or a ref to an | |
22 | ## array, adjusting each element. If called in array context, returns an | |
23 | ## array, otherwise the join of all elements | |
24 | ||
cb79f740 | 25 | sub fixup_expect { |
af01601c KW |
26 | my $expect_ref = shift; |
27 | return if $expect_ref eq ""; | |
28 | ||
29 | my @expect; | |
30 | if (ref $expect_ref) { | |
31 | @expect = @$expect_ref; | |
32 | } | |
33 | else { | |
34 | @expect = $expect_ref; | |
35 | } | |
36 | ||
37 | foreach my $element (@expect) { | |
6d24e9d4 | 38 | $element =~ s/{\#}/in regex; marked by <-- HERE in/; |
af01601c KW |
39 | $element =~ s/{\#}/ <-- HERE /; |
40 | $element .= " at "; | |
41 | } | |
42 | return wantarray ? @expect : join "", @expect; | |
cb79f740 | 43 | } |
b45f050a | 44 | |
c1d900c3 BF |
45 | ## Because we don't "use utf8" in this file, we need to do some extra legwork |
46 | ## for the utf8 tests: Append 'use utf8' to the pattern, and mark the strings | |
47 | ## to check against as UTF-8 | |
4cabb89a BF |
48 | ## |
49 | ## This also creates a second variant of the tests to check if the | |
50 | ## latin1 error messages are working correctly. | |
51 | my $l1 = "\x{ef}"; | |
52 | my $utf8 = "\x{30cd}"; | |
53 | utf8::encode($utf8); | |
54 | ||
c1d900c3 BF |
55 | sub mark_as_utf8 { |
56 | my @ret; | |
57 | while ( my ($pat, $msg) = splice(@_, 0, 2) ) { | |
4cabb89a BF |
58 | my $l1_pat = $pat =~ s/$utf8/$l1/gr; |
59 | my $l1_msg; | |
c1d900c3 BF |
60 | $pat = "use utf8; $pat"; |
61 | ||
62 | if (ref $msg) { | |
4cabb89a BF |
63 | $l1_msg = [ map { s/$utf8/$l1/gr } @$msg ]; |
64 | @$msg = map { my $c = $_; utf8::decode($c); $c } @$msg; | |
c1d900c3 BF |
65 | } |
66 | else { | |
4cabb89a | 67 | $l1_msg = $msg =~ s/$utf8/$l1/gr; |
c1d900c3 BF |
68 | utf8::decode($msg); |
69 | } | |
70 | push @ret, $pat => $msg; | |
4cabb89a | 71 | push @ret, $l1_pat => $l1_msg unless $l1_pat =~ /#no latin1/; |
c1d900c3 BF |
72 | } |
73 | return @ret; | |
74 | } | |
75 | ||
cb79f740 NC |
76 | my $inf_m1 = ($Config::Config{reg_infty} || 32767) - 1; |
77 | my $inf_p1 = $inf_m1 + 2; | |
b45f050a JF |
78 | |
79 | ## | |
80 | ## Key-value pairs of code/error of code that should have fatal errors. | |
81 | ## | |
82 | my @death = | |
83 | ( | |
6d24e9d4 | 84 | '/[[=foo=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=foo=]{#}]/', |
b45f050a | 85 | |
58e23c8d | 86 | '/(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/(?<= .*)/', |
b45f050a | 87 | |
58e23c8d | 88 | '/(?<= x{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= x{1000})/', |
b45f050a | 89 | |
6d24e9d4 | 90 | '/(?@)/' => 'Sequence (?@...) not implemented {#} m/(?@{#})/', |
b45f050a | 91 | |
9da1dd8f | 92 | '/(?{ 1/' => 'Missing right curly or square bracket', |
b45f050a | 93 | |
6d24e9d4 | 94 | '/(?(1x))/' => 'Switch condition not recognized {#} m/(?(1x{#}))/', |
311cc1ad | 95 | '/(?(1x(?#)))/'=> 'Switch condition not recognized {#} m/(?(1x{#}(?#)))/', |
b45f050a | 96 | |
6d24e9d4 | 97 | '/(?(1)x|y|z)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)x|y|{#}z)/', |
b45f050a | 98 | |
c1d900c3 | 99 | '/(?(x)y|x)/' => 'Unknown switch condition (?(...)) {#} m/(?(x{#})y|x)/', |
10380cb3 FC |
100 | '/(?(??{}))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}?{}))/', |
101 | '/(?(?[]))/' => 'Unknown switch condition (?(...)) {#} m/(?(?{#}[]))/', | |
b45f050a | 102 | |
6d24e9d4 | 103 | '/(?/' => 'Sequence (? incomplete {#} m/(?{#}/', |
b45f050a | 104 | |
6d24e9d4 KW |
105 | '/(?;x/' => 'Sequence (?;...) not recognized {#} m/(?;{#}x/', |
106 | '/(?<;x/' => 'Group name must start with a non-digit word character {#} m/(?<;{#}x/', | |
107 | '/(?\ix/' => 'Sequence (?\...) not recognized {#} m/(?\{#}ix/', | |
108 | '/(?\mx/' => 'Sequence (?\...) not recognized {#} m/(?\{#}mx/', | |
109 | '/(?\:x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}:x/', | |
110 | '/(?\=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}=x/', | |
111 | '/(?\!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}!x/', | |
112 | '/(?\<=x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<=x/', | |
113 | '/(?\<!x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}<!x/', | |
114 | '/(?\>x/' => 'Sequence (?\...) not recognized {#} m/(?\{#}>x/', | |
115 | '/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
116 | '/(?^-i)foo/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i)foo/', | |
117 | '/(?^d:foo)/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#}:foo)/', | |
118 | '/(?^d)foo/' => 'Sequence (?^d...) not recognized {#} m/(?^d{#})foo/', | |
119 | '/(?^lu:foo)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#}:foo)/', | |
120 | '/(?^lu)foo/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/(?^lu{#})foo/', | |
121 | '/(?da:foo)/' => 'Regexp modifiers "d" and "a" are mutually exclusive {#} m/(?da{#}:foo)/', | |
122 | '/(?lil:foo)/' => 'Regexp modifier "l" may not appear twice {#} m/(?lil{#}:foo)/', | |
123 | '/(?aaia:foo)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/(?aaia{#}:foo)/', | |
124 | '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/', | |
32d02813 KW |
125 | '/a\b{cde/' => 'Use "\b\{" instead of "\b{" {#} m/a\{#}b{cde/', |
126 | '/a\B{cde/' => 'Use "\B\{" instead of "\B{" {#} m/a\{#}B{cde/', | |
cc74c5bd | 127 | |
6d24e9d4 | 128 | '/((x)/' => 'Unmatched ( {#} m/({#}(x)/', |
b45f050a | 129 | |
6d24e9d4 | 130 | "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/", |
b45f050a | 131 | |
b45f050a | 132 | |
6d24e9d4 | 133 | '/x**/' => 'Nested quantifiers {#} m/x**{#}/', |
b45f050a | 134 | |
6d24e9d4 | 135 | '/x[/' => 'Unmatched [ {#} m/x[{#}/', |
b45f050a | 136 | |
6d24e9d4 | 137 | '/*/', => 'Quantifier follows nothing {#} m/*{#}/', |
b45f050a | 138 | |
6d24e9d4 | 139 | '/\p{x/' => 'Missing right brace on \p{} {#} m/\p{{#}x/', |
b45f050a | 140 | |
6d24e9d4 | 141 | '/[\p{x]/' => 'Missing right brace on \p{} {#} m/[\p{{#}x]/', |
b45f050a | 142 | |
6d24e9d4 | 143 | '/(x)\2/' => 'Reference to nonexistent group {#} m/(x)\2{#}/', |
b45f050a | 144 | |
779fedd7 | 145 | '/\g/' => 'Unterminated \g... pattern {#} m/\g{#}/', |
76cccc4d KW |
146 | '/\g{1/' => 'Unterminated \g{...} pattern {#} m/\g{1{#}/', |
147 | ||
40809656 | 148 | 'my $m = "\\\"; $m =~ $m', => 'Trailing \ in regex m/\/', |
b45f050a | 149 | |
6d24e9d4 KW |
150 | '/\x{1/' => 'Missing right brace on \x{} {#} m/\x{1{#}/', |
151 | '/\x{X/' => 'Missing right brace on \x{} {#} m/\x{{#}X/', | |
152 | ||
153 | '/[\x{X]/' => 'Missing right brace on \x{} {#} m/[\x{{#}X]/', | |
154 | '/[\x{A]/' => 'Missing right brace on \x{} {#} m/[\x{A{#}]/', | |
155 | ||
156 | '/\o{1/' => 'Missing right brace on \o{ {#} m/\o{1{#}/', | |
157 | '/\o{X/' => 'Missing right brace on \o{ {#} m/\o{{#}X/', | |
158 | ||
159 | '/[\o{X]/' => 'Missing right brace on \o{ {#} m/[\o{{#}X]/', | |
160 | '/[\o{7]/' => 'Missing right brace on \o{ {#} m/[\o{7{#}]/', | |
161 | ||
162 | '/[[:barf:]]/' => 'POSIX class [:barf:] unknown {#} m/[[:barf:]{#}]/', | |
163 | ||
164 | '/[[=barf=]]/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/[[=barf=]{#}]/', | |
165 | ||
166 | '/[[.barf.]]/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/[[.barf.]{#}]/', | |
167 | ||
168 | '/[z-a]/' => 'Invalid [] range "z-a" {#} m/[z-a{#}]/', | |
169 | ||
170 | '/\p/' => 'Empty \p{} {#} m/\p{#}/', | |
171 | ||
172 | '/\P{}/' => 'Empty \P{} {#} m/\P{{#}}/', | |
173 | '/(?[[[:word]]])/' => "Unmatched ':' in POSIX class {#} m/(?[[[:word{#}]]])/", | |
174 | '/(?[[:word]])/' => "Unmatched ':' in POSIX class {#} m/(?[[:word{#}]])/", | |
175 | '/(?[[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[[:digit:{#} ])/", | |
176 | '/(?[[:digit: ])/' => "Unmatched '[' in POSIX class {#} m/(?[[:digit:{#} ])/", | |
177 | '/(?[[[::]]])/' => "POSIX class [::] unknown {#} m/(?[[[::]{#}]])/", | |
178 | '/(?[[[:w:]]])/' => "POSIX class [:w:] unknown {#} m/(?[[[:w:]{#}]])/", | |
179 | '/(?[[:w:]])/' => "POSIX class [:w:] unknown {#} m/(?[[:w:]{#}])/", | |
180 | '/(?[a])/' => 'Unexpected character {#} m/(?[a{#}])/', | |
181 | '/(?[\t])/l' => '(?[...]) not valid in locale {#} m/(?[{#}\t])/', | |
182 | '/(?[ + \t ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ +{#} \t ])/', | |
183 | '/(?[ \cK - ( + \t ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/(?[ \cK - ( +{#} \t ) ])/', | |
184 | '/(?[ \cK ( \t ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/(?[ \cK ({#} \t ) ])/', | |
185 | '/(?[ \cK \t ])/' => 'Operand with no preceding operator {#} m/(?[ \cK \t{#} ])/', | |
186 | '/(?[ \0004 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \0004 {#}])/', | |
187 | '/(?[ \05 ])/' => 'Need exactly 3 octal digits {#} m/(?[ \05 {#}])/', | |
188 | '/(?[ \o{1038} ])/' => 'Non-octal character {#} m/(?[ \o{1038{#}} ])/', | |
189 | '/(?[ \o{} ])/' => 'Number with no digits {#} m/(?[ \o{}{#} ])/', | |
190 | '/(?[ \x{defg} ])/' => 'Non-hex character {#} m/(?[ \x{defg{#}} ])/', | |
191 | '/(?[ \xabcdef ])/' => 'Use \\x{...} for more than two hex characters {#} m/(?[ \xabc{#}def ])/', | |
192 | '/(?[ \x{} ])/' => 'Number with no digits {#} m/(?[ \x{}{#} ])/', | |
193 | '/(?[ \cK + ) ])/' => 'Unexpected \')\' {#} m/(?[ \cK + ){#} ])/', | |
194 | '/(?[ \cK + ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ \cK + {#}])/', | |
195 | '/(?[ \p{foo} ])/' => 'Property \'foo\' is unknown {#} m/(?[ \p{foo}{#} ])/', | |
196 | '/(?[ \p{ foo = bar } ])/' => 'Property \'foo = bar\' is unknown {#} m/(?[ \p{ foo = bar }{#} ])/', | |
197 | '/(?[ \8 ])/' => 'Unrecognized escape \8 in character class {#} m/(?[ \8{#} ])/', | |
3f4fde43 KW |
198 | '/(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ]/', |
199 | '/(?[ [ \t ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ \t ]/', | |
200 | '/(?[ \t ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ \t ] ]/', | |
201 | '/(?[ [ ] ]/' => 'Syntax error in (?[...]) in regex m/(?[ [ ] ]/', | |
202 | '/(?[ \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 |
203 | '/(?[ ])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[ {#}])/', |
204 | 'm/(?[[a-\d]])/' => 'False [] range "a-\d" {#} m/(?[[a-\d{#}]])/', | |
205 | 'm/(?[[\w-x]])/' => 'False [] range "\w-" {#} m/(?[[\w-{#}x]])/', | |
206 | 'm/(?[[a-\pM]])/' => 'False [] range "a-\pM" {#} m/(?[[a-\pM{#}]])/', | |
207 | 'm/(?[[\pM-x]])/' => 'False [] range "\pM-" {#} m/(?[[\pM-{#}x]])/', | |
208 | 'm/(?[[\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}]])/' => '\N{} in character class restricted to one character {#} m/(?[[\N{U+100.300{#}}]])/', | |
b5864679 KW |
209 | 'm/(?[ \p{Digit} & (?(?[ \p{Thai} | \p{Lao} ]))])/' => 'Sequence (?(...) not recognized {#} m/(?[ \p{Digit} & (?({#}?[ \p{Thai} | \p{Lao} ]))])/', |
210 | 'm/(?[ \p{Digit} & (?:(?[ \p{Thai} | \p{Lao} ]))])/' => 'Expecting \'(?flags:(?[...\' {#} m/(?[ \p{Digit} & (?{#}:(?[ \p{Thai} | \p{Lao} ]))])/', | |
6d24e9d4 KW |
211 | 'm/\o{/' => 'Missing right brace on \o{ {#} m/\o{{#}/', |
212 | 'm/\o/' => 'Missing braces on \o{} {#} m/\o{#}/', | |
213 | 'm/\o{}/' => 'Number with no digits {#} m/\o{}{#}/', | |
214 | 'm/[\o{]/' => 'Missing right brace on \o{ {#} m/[\o{{#}]/', | |
215 | 'm/[\o]/' => 'Missing braces on \o{} {#} m/[\o{#}]/', | |
216 | 'm/[\o{}]/' => 'Number with no digits {#} m/[\o{}{#}]/', | |
217 | 'm/(?^-i:foo)/' => 'Sequence (?^-...) not recognized {#} m/(?^-{#}i:foo)/', | |
f1e1b256 YO |
218 | 'm/\87/' => 'Reference to nonexistent group {#} m/\87{#}/', |
219 | 'm/a\87/' => 'Reference to nonexistent group {#} m/a\87{#}/', | |
220 | 'm/a\97/' => 'Reference to nonexistent group {#} m/a\97{#}/', | |
07ea66ee FC |
221 | 'm/(*DOOF)/' => 'Unknown verb pattern \'DOOF\' {#} m/(*DOOF){#}/', |
222 | 'm/(?&a/' => 'Sequence (?&... not terminated {#} m/(?&a{#}/', | |
75839571 FC |
223 | 'm/(?P=/' => 'Sequence ?P=... not terminated {#} m/(?P={#}/', |
224 | "m/(?'/" => "Sequence (?'... not terminated {#} m/(?'{#}/", | |
225 | "m/(?</" => "Sequence (?<... not terminated {#} m/(?<{#}/", | |
226 | 'm/(?&/' => 'Sequence (?&... not terminated {#} m/(?&{#}/', | |
227 | 'm/(?(</' => 'Sequence (?(<... not terminated {#} m/(?(<{#}/', | |
228 | "m/(?('/" => "Sequence (?('... not terminated {#} m/(?('{#}/", | |
229 | 'm/\g{/' => 'Sequence \g{... not terminated {#} m/\g{{#}/', | |
230 | 'm/\k</' => 'Sequence \k<... not terminated {#} m/\k<{#}/', | |
9b8f4e92 | 231 | 'm/\cß/' => "Character following \"\\c\" must be printable ASCII", |
cd209d9d KW |
232 | '/((?# 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)/', |
233 | '/((?# 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 | 234 | ); |
c1d900c3 BF |
235 | |
236 | my @death_utf8 = mark_as_utf8( | |
237 | '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/', | |
238 | '/ネ(?<= .*)/' => 'Variable length lookbehind not implemented in regex m/ネ(?<= .*)/', | |
239 | ||
240 | '/(?<= ネ{1000})/' => 'Lookbehind longer than 255 not implemented in regex m/(?<= ネ{1000})/', | |
241 | ||
242 | '/ネ(?ネ)ネ/' => 'Sequence (?ネ...) not recognized {#} m/ネ(?ネ{#})ネ/', | |
243 | ||
476afc4b | 244 | '/ネ(?(1ネ))ネ/' => 'Switch condition not recognized {#} m/ネ(?(1ネ{#}))ネ/', |
c1d900c3 BF |
245 | |
246 | '/(?(1)ネ|y|ヌ)/' => 'Switch (?(condition)... contains too many branches {#} m/(?(1)ネ|y|{#}ヌ)/', | |
247 | ||
248 | '/(?(ネ)y|ネ)/' => 'Unknown switch condition (?(...)) {#} m/(?(ネ{#})y|ネ)/', | |
249 | ||
250 | '/ネ(?/' => 'Sequence (? incomplete {#} m/ネ(?{#}/', | |
251 | ||
252 | '/ネ(?;ネ/' => 'Sequence (?;...) not recognized {#} m/ネ(?;{#}ネ/', | |
253 | '/ネ(?<;ネ/' => 'Group name must start with a non-digit word character {#} m/ネ(?<;{#}ネ/', | |
254 | '/ネ(?\ixネ/' => 'Sequence (?\...) not recognized {#} m/ネ(?\{#}ixネ/', | |
255 | '/ネ(?^lu:ネ)/' => 'Regexp modifiers "l" and "u" are mutually exclusive {#} m/ネ(?^lu{#}:ネ)/', | |
256 | '/ネ(?lil:ネ)/' => 'Regexp modifier "l" may not appear twice {#} m/ネ(?lil{#}:ネ)/', | |
257 | '/ネ(?aaia:ネ)/' => 'Regexp modifier "a" may appear a maximum of twice {#} m/ネ(?aaia{#}:ネ)/', | |
258 | '/ネ(?i-l:ネ)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/ネ(?i-l{#}:ネ)/', | |
259 | ||
260 | '/ネ((ネ)/' => 'Unmatched ( {#} m/ネ({#}(ネ)/', | |
261 | ||
262 | "/ネ{$inf_p1}ネ/" => "Quantifier in {,} bigger than $inf_m1 {#} m/ネ{{#}$inf_p1}ネ/", | |
263 | ||
264 | ||
265 | '/ネ**ネ/' => 'Nested quantifiers {#} m/ネ**{#}ネ/', | |
266 | ||
267 | '/ネ[ネ/' => 'Unmatched [ {#} m/ネ[{#}ネ/', | |
268 | ||
269 | '/*ネ/', => 'Quantifier follows nothing {#} m/*{#}ネ/', | |
270 | ||
271 | '/ネ\p{ネ/' => 'Missing right brace on \p{} {#} m/ネ\p{{#}ネ/', | |
272 | ||
273 | '/(ネ)\2ネ/' => 'Reference to nonexistent group {#} m/(ネ)\2{#}ネ/', | |
274 | ||
4cabb89a | 275 | '/\g{ネ/; #no latin1' => 'Sequence \g{... not terminated {#} m/\g{ネ{#}/', |
c1d900c3 BF |
276 | |
277 | 'my $m = "ネ\\\"; $m =~ $m', => 'Trailing \ in regex m/ネ\/', | |
278 | ||
279 | '/\x{ネ/' => 'Missing right brace on \x{} {#} m/\x{{#}ネ/', | |
280 | '/ネ[\x{ネ]ネ/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]ネ/', | |
281 | '/ネ[\x{ネ]/' => 'Missing right brace on \x{} {#} m/ネ[\x{{#}ネ]/', | |
282 | ||
283 | '/ネ\o{ネ/' => 'Missing right brace on \o{ {#} m/ネ\o{{#}ネ/', | |
284 | '/ネ[[:ネ:]]ネ/' => 'POSIX class [:ネ:] unknown {#} m/ネ[[:ネ:]{#}]ネ/', | |
285 | ||
286 | '/ネ[[=ネ=]]ネ/' => 'POSIX syntax [= =] is reserved for future extensions {#} m/ネ[[=ネ=]{#}]ネ/', | |
287 | ||
288 | '/ネ[[.ネ.]]ネ/' => 'POSIX syntax [. .] is reserved for future extensions {#} m/ネ[[.ネ.]{#}]ネ/', | |
289 | ||
290 | '/[ネ-a]ネ/' => 'Invalid [] range "ネ-a" {#} m/[ネ-a{#}]ネ/', | |
291 | ||
292 | '/ネ\p{}ネ/' => 'Empty \p{} {#} m/ネ\p{{#}}ネ/', | |
293 | ||
294 | '/ネ(?[[[:ネ]]])ネ/' => "Unmatched ':' in POSIX class {#} m/ネ(?[[[:ネ{#}]]])ネ/", | |
295 | '/ネ(?[[[:ネ: ])ネ/' => "Unmatched '[' in POSIX class {#} m/ネ(?[[[:ネ:{#} ])ネ/", | |
296 | '/ネ(?[[[::]]])ネ/' => "POSIX class [::] unknown {#} m/ネ(?[[[::]{#}]])ネ/", | |
297 | '/ネ(?[[[:ネ:]]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[[:ネ:]{#}]])ネ/", | |
298 | '/ネ(?[[:ネ:]])ネ/' => "POSIX class [:ネ:] unknown {#} m/ネ(?[[:ネ:]{#}])ネ/", | |
299 | '/ネ(?[ネ])ネ/' => 'Unexpected character {#} m/ネ(?[ネ{#}])ネ/', | |
300 | '/ネ(?[ネ])/l' => '(?[...]) not valid in locale {#} m/ネ(?[{#}ネ])/', | |
301 | '/ネ(?[ + [ネ] ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ +{#} [ネ] ])/', | |
302 | '/ネ(?[ \cK - ( + [ネ] ) ])/' => 'Unexpected binary operator \'+\' with no preceding operand {#} m/ネ(?[ \cK - ( +{#} [ネ] ) ])/', | |
303 | '/ネ(?[ \cK ( [ネ] ) ])/' => 'Unexpected \'(\' with no preceding operator {#} m/ネ(?[ \cK ({#} [ネ] ) ])/', | |
304 | '/ネ(?[ \cK [ネ] ])ネ/' => 'Operand with no preceding operator {#} m/ネ(?[ \cK [ネ{#}] ])ネ/', | |
305 | '/ネ(?[ \0004 ])ネ/' => 'Need exactly 3 octal digits {#} m/ネ(?[ \0004 {#}])ネ/', | |
306 | '/(?[ \o{ネ} ])ネ/' => 'Non-octal character {#} m/(?[ \o{ネ{#}} ])ネ/', | |
307 | '/ネ(?[ \o{} ])ネ/' => 'Number with no digits {#} m/ネ(?[ \o{}{#} ])ネ/', | |
308 | '/(?[ \x{ネ} ])ネ/' => 'Non-hex character {#} m/(?[ \x{ネ{#}} ])ネ/', | |
309 | '/(?[ \p{ネ} ])/' => 'Property \'ネ\' is unknown {#} m/(?[ \p{ネ}{#} ])/', | |
310 | '/(?[ \p{ ネ = bar } ])/' => 'Property \'ネ = bar\' is unknown {#} m/(?[ \p{ ネ = bar }{#} ])/', | |
311 | '/ネ(?[ \t ]/' => 'Syntax error in (?[...]) in regex m/ネ(?[ \t ]/', | |
312 | '/(?[ \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 |
313 | 'm/(*ネ)ネ/' => q<Unknown verb pattern 'ネ' {#} m/(*ネ){#}ネ/>, |
314 | '/\cネ/' => "Character following \"\\c\" must be printable ASCII", | |
c1d900c3 BF |
315 | ); |
316 | push @death, @death_utf8; | |
317 | ||
902994e4 | 318 | # Tests involving a user-defined charnames translator are in pat_advanced.t |
b45f050a | 319 | |
af01601c KW |
320 | # In the following arrays of warnings, the value can be an array of things to |
321 | # expect. If the empty string, it means no warning should be raised. | |
322 | ||
b45f050a | 323 | ## |
6fe2934b | 324 | ## Key-value pairs of code/error of code that should have non-fatal regexp warnings. |
b45f050a | 325 | ## |
cb79f740 | 326 | my @warning = ( |
6d24e9d4 | 327 | 'm/\b*/' => '\b* matches null string many times {#} m/\b*{#}/', |
6d24e9d4 KW |
328 | 'm/[:blank:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}/', |
329 | ||
330 | "m'[\\y]'" => 'Unrecognized escape \y in character class passed through {#} m/[\y{#}]/', | |
331 | ||
332 | 'm/[a-\d]/' => 'False [] range "a-\d" {#} m/[a-\d{#}]/', | |
333 | 'm/[\w-x]/' => 'False [] range "\w-" {#} m/[\w-{#}x]/', | |
334 | 'm/[a-\pM]/' => 'False [] range "a-\pM" {#} m/[a-\pM{#}]/', | |
335 | 'm/[\pM-x]/' => 'False [] range "\pM-" {#} m/[\pM-{#}x]/', | |
3da4c246 | 336 | '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}]/', |
6d24e9d4 KW |
337 | "m'\\y'" => 'Unrecognized escape \y passed through {#} m/\y{#}/', |
338 | '/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/', | |
339 | '/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/', | |
340 | '/\018/' => '\'\018\' resolved to \'\o{1}8\' {#} m/\018{#}/', | |
341 | '/[\08]/' => '\'\08\' resolved to \'\o{0}8\' {#} m/[\08{#}]/', | |
342 | '/[\018]/' => '\'\018\' resolved to \'\o{1}8\' {#} m/[\018{#}]/', | |
6d24e9d4 KW |
343 | '/(?=a)*/' => '(?=a)* matches null string many times {#} m/(?=a)*{#}/', |
344 | 'my $x = \'\m\'; qr/a$x/' => 'Unrecognized escape \m passed through {#} m/a\m{#}/', | |
345 | '/\q/' => 'Unrecognized escape \q passed through {#} m/\q{#}/', | |
6d24e9d4 | 346 | '/(?=a){1,3}/' => 'Quantifier unexpected on zero-length expression {#} m/(?=a){1,3}{#}/', |
688e0391 | 347 | '/(a|b)(?=a){3}/' => 'Quantifier unexpected on zero-length expression {#} m/(a|b)(?=a){3}{#}/', |
63fbd1cb KW |
348 | '/\_/' => "", |
349 | '/[\_\0]/' => "", | |
350 | '/[\07]/' => "", | |
351 | '/[\006]/' => "", | |
352 | '/[\0005]/' => "", | |
6d24e9d4 KW |
353 | '/[\8\9]/' => ['Unrecognized escape \8 in character class passed through {#} m/[\8{#}\9]/', |
354 | 'Unrecognized escape \9 in character class passed through {#} m/[\8\9{#}]/', | |
63fbd1cb | 355 | ], |
6d24e9d4 KW |
356 | '/[:alpha:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:alpha:]{#}/', |
357 | '/[:zog:]/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:zog:]{#}/', | |
358 | '/[.zog.]/' => 'POSIX syntax [. .] belongs inside character classes {#} m/[.zog.]{#}/', | |
63fbd1cb | 359 | '/[a-b]/' => "", |
6d24e9d4 KW |
360 | '/[a-\d]/' => 'False [] range "a-\d" {#} m/[a-\d{#}]/', |
361 | '/[\d-b]/' => 'False [] range "\d-" {#} m/[\d-{#}b]/', | |
362 | '/[\s-\d]/' => 'False [] range "\s-" {#} m/[\s-{#}\d]/', | |
363 | '/[\d-\s]/' => 'False [] range "\d-" {#} m/[\d-{#}\s]/', | |
364 | '/[a-[:digit:]]/' => 'False [] range "a-[:digit:]" {#} m/[a-[:digit:]{#}]/', | |
365 | '/[[:digit:]-b]/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}b]/', | |
366 | '/[[:alpha:]-[:digit:]]/' => 'False [] range "[:alpha:]-" {#} m/[[:alpha:]-{#}[:digit:]]/', | |
367 | '/[[:digit:]-[:alpha:]]/' => 'False [] range "[:digit:]-" {#} m/[[:digit:]-{#}[:alpha:]]/', | |
368 | '/[a\zb]/' => 'Unrecognized escape \z in character class passed through {#} m/[a\z{#}b]/', | |
369 | '/(?c)/' => 'Useless (?c) - use /gc modifier {#} m/(?c{#})/', | |
370 | '/(?-c)/' => 'Useless (?-c) - don\'t use /gc modifier {#} m/(?-c{#})/', | |
371 | '/(?g)/' => 'Useless (?g) - use /g modifier {#} m/(?g{#})/', | |
372 | '/(?-g)/' => 'Useless (?-g) - don\'t use /g modifier {#} m/(?-g{#})/', | |
373 | '/(?o)/' => 'Useless (?o) - use /o modifier {#} m/(?o{#})/', | |
374 | '/(?-o)/' => 'Useless (?-o) - don\'t use /o modifier {#} m/(?-o{#})/', | |
375 | '/(?g-o)/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-o)/', | |
376 | 'Useless (?-o) - don\'t use /o modifier {#} m/(?g-o{#})/', | |
63fbd1cb | 377 | ], |
6d24e9d4 KW |
378 | '/(?g-c)/' => [ 'Useless (?g) - use /g modifier {#} m/(?g{#}-c)/', |
379 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?g-c{#})/', | |
63fbd1cb KW |
380 | ], |
381 | # (?c) means (?g) error won't be thrown | |
6d24e9d4 KW |
382 | '/(?o-cg)/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}-cg)/', |
383 | 'Useless (?-c) - don\'t use /gc modifier {#} m/(?o-c{#}g)/', | |
63fbd1cb | 384 | ], |
6d24e9d4 KW |
385 | '/(?ogc)/' => [ 'Useless (?o) - use /o modifier {#} m/(?o{#}gc)/', |
386 | 'Useless (?g) - use /g modifier {#} m/(?og{#}c)/', | |
387 | 'Useless (?c) - use /gc modifier {#} m/(?ogc{#})/', | |
63fbd1cb | 388 | ], |
4fa6dd16 KW |
389 | '/a{1,1}?/' => 'Useless use of greediness modifier \'?\' {#} m/a{1,1}?{#}/', |
390 | '/b{3} +/x' => 'Useless use of greediness modifier \'+\' {#} m/b{3} +{#}/', | |
6fe2934b KW |
391 | ); |
392 | ||
c1d900c3 BF |
393 | my @warnings_utf8 = mark_as_utf8( |
394 | 'm/ネ\b*ネ/' => '\b* matches null string many times {#} m/ネ\b*{#}ネ/', | |
395 | '/(?=ネ)*/' => '(?=ネ)* matches null string many times {#} m/(?=ネ)*{#}/', | |
396 | 'm/ネ[:foo:]ネ/' => 'POSIX syntax [: :] belongs inside character classes {#} m/ネ[:foo:]{#}ネ/', | |
397 | "m'ネ[\\y]ネ'" => 'Unrecognized escape \y in character class passed through {#} m/ネ[\y{#}]ネ/', | |
398 | 'm/ネ[ネ-\d]ネ/' => 'False [] range "ネ-\d" {#} m/ネ[ネ-\d{#}]ネ/', | |
399 | 'm/ネ[\w-ネ]ネ/' => 'False [] range "\w-" {#} m/ネ[\w-{#}ネ]ネ/', | |
400 | 'm/ネ[ネ-\pM]ネ/' => 'False [] range "ネ-\pM" {#} m/ネ[ネ-\pM{#}]ネ/', | |
401 | '/ネ[ネ-[:digit:]]ネ/' => 'False [] range "ネ-[:digit:]" {#} m/ネ[ネ-[:digit:]{#}]ネ/', | |
402 | '/ネ[\d-\s]ネ/' => 'False [] range "\d-" {#} m/ネ[\d-{#}\s]ネ/', | |
403 | '/ネ[a\zb]ネ/' => 'Unrecognized escape \z in character class passed through {#} m/ネ[a\z{#}b]ネ/', | |
404 | '/ネ(?c)ネ/' => 'Useless (?c) - use /gc modifier {#} m/ネ(?c{#})ネ/', | |
405 | '/utf8 ネ (?ogc) ネ/' => [ | |
406 | 'Useless (?o) - use /o modifier {#} m/utf8 ネ (?o{#}gc) ネ/', | |
407 | 'Useless (?g) - use /g modifier {#} m/utf8 ネ (?og{#}c) ネ/', | |
408 | 'Useless (?c) - use /gc modifier {#} m/utf8 ネ (?ogc{#}) ネ/', | |
409 | ], | |
410 | ||
411 | ); | |
412 | ||
413 | push @warning, @warnings_utf8; | |
414 | ||
6fe2934b | 415 | my @experimental_regex_sets = ( |
6d24e9d4 | 416 | '/(?[ \t ])/' => 'The regex_sets feature is experimental {#} m/(?[{#} \t ])/', |
c1d900c3 BF |
417 | 'use utf8; /utf8 ネ (?[ [\tネ] ])/' => do { use utf8; 'The regex_sets feature is experimental {#} m/utf8 ネ (?[{#} [\tネ] ])/' }, |
418 | '/noutf8 ネ (?[ [\tネ] ])/' => 'The regex_sets feature is experimental {#} m/noutf8 ネ (?[{#} [\tネ] ])/', | |
b45f050a JF |
419 | ); |
420 | ||
63fbd1cb | 421 | my @deprecated = ( |
412f55bb KW |
422 | '/\w{/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/\w{{#}/', |
423 | '/\q{/' => [ | |
424 | 'Unrecognized escape \q{ passed through {#} m/\q{{#}/', | |
425 | 'Unescaped left brace in regex is deprecated, passed through {#} m/\q{{#}/' | |
426 | ], | |
427 | '/:{4,a}/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/:{{#}4,a}/', | |
63fbd1cb KW |
428 | ); |
429 | ||
cb79f740 NC |
430 | while (my ($regex, $expect) = splice @death, 0, 2) { |
431 | my $expect = fixup_expect($expect); | |
3f4fde43 | 432 | no warnings 'experimental::regex_sets'; |
40809656 | 433 | # skip the utf8 test on EBCDIC since they do not die |
cb79f740 | 434 | next if $::IS_EBCDIC && $regex =~ /utf8/; |
b45f050a | 435 | |
cb79f740 NC |
436 | warning_is(sub { |
437 | $_ = "x"; | |
438 | eval $regex; | |
40e98def KW |
439 | like($@, qr/\Q$expect/, $regex); |
440 | }, undef, "... and died without any other warnings"); | |
b45f050a JF |
441 | } |
442 | ||
63fbd1cb | 443 | foreach my $ref (\@warning, \@experimental_regex_sets, \@deprecated) { |
6fe2934b KW |
444 | my $warning_type = ($ref == \@warning) |
445 | ? 'regexp' | |
63fbd1cb | 446 | : ($ref == \@deprecated) |
c2a42ab2 | 447 | ? 'regexp, deprecated' |
63fbd1cb | 448 | : 'experimental::regex_sets'; |
b42857f3 | 449 | while (my ($regex, $expect) = splice @$ref, 0, 2) { |
af01601c KW |
450 | my @expect = fixup_expect($expect); |
451 | { | |
452 | $_ = "x"; | |
453 | no warnings; | |
454 | eval $regex; | |
455 | } | |
456 | if (is($@, "", "$regex did not die")) { | |
457 | my @got = capture_warnings(sub { | |
458 | $_ = "x"; | |
459 | eval $regex }); | |
460 | my $count = @expect; | |
461 | if (! is(scalar @got, scalar @expect, "... and gave expected number ($count) of warnings")) { | |
462 | if (@got < @expect) { | |
463 | $count = @got; | |
464 | note "Expected warnings not gotten:\n\t" . join "\n\t", @expect[$count .. $#expect]; | |
465 | } | |
466 | else { | |
467 | note "Unexpected warnings gotten:\n\t" . join("\n\t", @got[$count .. $#got]); | |
468 | } | |
469 | } | |
470 | foreach my $i (0 .. $count - 1) { | |
b0b90d25 KW |
471 | if (! like($got[$i], qr/\Q$expect[$i]/, "... and gave expected warning")) { |
472 | chomp($got[$i]); | |
473 | chomp($expect[$i]); | |
474 | diag("GOT\n'$got[$i]'\nEXPECT\n'$expect[$i]'"); | |
475 | } | |
476 | else { | |
af01601c KW |
477 | ok (0 == capture_warnings(sub { |
478 | $_ = "x"; | |
6fe2934b | 479 | eval "no warnings '$warning_type'; $regex;" } |
af01601c KW |
480 | ), |
481 | "... and turning off '$warning_type' warnings suppressed it"); | |
9a5996c9 FC |
482 | # Test that whether the warning is on by default is |
483 | # correct. Experimental and deprecated warnings are; | |
484 | # others are not. This test relies on the fact that we | |
485 | # are outside the scope of any ‘use warnings’. | |
486 | local $^W; | |
487 | my $on = 'on' x ($warning_type ne 'regexp'); | |
488 | ok !!$on == | |
489 | capture_warnings(sub { $_ = "x"; eval $regex }), | |
490 | "... and the warning is " . ($on||'off') | |
491 | . " by default"; | |
af01601c KW |
492 | } |
493 | } | |
b42857f3 | 494 | } |
6fe2934b KW |
495 | } |
496 | } | |
b45f050a | 497 | |
cb79f740 | 498 | done_testing(); |