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