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