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