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