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