This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test that defined warns for package arrays and hashes.
[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 "foo" =~ /a\b{cde/;
61 "foo" =~ /a\B{cde/;
62 "bar" =~ /\_/;
63 no warnings 'regexp';
64 "foo" =~ /\q/;
65 "foo" =~ /\q{/;
66 "foo" =~ /a\b{cde/;
67 "foo" =~ /a\B{cde/;
68 "bar" =~ /\_/;
69 EXPECT
70 Unrecognized escape \q passed through in regex; marked by <-- HERE in m/\q <-- HERE / at - line 4.
71 Unrecognized escape \q{ passed through in regex; marked by <-- HERE in m/\q{ <-- HERE / at - line 5.
72 "\b{" is deprecated; use "\b\{" instead in regex; marked by <-- HERE in m/a\ <-- HERE b{cde/ at - line 6.
73 "\B{" is deprecated; use "\B\{" instead in regex; marked by <-- HERE in m/a\ <-- HERE B{cde/ at - line 7.
74 ########
75 # regcomp.c [S_regpposixcc S_checkposixcc]
76 #
77 use warnings 'regexp' ;
78 $_ = "" ;
79 /[:alpha:]/;
80 /[:zog:]/;
81 no warnings 'regexp' ;
82 /[:alpha:]/;
83 /[:zog:]/;
84 EXPECT
85 POSIX syntax [: :] belongs inside character classes in regex; marked by <-- HERE in m/[:alpha:] <-- HERE / at - line 5.
86 POSIX syntax [: :] belongs inside character classes in regex; marked by <-- HERE in m/[:zog:] <-- HERE / at - line 6.
87 ########
88 # regcomp.c [S_checkposixcc]
89 #
90 use warnings 'regexp' ;
91 $_ = "" ;
92 /[.zog.]/;
93 no warnings 'regexp' ;
94 /[.zog.]/;
95 EXPECT
96 POSIX syntax [. .] belongs inside character classes in regex; marked by <-- HERE in m/[.zog.] <-- HERE / at - line 5.
97 POSIX syntax [. .] is reserved for future extensions in regex; marked by <-- HERE in m/[.zog.] <-- HERE / at - line 5.
98 ########
99 # regcomp.c [S_regclass]
100 $_ = "";
101 use warnings 'regexp' ;
102 /[a-b]/;
103 /[a-\d]/;
104 /[\d-b]/;
105 /[\s-\d]/;
106 /[\d-\s]/;
107 /[a-[:digit:]]/;
108 /[[:digit:]-b]/;
109 /[[:alpha:]-[:digit:]]/;
110 /[[:digit:]-[:alpha:]]/;
111 no warnings 'regexp' ;
112 /[a-b]/;
113 /[a-\d]/;
114 /[\d-b]/;
115 /[\s-\d]/;
116 /[\d-\s]/;
117 /[a-[:digit:]]/;
118 /[[:digit:]-b]/;
119 /[[:alpha:]-[:digit:]]/;
120 /[[:digit:]-[:alpha:]]/;
121 EXPECT
122 False [] range "a-\d" in regex; marked by <-- HERE in m/[a-\d <-- HERE ]/ at - line 5.
123 False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE b]/ at - line 6.
124 False [] range "\s-" in regex; marked by <-- HERE in m/[\s- <-- HERE \d]/ at - line 7.
125 False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE \s]/ at - line 8.
126 False [] range "a-[:digit:]" in regex; marked by <-- HERE in m/[a-[:digit:] <-- HERE ]/ at - line 9.
127 False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE b]/ at - line 10.
128 False [] range "[:alpha:]-" in regex; marked by <-- HERE in m/[[:alpha:]- <-- HERE [:digit:]]/ at - line 11.
129 False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE [:alpha:]]/ at - line 12.
130 ########
131 # regcomp.c [S_regclassutf8]
132 BEGIN {
133     if (ord("\t") == 5) {
134         print "SKIPPED\n# ebcdic regular expression ranges differ.";
135         exit 0;
136     }
137 }
138 use utf8;
139 $_ = "";
140 use warnings 'regexp' ;
141 /[a-b]/;
142 /[a-\d]/;
143 /[\d-b]/;
144 /[\s-\d]/;
145 /[\d-\s]/;
146 /[a-[:digit:]]/;
147 /[[:digit:]-b]/;
148 /[[:alpha:]-[:digit:]]/;
149 /[[:digit:]-[:alpha:]]/;
150 no warnings 'regexp' ;
151 /[a-b]/;
152 /[a-\d]/;
153 /[\d-b]/;
154 /[\s-\d]/;
155 /[\d-\s]/;
156 /[a-[:digit:]]/;
157 /[[:digit:]-b]/;
158 /[[:alpha:]-[:digit:]]/;
159 /[[:digit:]-[:alpha:]]/;
160 EXPECT
161 False [] range "a-\d" in regex; marked by <-- HERE in m/[a-\d <-- HERE ]/ at - line 12.
162 False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE b]/ at - line 13.
163 False [] range "\s-" in regex; marked by <-- HERE in m/[\s- <-- HERE \d]/ at - line 14.
164 False [] range "\d-" in regex; marked by <-- HERE in m/[\d- <-- HERE \s]/ at - line 15.
165 False [] range "a-[:digit:]" in regex; marked by <-- HERE in m/[a-[:digit:] <-- HERE ]/ at - line 16.
166 False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE b]/ at - line 17.
167 False [] range "[:alpha:]-" in regex; marked by <-- HERE in m/[[:alpha:]- <-- HERE [:digit:]]/ at - line 18.
168 False [] range "[:digit:]-" in regex; marked by <-- HERE in m/[[:digit:]- <-- HERE [:alpha:]]/ at - line 19.
169 ########
170 # regcomp.c [S_regclass S_regclassutf8]
171 use warnings 'regexp' ;
172 $a =~ /[a\zb]/ ;
173 no warnings 'regexp' ;
174 $a =~ /[a\zb]/ ;
175 EXPECT
176 Unrecognized escape \z in character class passed through in regex; marked by <-- HERE in m/[a\z <-- HERE b]/ at - line 3.
177
178 ########
179 # regcomp.c [S_reg]
180 use warnings 'regexp' ;
181 $a = qr/(?c)/;
182 $a = qr/(?-c)/;
183 $a = qr/(?g)/;
184 $a = qr/(?-g)/;
185 $a = qr/(?o)/;
186 $a = qr/(?-o)/;
187 $a = qr/(?g-o)/;
188 $a = qr/(?g-c)/;
189 $a = qr/(?o-cg)/;  # (?c) means (?g) error won't be thrown
190 $a = qr/(?ogc)/;
191 no warnings 'regexp' ;
192 $a = qr/(?c)/;
193 $a = qr/(?-c)/;
194 $a = qr/(?g)/;
195 $a = qr/(?-g)/;
196 $a = qr/(?o)/;
197 $a = qr/(?-o)/;
198 $a = qr/(?g-o)/;
199 $a = qr/(?g-c)/;
200 $a = qr/(?o-cg)/;  # (?c) means (?g) error won't be thrown
201 $a = qr/(?ogc)/;
202 #EXPECT
203 EXPECT
204 Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?c <-- HERE )/ at - line 3.
205 Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?-c <-- HERE )/ at - line 4.
206 Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE )/ at - line 5.
207 Useless (?-g) - don't use /g modifier in regex; marked by <-- HERE in m/(?-g <-- HERE )/ at - line 6.
208 Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE )/ at - line 7.
209 Useless (?-o) - don't use /o modifier in regex; marked by <-- HERE in m/(?-o <-- HERE )/ at - line 8.
210 Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE -o)/ at - line 9.
211 Useless (?-o) - don't use /o modifier in regex; marked by <-- HERE in m/(?g-o <-- HERE )/ at - line 9.
212 Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g <-- HERE -c)/ at - line 10.
213 Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?g-c <-- HERE )/ at - line 10.
214 Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE -cg)/ at - line 11.
215 Useless (?-c) - don't use /gc modifier in regex; marked by <-- HERE in m/(?o-c <-- HERE g)/ at - line 11.
216 Useless (?o) - use /o modifier in regex; marked by <-- HERE in m/(?o <-- HERE gc)/ at - line 12.
217 Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?og <-- HERE c)/ at - line 12.
218 Useless (?c) - use /gc modifier in regex; marked by <-- HERE in m/(?ogc <-- HERE )/ at - line 12.
219 ########
220 # regcomp.c [S_regatom]
221 $a = qr/\o{/;
222 EXPECT
223 Missing right brace on \o{ in regex; marked by <-- HERE in m/\o{ <-- HERE / at - line 2.
224 ########
225 # regcomp.c [S_regatom]
226 $a = qr/\o/;
227 EXPECT
228 Missing braces on \o{} in regex; marked by <-- HERE in m/\o <-- HERE / at - line 2.
229 ########
230 # regcomp.c [S_regatom]
231 $a = qr/\o{}/;
232 EXPECT
233 Number with no digits in regex; marked by <-- HERE in m/\o{} <-- HERE / at - line 2.
234 ########
235 # regcomp.c [S_regclass]
236 $a = qr/[\o{]/;
237 EXPECT
238 Missing right brace on \o{ in regex; marked by <-- HERE in m/[\o{ <-- HERE ]/ at - line 2.
239 ########
240 # regcomp.c [S_regclass]
241 $a = qr/[\o]/;
242 EXPECT
243 Missing braces on \o{} in regex; marked by <-- HERE in m/[\o <-- HERE ]/ at - line 2.
244 ########
245 # regcomp.c [S_regclass]
246 $a = qr/[\o{}]/;
247 EXPECT
248 Number with no digits in regex; marked by <-- HERE in m/[\o{} <-- HERE ]/ at - line 2.
249 ########
250 # regcomp.c [S_regclass]
251 use warnings 'regexp' ;
252 $a = qr/[\8\9]/;
253 $a = qr/[\_\0]/; # Should have no warnings on this and the remainder of this test
254 $a = qr/[\07]/;
255 $a = qr/[\006]/;
256 $a = qr/[\0005]/;
257 no warnings 'regexp' ;
258 $a = qr/[\8\9]/;
259 EXPECT
260 Unrecognized escape \8 in character class passed through in regex; marked by <-- HERE in m/[\8 <-- HERE \9]/ at - line 3.
261 Unrecognized escape \9 in character class passed through in regex; marked by <-- HERE in m/[\8\9 <-- HERE ]/ at - line 3.
262 ########
263 # regcomp.c [Perl_re_compile]
264 $a = qr/(?^-i:foo)/;
265 EXPECT
266 Sequence (?^-...) not recognized in regex; marked by <-- HERE in m/(?^- <-- HERE i:foo)/ at - line 2.