This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp: Add warning if tries to use \p in locale.
[perl5.git] / t / lib / warnings / regcomp
CommitLineData
599cee73
PM
1 regcomp.c AOK
2
f9373011
PM
3 Quantifier unexpected on zero-length expression [S_study_chunk]
4
f9373011
PM
5 Useless (%s%c) - %suse /%c modifier [S_reg]
6 Useless (%sc) - %suse /gc modifier [S_reg]
7
8
9
767a6a26
PM
10 Strange *+?{} on zero-length expression [S_study_chunk]
11 /(?=a)?/
599cee73 12
767a6a26 13 %.*s matches null string many times [S_regpiece]
599cee73
PM
14 $a = "ABC123" ; $a =~ /(?=a)*/'
15
ac561586 16 /%.127s/: Unrecognized escape \\%c passed through [S_regatom]
e476b1b5 17 $x = '\m' ; /$x/
599cee73 18
cd84f5b2 19 POSIX syntax [%c %c] belongs inside character classes [S_checkposixcc]
f9373011
PM
20
21
ac561586
JH
22 Character class [:%.*s:] unknown [S_regpposixcc]
23
767a6a26
PM
24 Character class syntax [%c %c] belongs inside character classes [S_checkposixcc]
25
73b437c8 26 /%.127s/: false [] range \"%*.*s\" in regexp [S_regclass]
599cee73 27
73b437c8 28 /%.127s/: false [] range \"%*.*s\" in regexp [S_regclassutf8]
599cee73 29
1028017a
JH
30 /%.127s/: Unrecognized escape \\%c in character class passed through" [S_regclass]
31
32 /%.127s/: Unrecognized escape \\%c in character class passed through" [S_regclassutf8]
33
f9373011
PM
34 False [] range \"%*.*s\" [S_regclass]
35
599cee73 36__END__
767a6a26 37# regcomp.c [S_regpiece]
e476b1b5 38use warnings 'regexp' ;
599cee73
PM
39my $a = "ABC123" ;
40$a =~ /(?=a)*/ ;
e476b1b5 41no warnings 'regexp' ;
0453d815 42$a =~ /(?=a)*/ ;
599cee73 43EXPECT
7253e4e3 44(?=a)* matches null string many times in regex; marked by <-- HERE in m/(?=a)* <-- HERE / at - line 4.
599cee73 45########
767a6a26 46# regcomp.c [S_regatom]
e476b1b5
GS
47$x = '\m' ;
48use warnings 'regexp' ;
49$a =~ /a$x/ ;
50no warnings 'regexp' ;
51$a =~ /a$x/ ;
767a6a26 52EXPECT
7253e4e3 53Unrecognized escape \m passed through in regex; marked by <-- HERE in m/a\m <-- HERE / at - line 4.
767a6a26 54########
cc74c5bd
ST
55# regcomp.c [S_regatom]
56# The \q should warn, the \_ should NOT warn.
57use warnings 'regexp';
58"foo" =~ /\q/;
59"bar" =~ /\_/;
60no warnings 'regexp';
61"foo" =~ /\q/;
62"bar" =~ /\_/;
63EXPECT
64Unrecognized escape \q passed through in regex; marked by <-- HERE in m/\q <-- HERE / at - line 4.
65########
767a6a26 66# regcomp.c [S_regpposixcc S_checkposixcc]
7f01dc7a 67#
e476b1b5 68use warnings 'regexp' ;
599cee73 69$_ = "" ;
e8c223df 70/[:alpha:]/;
e8c223df 71/[:zog:]/;
e476b1b5 72no warnings 'regexp' ;
e8c223df 73/[:alpha:]/;
ac561586 74/[:zog:]/;
599cee73 75EXPECT
7253e4e3
RK
76POSIX syntax [: :] belongs inside character classes in regex; marked by <-- HERE in m/[:alpha:] <-- HERE / at - line 5.
77POSIX syntax [: :] belongs inside character classes in regex; marked by <-- HERE in m/[:zog:] <-- HERE / at - line 6.
3802429d
JF
78########
79# regcomp.c [S_checkposixcc]
7f01dc7a 80#
3802429d
JF
81use warnings 'regexp' ;
82$_ = "" ;
83/[.zog.]/;
84no warnings 'regexp' ;
85/[.zog.]/;
86EXPECT
7253e4e3 87POSIX syntax [. .] belongs inside character classes in regex; marked by <-- HERE in m/[.zog.] <-- HERE / at - line 5.
d0808320 88POSIX syntax [. .] is reserved for future extensions in regex; marked by <-- HERE in m/[.zog.] <-- HERE / at - line 5.
3802429d 89########
73b437c8
JH
90# regcomp.c [S_regclass]
91$_ = "";
e476b1b5 92use warnings 'regexp' ;
73b437c8
JH
93/[a-b]/;
94/[a-\d]/;
95/[\d-b]/;
96/[\s-\d]/;
97/[\d-\s]/;
98/[a-[:digit:]]/;
99/[[:digit:]-b]/;
100/[[:alpha:]-[:digit:]]/;
101/[[:digit:]-[:alpha:]]/;
e476b1b5 102no warnings 'regexp' ;
73b437c8
JH
103/[a-b]/;
104/[a-\d]/;
105/[\d-b]/;
106/[\s-\d]/;
107/[\d-\s]/;
108/[a-[:digit:]]/;
109/[[:digit:]-b]/;
110/[[:alpha:]-[:digit:]]/;
111/[[:digit:]-[:alpha:]]/;
112EXPECT
7253e4e3
RK
113False [] range "a-\d" in regex; marked by <-- HERE in m/[a-\d <-- HERE ]/ at - line 5.
114False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE b]/ at - line 6.
115False [] range "\s-" in regex; marked by <-- HERE in m/[\s- <-- HERE \d]/ at - line 7.
116False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE \s]/ at - line 8.
117False [] range "a-[:digit:]" in regex; marked by <-- HERE in m/[a-[:digit:] <-- HERE ]/ at - line 9.
118False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE b]/ at - line 10.
119False [] range "[:alpha:]-" in regex; marked by <-- HERE in m/[[:alpha:]- <-- HERE [:digit:]]/ at - line 11.
120False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE [:alpha:]]/ at - line 12.
73b437c8
JH
121########
122# regcomp.c [S_regclassutf8]
59af8754
GS
123BEGIN {
124 if (ord("\t") == 5) {
125 print "SKIPPED\n# ebcdic regular expression ranges differ.";
126 exit 0;
127 }
128}
73b437c8
JH
129use utf8;
130$_ = "";
e476b1b5 131use warnings 'regexp' ;
73b437c8
JH
132/[a-b]/;
133/[a-\d]/;
134/[\d-b]/;
135/[\s-\d]/;
136/[\d-\s]/;
137/[a-[:digit:]]/;
138/[[:digit:]-b]/;
139/[[:alpha:]-[:digit:]]/;
140/[[:digit:]-[:alpha:]]/;
e476b1b5 141no warnings 'regexp' ;
73b437c8
JH
142/[a-b]/;
143/[a-\d]/;
144/[\d-b]/;
145/[\s-\d]/;
146/[\d-\s]/;
147/[a-[:digit:]]/;
148/[[:digit:]-b]/;
149/[[:alpha:]-[:digit:]]/;
150/[[:digit:]-[:alpha:]]/;
151EXPECT
7253e4e3
RK
152False [] range "a-\d" in regex; marked by <-- HERE in m/[a-\d <-- HERE ]/ at - line 12.
153False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE b]/ at - line 13.
154False [] range "\s-" in regex; marked by <-- HERE in m/[\s- <-- HERE \d]/ at - line 14.
155False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE \s]/ at - line 15.
156False [] range "a-[:digit:]" in regex; marked by <-- HERE in m/[a-[:digit:] <-- HERE ]/ at - line 16.
157False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE b]/ at - line 17.
158False [] range "[:alpha:]-" in regex; marked by <-- HERE in m/[[:alpha:]- <-- HERE [:digit:]]/ at - line 18.
159False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE [:alpha:]]/ at - line 19.
1028017a
JH
160########
161# regcomp.c [S_regclass S_regclassutf8]
e476b1b5 162use warnings 'regexp' ;
1028017a 163$a =~ /[a\zb]/ ;
e476b1b5 164no warnings 'regexp' ;
1028017a
JH
165$a =~ /[a\zb]/ ;
166EXPECT
7253e4e3 167Unrecognized escape \z in character class passed through in regex; marked by <-- HERE in m/[a\z <-- HERE b]/ at - line 3.
b45f050a 168
f9373011 169########
f9373011
PM
170# regcomp.c [S_reg]
171use warnings 'regexp' ;
172$a = qr/(?c)/;
173$a = qr/(?-c)/;
174$a = qr/(?g)/;
175$a = qr/(?-g)/;
176$a = qr/(?o)/;
177$a = qr/(?-o)/;
178$a = qr/(?g-o)/;
179$a = qr/(?g-c)/;
180$a = qr/(?o-cg)/; # (?c) means (?g) error won't be thrown
181$a = qr/(?ogc)/;
182no warnings 'regexp' ;
183$a = qr/(?c)/;
184$a = qr/(?-c)/;
185$a = qr/(?g)/;
186$a = qr/(?-g)/;
187$a = qr/(?o)/;
188$a = qr/(?-o)/;
189$a = qr/(?g-o)/;
190$a = qr/(?g-c)/;
191$a = qr/(?o-cg)/; # (?c) means (?g) error won't be thrown
192$a = qr/(?ogc)/;
193#EXPECT
194EXPECT
195Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <-- HERE )/ at - line 3.
196Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?-c <-- HERE )/ at - line 4.
197Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE )/ at - line 5.
198Useless (?-g) - don't use /g modifier in regex; marked by <-- HERE in m/(?-g <-- HERE )/ at - line 6.
199Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE )/ at - line 7.
200Useless (?-o) - don't use /o modifier in regex; marked by <-- HERE in m/(?-o <-- HERE )/ at - line 8.
201Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE -o)/ at - line 9.
202Useless (?-o) - don't use /o modifier in regex; marked by <-- HERE in m/(?g-o <-- HERE )/ at - line 9.
203Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE -c)/ at - line 10.
204Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?g-c <-- HERE )/ at - line 10.
205Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE -cg)/ at - line 11.
206Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?o-c <-- HERE g)/ at - line 11.
207Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE gc)/ at - line 12.
208Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?og <-- HERE c)/ at - line 12.
209Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?ogc <-- HERE )/ at - line 12.
f0a2b745
KW
210########
211# regcomp.c [S_regatom]
212$a = qr/\o{/;
213EXPECT
454155d9 214Missing right brace on \o{ in regex; marked by <-- HERE in m/\o{ <-- HERE / at - line 2.
f0a2b745
KW
215########
216# regcomp.c [S_regatom]
217$a = qr/\o/;
218EXPECT
454155d9 219Missing braces on \o{} in regex; marked by <-- HERE in m/\o <-- HERE / at - line 2.
f0a2b745
KW
220########
221# regcomp.c [S_regatom]
222$a = qr/\o{}/;
223EXPECT
454155d9 224Number with no digits in regex; marked by <-- HERE in m/\o{} <-- HERE / at - line 2.
f0a2b745
KW
225########
226# regcomp.c [S_regclass]
227$a = qr/[\o{]/;
228EXPECT
454155d9 229Missing right brace on \o{ in regex; marked by <-- HERE in m/[\o{ <-- HERE ]/ at - line 2.
f0a2b745
KW
230########
231# regcomp.c [S_regclass]
232$a = qr/[\o]/;
233EXPECT
454155d9 234Missing braces on \o{} in regex; marked by <-- HERE in m/[\o <-- HERE ]/ at - line 2.
f0a2b745
KW
235########
236# regcomp.c [S_regclass]
237$a = qr/[\o{}]/;
238EXPECT
454155d9 239Number with no digits in regex; marked by <-- HERE in m/[\o{} <-- HERE ]/ at - line 2.
c99e91e9
KW
240########
241# regcomp.c [S_regclass]
242use warnings 'regexp' ;
243$a = qr/[\8\9]/;
244$a = qr/[\_\0]/; # Should have no warnings on this and the remainder of this test
245$a = qr/[\07]/;
246$a = qr/[\006]/;
247$a = qr/[\0005]/;
248no warnings 'regexp' ;
249$a = qr/[\8\9]/;
250EXPECT
251Unrecognized escape \8 in character class passed through in regex; marked by <-- HERE in m/[\8 <-- HERE \9]/ at - line 3.
252Unrecognized escape \9 in character class passed through in regex; marked by <-- HERE in m/[\8\9 <-- HERE ]/ at - line 3.
fb85c044
KW
253########
254# regcomp.c [Perl_re_compile]
255$a = qr/(?^-i:foo)/;
256EXPECT
257Sequence (?^-...) not recognized in regex; marked by <-- HERE in m/(?^- <-- HERE i:foo)/ at - line 2.
fb2e24cd
KW
258########
259# regcomp.c [S_regclass]
260use warnings 'regexp' ;
261$a = qr/(?^l:\pL)/;
262$a = qr/(?^l:\PL)/;
263no warnings 'regexp' ;
264$a = qr/(?^l:\pL)/;
265$a = qr/(?^l:\PL)/;
266EXPECT
267\p uses Unicode rules, not locale rules in regex; marked by <-- HERE in m/(?^l:\p <-- HERE L)/ at - line 3.
268\P uses Unicode rules, not locale rules in regex; marked by <-- HERE in m/(?^l:\P <-- HERE L)/ at - line 4.