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