This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
NI-S' cunning idea of how to de-UTF8 the "\C-broken" submatches.
[perl5.git] / t / op / pat.t
CommitLineData
8d063cd8 1#!./perl
8d37f932
DD
2#
3# This is a home for regular expression tests that don't fit into
4# the format supported by op/regexp.t. If you want to add a test
5# that does fit that format, add it to op/re_tests, not here.
8d063cd8 6
8269fa76 7print "1..581\n";
8d37f932 8
e4d48cc9
GS
9BEGIN {
10 chdir 't' if -d 't';
20822f61 11 @INC = '../lib';
e4d48cc9 12}
8d37f932 13eval 'use Config'; # Defaults assumed if this fails
8d063cd8 14
9c63abab
GS
15# XXX known to leak scalars
16$ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
eec2d3df 17
8d063cd8
LW
18$x = "abc\ndef\n";
19
20if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
21if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
22
23$* = 1;
24if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
25$* = 0;
26
27$_ = '123';
28if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
29
30if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
31if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
32
33if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
34if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
35
36if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
37if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
38
39if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
40if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
41
42$_ = 'aaabbbccc';
43if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
44 print "ok 13\n";
45} else {
46 print "not ok 13\n";
47}
48if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
49 print "ok 14\n";
50} else {
51 print "not ok 14\n";
52}
53
54if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
55
56$_ = 'aaabccc';
57if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
58if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
59
60$_ = 'aaaccc';
61if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
62if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
63
64$_ = 'abcdef';
65if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
66if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
67
68if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
378cc40b
LW
69
70if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
71
72$* = 1; # test 3 only tested the optimized version--this one is for real
73if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
74$* = 0;
75
f8b27a63
JH
76#$XXX{123} = 123;
77#$XXX{234} = 234;
78#$XXX{345} = 345;
79#
80#@XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
81#while ($_ = shift(@XXX)) {
82# ?(.*)? && (print $1,"\n");
922205fa 83# /not/ && reset;
f8b27a63
JH
84# /not ok 26/ && reset 'X';
85#}
86#
87#while (($key,$val) = each(%XXX)) {
88# print "not ok 27\n";
89# exit;
90#}
91#
92#print "ok 27\n";
922205fa 93for (25..27) { print "ok $_\n" }
378cc40b 94
378cc40b
LW
95'cde' =~ /[^ab]*/;
96'xyz' =~ //;
97if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
98
99$foo = '[^ab]*';
100'cde' =~ /$foo/;
101'xyz' =~ //;
102if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
103
104$foo = '[^ab]*';
105'cde' =~ /$foo/;
106'xyz' =~ /$null/;
107if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
a687059c
LW
108
109$_ = 'abcdefghi';
110/def/; # optimized up to cmd
111if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
112
113/cde/ + 0; # optimized only to spat
114if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
115
116/[d][e][f]/; # not optimized
117if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
118
119$_ = 'now is the {time for all} good men to come to.';
120/ {([^}]*)}/;
121if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
122
123$_ = 'xxx {3,4} yyy zzz';
124print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
125print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
126print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
127print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
128print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
129print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
130print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
131print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
132print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
352d5a3a
LW
133
134$_ = "now is the time for all good men to come to.";
135@words = /(\w+)/g;
136print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
137 ? "ok 44\n"
138 : "not ok 44\n";
139
140@words = ();
141while (/\w+/g) {
142 push(@words, $&);
143}
144print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
145 ? "ok 45\n"
146 : "not ok 45\n";
147
148@words = ();
71be2cbc 149pos = 0;
352d5a3a
LW
150while (/to/g) {
151 push(@words, $&);
152}
153print join(':',@words) eq "to:to"
154 ? "ok 46\n"
71be2cbc 155 : "not ok 46 `@words'\n";
352d5a3a 156
71be2cbc 157pos $_ = 0;
352d5a3a
LW
158@words = /to/g;
159print join(':',@words) eq "to:to"
160 ? "ok 47\n"
71be2cbc 161 : "not ok 47 `@words'\n";
352d5a3a
LW
162
163$_ = "abcdefghi";
164
165$pat1 = 'def';
166$pat2 = '^def';
167$pat3 = '.def.';
168$pat4 = 'abc';
169$pat5 = '^abc';
170$pat6 = 'abc$';
171$pat7 = 'ghi';
172$pat8 = '\w*ghi';
173$pat9 = 'ghi$';
174
175$t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
176
177for $iter (1..5) {
178 $t1++ if /$pat1/o;
179 $t2++ if /$pat2/o;
180 $t3++ if /$pat3/o;
181 $t4++ if /$pat4/o;
182 $t5++ if /$pat5/o;
183 $t6++ if /$pat6/o;
184 $t7++ if /$pat7/o;
185 $t8++ if /$pat8/o;
186 $t9++ if /$pat9/o;
187}
188
189$x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
190print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
1462b684
LW
191
192$xyz = 'xyz';
193print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
194
195# perl 4.009 says "unmatched ()"
196eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
197print $@ eq "" ? "ok 50\n" : "not ok 50\n";
198print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
a0d0e21e
LW
199
200
201$_="abcfooabcbar";
202$x=/abc/g;
203print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
204$x=/abc/g;
205print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
206$x=/abc/g;
207print $x == 0 ? "ok 54\n" : "not ok 54\n";
71be2cbc 208pos = 0;
a0d0e21e
LW
209$x=/ABC/gi;
210print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
211$x=/ABC/gi;
212print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
213$x=/ABC/gi;
214print $x == 0 ? "ok 57\n" : "not ok 57\n";
71be2cbc 215pos = 0;
a0d0e21e
LW
216$x=/abc/g;
217print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
218$x=/abc/g;
219print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
220$_ .= '';
221@x=/abc/g;
222print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
71be2cbc
PP
223
224$_ = "abdc";
225pos $_ = 2;
c90c0ff4 226/\Gc/gc;
71be2cbc
PP
227print "not " if (pos $_) != 2;
228print "ok 61\n";
c90c0ff4
PP
229/\Gc/g;
230print "not " if defined pos $_;
231print "ok 62\n";
c277df42
IZ
232
233$out = 1;
234'abc' =~ m'a(?{ $out = 2 })b';
235print "not " if $out != 2;
236print "ok 63\n";
237
238$out = 1;
239'abc' =~ m'a(?{ $out = 3 })c';
240print "not " if $out != 1;
241print "ok 64\n";
242
243$_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
244@out = /(?<!foo)bar./g;
245print "not " if "@out" ne 'bar2 barf';
246print "ok 65\n";
247
8d37f932
DD
248# Tests which depend on REG_INFTY
249$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
250$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
251
252# As well as failing if the pattern matches do unexpected things, the
253# next three tests will fail if you should have picked up a lower-than-
254# default value for $reg_infty from Config.pm, but have not.
255
256undef $@;
257print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
258print "ok 66\n";
259
260undef $@;
261print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
262print "ok 67\n";
263
264undef $@;
265print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
266print "ok 68\n";
267
268undef $@;
269eval "'aaa' =~ /a{1,$reg_infty}/";
9baa0206 270print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932
DD
271print "ok 69\n";
272
273eval "'aaa' =~ /a{1,$reg_infty_p}/";
274print "not "
9baa0206 275 if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932
DD
276print "ok 70\n";
277undef $@;
278
279# Poke a couple more parse failures
280
281$context = 'x' x 256;
282eval qq("${context}y" =~ /(?<=$context)y/);
9baa0206 283print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
8d37f932
DD
284print "ok 71\n";
285
b8c5462f 286# removed test
8d37f932
DD
287print "ok 72\n";
288
c277df42 289# Long Monsters
8d37f932 290$test = 73;
c277df42
IZ
291for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
292 $a = 'a' x $l;
293 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
294 print "ok $test\n";
295 $test++;
73d6d589 296
c277df42
IZ
297 print "not " if "b$a=" =~ /a$a=/;
298 print "ok $test\n";
299 $test++;
300}
301
302# 20000 nodes, each taking 3 words per string, and 1 per branch
303$long_constant_len = join '|', 12120 .. 32645;
304$long_var_len = join '|', 8120 .. 28645;
305%ans = ( 'ax13876y25677lbc' => 1,
306 'ax13876y25677mcb' => 0, # not b.
307 'ax13876y35677nbc' => 0, # Num too big
308 'ax13876y25677y21378obc' => 1,
309 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
310 'ax13876y25677y21378y21378kbc' => 1,
311 'ax13876y25677y21378y21378kcb' => 0, # Not b.
312 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
313 );
314
315for ( keys %ans ) {
73d6d589 316 print "# const-len `$_' not => $ans{$_}\nnot "
c277df42
IZ
317 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
318 print "ok $test\n";
319 $test++;
73d6d589 320 print "# var-len `$_' not => $ans{$_}\nnot "
c277df42
IZ
321 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
322 print "ok $test\n";
323 $test++;
324}
325
326$_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
327$expect = "(bla()) ((l)u((e))) (l(e)e)";
328
73d6d589 329sub matchit {
cc6b7395 330 m/
c277df42 331 (
73d6d589 332 \(
c277df42
IZ
333 (?{ $c = 1 }) # Initialize
334 (?:
335 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
336 (?!
337 ) # Fail: will unwind one iteration back
73d6d589 338 )
c277df42
IZ
339 (?:
340 [^()]+ # Match a big chunk
341 (?=
342 [()]
343 ) # Do not try to match subchunks
344 |
73d6d589 345 \(
c277df42
IZ
346 (?{ ++$c })
347 |
73d6d589 348 \)
c277df42
IZ
349 (?{ --$c })
350 )
351 )+ # This may not match with different subblocks
352 )
353 (?(?{ $c != 0 })
354 (?!
355 ) # Fail
356 ) # Otherwise the chunk 1 may succeed with $c>0
cc6b7395 357 /xg;
c277df42
IZ
358}
359
0f5d15d6 360@ans = ();
c277df42
IZ
361push @ans, $res while $res = matchit;
362
363print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
364print "ok $test\n";
365$test++;
366
367@ans = matchit;
368
369print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
370print "ok $test\n";
371$test++;
372
96776eda
GS
373print "not " unless "abc" =~ /^(??{"a"})b/;
374print "ok $test\n";
375$test++;
376
0f5d15d6 377my $matched;
14455d6c 378$matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
0f5d15d6
IZ
379
380@ans = @ans1 = ();
381push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
382
383print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
384print "ok $test\n";
385$test++;
386
387print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
388print "ok $test\n";
389$test++;
390
391@ans = m/$matched/g;
392
393print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
394print "ok $test\n";
395$test++;
396
c277df42
IZ
397@ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
398print "not " if "@ans" ne 'a/ b';
399print "ok $test\n";
400$test++;
401
cc6b7395 402$code = '{$blah = 45}';
c277df42 403$blah = 12;
2cd61cdb
IZ
404eval { /(?$code)/ };
405print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
e4d48cc9
GS
406print "ok $test\n";
407$test++;
408
2cd61cdb
IZ
409for $code ('{$blah = 45}','=xx') {
410 $blah = 12;
411 $res = eval { "xx" =~ /(?$code)/o };
412 if ($code eq '=xx') {
413 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
414 } else {
73d6d589 415 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
2cd61cdb
IZ
416 }
417 print "ok $test\n";
418 $test++;
419}
420
e4d48cc9
GS
421$code = '{$blah = 45}';
422$blah = 12;
423eval "/(?$code)/";
cc6b7395
IZ
424print "not " if $blah != 45;
425print "ok $test\n";
426$test++;
427
428$blah = 12;
429/(?{$blah = 45})/;
c277df42
IZ
430print "not " if $blah != 45;
431print "ok $test\n";
432$test++;
433
74d6a13a
MB
434$x = 'banana';
435$x =~ /.a/g;
436print "not " unless pos($x) == 2;
437print "ok $test\n";
438$test++;
439
440$x =~ /.z/gc;
441print "not " unless pos($x) == 2;
442print "ok $test\n";
443$test++;
444
445sub f {
446 my $p = $_[0];
447 return $p;
448}
449
450$x =~ /.a/g;
451print "not " unless f(pos($x)) == 4;
452print "ok $test\n";
453$test++;
4599a1de 454
ce862d02
IZ
455$x = $^R = 67;
456'foot' =~ /foo(?{$x = 12; 75})[t]/;
457print "not " unless $^R eq '75';
458print "ok $test\n";
459$test++;
460
461$x = $^R = 67;
462'foot' =~ /foo(?{$x = 12; 75})[xy]/;
463print "not " unless $^R eq '67' and $x eq '12';
464print "ok $test\n";
465$test++;
466
467$x = $^R = 67;
468'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
469print "not " unless $^R eq '79' and $x eq '12';
470print "ok $test\n";
471$test++;
472
8782bef2
GB
473print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
474print "ok $test\n";
475$test++;
476
477print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
478print "ok $test\n";
479$test++;
480
481print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
482print "ok $test\n";
483$test++;
484
485print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
486print "ok $test\n";
487$test++;
488
489print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
490print "ok $test\n";
491$test++;
492
493print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
97197631
IZ
494print "ok $test\n";
495$test++;
496
7e5428c5
IZ
497$_ = 'xabcx';
498foreach $ans ('', 'c') {
499 /(?<=(?=a)..)((?=c)|.)/g;
02db2b7b 500 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
7e5428c5
IZ
501 print "ok $test\n";
502 $test++;
503}
504
505$_ = 'a';
506foreach $ans ('', 'a', '') {
507 /^|a|$/g;
02db2b7b 508 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
7e5428c5
IZ
509 print "ok $test\n";
510 $test++;
511}
512
09f25ae4 513sub prefixify {
73d6d589
NIS
514 my($v,$a,$b,$res) = @_;
515 $v =~ s/\Q$a\E/$b/;
516 print "not " unless $res eq $v;
09f25ae4
IZ
517 print "ok $test\n";
518 $test++;
519}
520prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
521prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
522
523$_ = 'var="foo"';
524/(\")/;
525print "not " unless $1 and /$1/;
526print "ok $test\n";
527$test++;
528
73d6d589 529$a=qr/(?{++$b})/;
2cd61cdb 530$b = 7;
73d6d589
NIS
531/$a$a/;
532print "not " unless $b eq '9';
2cd61cdb
IZ
533print "ok $test\n";
534$test++;
535
73d6d589
NIS
536$c="$a";
537/$a$a/;
538print "not " unless $b eq '11';
2cd61cdb
IZ
539print "ok $test\n";
540$test++;
541
542{
73d6d589
NIS
543 use re "eval";
544 /$a$c$a/;
545 print "not " unless $b eq '14';
2cd61cdb
IZ
546 print "ok $test\n";
547 $test++;
548
160cb429
JH
549 local $lex_a = 2;
550 my $lex_a = 43;
551 my $lex_b = 17;
552 my $lex_c = 27;
553 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
554 print "not " unless $lex_res eq '1';
555 print "ok $test\n";
556 $test++;
557 print "not " unless $lex_a eq '44';
558 print "ok $test\n";
559 $test++;
560 print "not " unless $lex_c eq '43';
561 print "ok $test\n";
562 $test++;
563
564
73d6d589 565 no re "eval";
2cd61cdb 566 $match = eval { /$a$c$a/ };
73d6d589 567 print "not "
2cd61cdb
IZ
568 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
569 print "ok $test\n";
570 $test++;
571}
cbce877f
IZ
572
573{
160cb429
JH
574 local $lex_a = 2;
575 my $lex_a = 43;
576 my $lex_b = 17;
577 my $lex_c = 27;
578 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
579 print "not " unless $lex_res eq '1';
580 print "ok $test\n";
581 $test++;
582 print "not " unless $lex_a eq '44';
583 print "ok $test\n";
584 $test++;
585 print "not " unless $lex_c eq '43';
586 print "ok $test\n";
587 $test++;
588}
589
590{
cbce877f
IZ
591 package aa;
592 $c = 2;
593 $::c = 3;
594 '' =~ /(?{ $c = 4 })/;
595 print "not " unless $c == 4;
596}
597print "ok $test\n";
598$test++;
599print "not " unless $c == 3;
600print "ok $test\n";
73d6d589
NIS
601$test++;
602
4599a1de
JH
603sub must_warn_pat {
604 my $warn_pat = shift;
605 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
606}
607
608sub must_warn {
609 my ($warn_pat, $code) = @_;
9f1b1f2d
GS
610 local %SIG;
611 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
4599a1de
JH
612 print "ok $test\n";
613 $test++;
614}
615
616
617sub make_must_warn {
618 my $warn_pat = shift;
619 return sub { must_warn(must_warn_pat($warn_pat)) }
620}
621
622my $for_future = make_must_warn('reserved for future extensions');
623
624&$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
9baa0206
HS
625
626#&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
627print "ok $test\n"; $test++; # now a fatal croak
628
629#&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
630print "ok $test\n"; $test++; # now a fatal croak
f7e33566
GS
631
632# test if failure of patterns returns empty list
633$_ = 'aaa';
634@_ = /bbb/;
635print "not " if @_;
636print "ok $test\n";
637$test++;
638
639@_ = /bbb/g;
640print "not " if @_;
641print "ok $test\n";
642$test++;
643
644@_ = /(bbb)/;
645print "not " if @_;
646print "ok $test\n";
647$test++;
648
649@_ = /(bbb)/g;
650print "not " if @_;
651print "ok $test\n";
652$test++;
653
6cef1e77
IZ
654/a(?=.$)/;
655print "not " if $#+ != 0 or $#- != 0;
656print "ok $test\n";
657$test++;
658
659print "not " if $+[0] != 2 or $-[0] != 1;
660print "ok $test\n";
661$test++;
662
73d6d589 663print "not "
6cef1e77
IZ
664 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
665print "ok $test\n";
666$test++;
667
668/a(a)(a)/;
669print "not " if $#+ != 2 or $#- != 2;
670print "ok $test\n";
671$test++;
672
673print "not " if $+[0] != 3 or $-[0] != 0;
674print "ok $test\n";
675$test++;
676
677print "not " if $+[1] != 2 or $-[1] != 1;
678print "ok $test\n";
679$test++;
680
681print "not " if $+[2] != 3 or $-[2] != 2;
682print "ok $test\n";
683$test++;
684
73d6d589 685print "not "
6cef1e77
IZ
686 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
687print "ok $test\n";
688$test++;
689
690/.(a)(b)?(a)/;
691print "not " if $#+ != 3 or $#- != 3;
692print "ok $test\n";
693$test++;
694
695print "not " if $+[0] != 3 or $-[0] != 0;
696print "ok $test\n";
697$test++;
698
699print "not " if $+[1] != 2 or $-[1] != 1;
700print "ok $test\n";
701$test++;
702
703print "not " if $+[3] != 3 or $-[3] != 2;
704print "ok $test\n";
705$test++;
706
73d6d589 707print "not "
6cef1e77
IZ
708 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
709print "ok $test\n";
710$test++;
711
712/.(a)/;
713print "not " if $#+ != 1 or $#- != 1;
714print "ok $test\n";
715$test++;
716
717print "not " if $+[0] != 2 or $-[0] != 0;
718print "ok $test\n";
719$test++;
720
721print "not " if $+[1] != 2 or $-[1] != 1;
722print "ok $test\n";
723$test++;
724
73d6d589 725print "not "
6cef1e77
IZ
726 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
727print "ok $test\n";
728$test++;
729
03a27ae7 730eval { $+[0] = 13; };
73d6d589 731print "not "
03a27ae7
MG
732 if $@ !~ /^Modification of a read-only value attempted/;
733print "ok $test\n";
734$test++;
735
736eval { $-[0] = 13; };
73d6d589 737print "not "
03a27ae7
MG
738 if $@ !~ /^Modification of a read-only value attempted/;
739print "ok $test\n";
740$test++;
741
742eval { @+ = (7, 6, 5); };
73d6d589 743print "not "
03a27ae7
MG
744 if $@ !~ /^Modification of a read-only value attempted/;
745print "ok $test\n";
746$test++;
747
748eval { @- = qw(foo bar); };
73d6d589 749print "not "
03a27ae7
MG
750 if $@ !~ /^Modification of a read-only value attempted/;
751print "ok $test\n";
752$test++;
753
8f580fb8
IZ
754/.(a)(ba*)?/;
755print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
756print "ok $test\n";
757$test++;
758
ad94a511
IZ
759$_ = 'aaa';
760pos = 1;
761@a = /\Ga/g;
762print "not " unless "@a" eq "a a";
763print "ok $test\n";
764$test++;
765
22e551b9
IZ
766$str = 'abcde';
767pos $str = 2;
768
769print "not " if $str =~ /^\G/;
770print "ok $test\n";
771$test++;
772
773print "not " if $str =~ /^.\G/;
774print "ok $test\n";
775$test++;
776
777print "not " unless $str =~ /^..\G/;
778print "ok $test\n";
779$test++;
780
781print "not " if $str =~ /^...\G/;
782print "ok $test\n";
783$test++;
784
785print "not " unless $str =~ /.\G./ and $& eq 'bc';
786print "ok $test\n";
787$test++;
788
789print "not " unless $str =~ /\G../ and $& eq 'cd';
790print "ok $test\n";
791$test++;
792
9661b544
IZ
793undef $foo; undef $bar;
794print "#'$str','$foo','$bar'\nnot "
73d6d589 795 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
9661b544
IZ
796 and $foo eq 'abcde' and $bar eq 2;
797print "ok $test\n";
798$test++;
799
800undef $foo; undef $bar;
801pos $str = undef;
802print "#'$str','$foo','$bar'\nnot "
73d6d589 803 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
9661b544
IZ
804 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
805print "ok $test\n";
806$test++;
807
808$_ = $str;
809
810undef $foo; undef $bar;
811print "#'$str','$foo','$bar'\nnot "
73d6d589 812 unless /b(?{$foo = $_; $bar = pos})c/
9661b544
IZ
813 and $foo eq 'abcde' and $bar eq 2;
814print "ok $test\n";
815$test++;
816
817undef $foo; undef $bar;
818print "#'$str','$foo','$bar'\nnot "
73d6d589 819 unless /b(?{$foo = $_; $bar = pos})c/g
9661b544
IZ
820 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
821print "ok $test\n";
822$test++;
823
824undef $foo; undef $bar;
825pos = undef;
8261 while /b(?{$foo = $_; $bar = pos})c/g;
827print "#'$str','$foo','$bar'\nnot "
828 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
829print "ok $test\n";
830$test++;
831
832undef $foo; undef $bar;
833$_ = 'abcde|abcde';
834print "#'$str','$foo','$bar','$_'\nnot "
73d6d589 835 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
9661b544
IZ
836 and $bar eq 8 and $_ eq 'axde|axde';
837print "ok $test\n";
838$test++;
839
5c5e4c24
IZ
840@res = ();
841# List context:
842$_ = 'abcde|abcde';
843@dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
844@res = map {defined $_ ? "'$_'" : 'undef'} @res;
845$res = "@res";
846print "#'@res' '$_'\nnot "
847 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
848print "ok $test\n";
849$test++;
850
851@res = ();
852@dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
853@res = map {defined $_ ? "'$_'" : 'undef'} @res;
854$res = "@res";
855print "#'@res' '$_'\nnot "
856 unless "@res" eq
857 "'' 'ab' 'cde|abcde' " .
858 "'' 'abc' 'de|abcde' " .
859 "'abcd' 'e|' 'abcde' " .
860 "'abcde|' 'ab' 'cde' " .
861 "'abcde|' 'abc' 'de'" ;
862print "ok $test\n";
863$test++;
864
b7a35066
IZ
865#Some more \G anchor checks
866$foo='aabbccddeeffgg';
867
868pos($foo)=1;
869
870$foo=~/.\G(..)/g;
871print "not " unless($1 eq 'ab');
872print "ok $test\n";
873$test++;
874
875pos($foo) += 1;
876$foo=~/.\G(..)/g;
877print "not " unless($1 eq 'cc');
878print "ok $test\n";
879$test++;
880
881pos($foo) += 1;
882$foo=~/.\G(..)/g;
883print "not " unless($1 eq 'de');
884print "ok $test\n";
885$test++;
886
0ef3e39e
HS
887print "not " unless $foo =~ /\Gef/g;
888print "ok $test\n";
889$test++;
890
b7a35066
IZ
891undef pos $foo;
892
893$foo=~/\G(..)/g;
894print "not " unless($1 eq 'aa');
895print "ok $test\n";
896$test++;
897
898$foo=~/\G(..)/g;
899print "not " unless($1 eq 'bb');
900print "ok $test\n";
901$test++;
902
903pos($foo)=5;
904$foo=~/\G(..)/g;
905print "not " unless($1 eq 'cd');
906print "ok $test\n";
907$test++;
908
73d6d589 909$_='123x123';
e60df1fa
IZ
910@res = /(\d*|x)/g;
911print "not " unless('123||x|123|' eq join '|', @res);
912print "ok $test\n";
913$test++;
914
9d080a66
GS
915# see if matching against temporaries (created via pp_helem()) is safe
916{ foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
917print "$1\n";
918$test++;
919
cf93c79d
IZ
920# See if $i work inside (?{}) in the presense of saved substrings and
921# changing $_
922@a = qw(foo bar);
923@b = ();
924s/(\w)(?{push @b, $1})/,$1,/g for @a;
925
926print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
927print "ok $test\n";
928$test++;
929
930print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
931print "ok $test\n";
932$test++;
933
2c914db6 934$brackets = qr{
14455d6c 935 { (?> [^{}]+ | (??{ $brackets }) )* }
2c914db6
IZ
936 }x;
937
938"{{}" =~ $brackets;
939print "ok $test\n"; # Did we survive?
940$test++;
941
942"something { long { and } hairy" =~ $brackets;
943print "ok $test\n"; # Did we survive?
944$test++;
945
14455d6c 946"something { long { and } hairy" =~ m/((??{ $brackets }))/;
2c914db6
IZ
947print "not " unless $1 eq "{ and }";
948print "ok $test\n";
949$test++;
950
30944b6d
IZ
951$_ = "a-a\nxbb";
952pos=1;
953m/^-.*bb/mg and print "not ";
954print "ok $test\n";
955$test++;
30382c73
IZ
956
957$text = "aaXbXcc";
958pos($text)=0;
959$text =~ /\GXb*X/g and print 'not ';
960print "ok $test\n";
961$test++;
3cf5c195
IZ
962
963$text = "xA\n" x 500;
964$text =~ /^\s*A/m and print 'not ';
965print "ok $test\n";
966$test++;
d506a20d
IZ
967
968$text = "abc dbf";
969@res = ($text =~ /.*?(b).*?\b/g);
970"@res" eq 'b b' or print 'not ';
971print "ok $test\n";
972$test++;
973
9442cb0e 974@a = map chr,0..255;
aeaf5620
GS
975
976@b = grep(/\S/,@a);
977@c = grep(/[^\s]/,@a);
978print "not " if "@b" ne "@c";
9442cb0e
GS
979print "ok $test\n";
980$test++;
981
aeaf5620
GS
982@b = grep(/\S/,@a);
983@c = grep(/[\S]/,@a);
984print "not " if "@b" ne "@c";
9442cb0e
GS
985print "ok $test\n";
986$test++;
987
aeaf5620
GS
988@b = grep(/\s/,@a);
989@c = grep(/[^\S]/,@a);
990print "not " if "@b" ne "@c";
9442cb0e
GS
991print "ok $test\n";
992$test++;
993
aeaf5620
GS
994@b = grep(/\s/,@a);
995@c = grep(/[\s]/,@a);
996print "not " if "@b" ne "@c";
9442cb0e
GS
997print "ok $test\n";
998$test++;
999
aeaf5620
GS
1000@b = grep(/\D/,@a);
1001@c = grep(/[^\d]/,@a);
1002print "not " if "@b" ne "@c";
9442cb0e
GS
1003print "ok $test\n";
1004$test++;
1005
aeaf5620
GS
1006@b = grep(/\D/,@a);
1007@c = grep(/[\D]/,@a);
1008print "not " if "@b" ne "@c";
9442cb0e
GS
1009print "ok $test\n";
1010$test++;
1011
aeaf5620
GS
1012@b = grep(/\d/,@a);
1013@c = grep(/[^\D]/,@a);
1014print "not " if "@b" ne "@c";
9442cb0e
GS
1015print "ok $test\n";
1016$test++;
1017
aeaf5620
GS
1018@b = grep(/\d/,@a);
1019@c = grep(/[\d]/,@a);
1020print "not " if "@b" ne "@c";
9442cb0e
GS
1021print "ok $test\n";
1022$test++;
1023
aeaf5620
GS
1024@b = grep(/\W/,@a);
1025@c = grep(/[^\w]/,@a);
1026print "not " if "@b" ne "@c";
9442cb0e
GS
1027print "ok $test\n";
1028$test++;
1029
aeaf5620
GS
1030@b = grep(/\W/,@a);
1031@c = grep(/[\W]/,@a);
1032print "not " if "@b" ne "@c";
9442cb0e
GS
1033print "ok $test\n";
1034$test++;
1035
aeaf5620
GS
1036@b = grep(/\w/,@a);
1037@c = grep(/[^\W]/,@a);
1038print "not " if "@b" ne "@c";
9442cb0e
GS
1039print "ok $test\n";
1040$test++;
1041
aeaf5620
GS
1042@b = grep(/\w/,@a);
1043@c = grep(/[\w]/,@a);
1044print "not " if "@b" ne "@c";
9442cb0e
GS
1045print "ok $test\n";
1046$test++;
1aeab75a
GS
1047
1048# see if backtracking optimization works correctly
1049"\n\n" =~ /\n $ \n/x or print "not ";
1050print "ok $test\n";
1051$test++;
1052
1053"\n\n" =~ /\n* $ \n/x or print "not ";
1054print "ok $test\n";
1055$test++;
1056
1057"\n\n" =~ /\n+ $ \n/x or print "not ";
1058print "ok $test\n";
1059$test++;
05b4157f
GS
1060
1061[] =~ /^ARRAY/ or print "# [] \nnot ";
1062print "ok $test\n";
1063$test++;
1064
1065eval << 'EOE';
1066{
1067 package S;
1068 use overload '""' => sub { 'Object S' };
1069 sub new { bless [] }
1070}
1071$a = 'S'->new;
1072EOE
1073
1074$a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1075print "ok $test\n";
1076$test++;
815d35b9
G
1077
1078# test result of match used as match (!)
1079'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1080print "ok $test\n";
1081$test++;
1082
1083'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1084print "ok $test\n";
1085$test++;
5e39e1e5
HS
1086
1087$w = 0;
1088{
1089 local $SIG{__WARN__} = sub { $w = 1 };
1090 local $^W = 1;
1091 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1092}
1093print $w ? "not " : "", "ok $test\n";
1094$test++;
aaa51d5e
JF
1095
1096my %space = ( spc => " ",
1097 tab => "\t",
1098 cr => "\r",
1099 lf => "\n",
1100 ff => "\f",
75369ccb
JH
1101# There's no \v but the vertical tabulator seems miraculously
1102# be 11 both in ASCII and EBCDIC.
aaa51d5e
JF
1103 vt => chr(11),
1104 false => "space" );
1105
1106my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1107my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1108my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1109
1110print "not " unless "@space0" eq "cr ff lf spc tab";
3bec3564 1111print "ok $test # @space0\n";
aaa51d5e
JF
1112$test++;
1113
1114print "not " unless "@space1" eq "cr ff lf spc tab vt";
3bec3564 1115print "ok $test # @space1\n";
aaa51d5e
JF
1116$test++;
1117
1118print "not " unless "@space2" eq "spc tab";
3bec3564 1119print "ok $test # @space2\n";
aaa51d5e 1120$test++;
73d6d589 1121
a1933d95
HS
1122# bugid 20001021.005 - this caused a SEGV
1123print "not " unless undef =~ /^([^\/]*)(.*)$/;
1124print "ok $test\n";
1125$test++;
b91bb191
JH
1126
1127# bugid 20000731.001
1128
1129print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1130print "ok $test\n";
1131$test++;
1132
3baa4c62
JH
1133$_ = "a\x{100}b";
1134if (/(.)(\C)(\C)(.)/) {
1135 print "ok 232\n";
1136 if ($1 eq "a") {
1137 print "ok 233\n";
1138 } else {
1139 print "not ok 233\n";
1140 }
1141 if ($2 eq "\xC4") {
1142 print "ok 234\n";
1143 } else {
1144 print "not ok 234\n";
1145 }
1146 if ($3 eq "\x80") {
1147 print "ok 235\n";
1148 } else {
1149 print "not ok 235\n";
1150 }
1151 if ($4 eq "b") {
1152 print "ok 236\n";
1153 } else {
1154 print "not ok 236\n";
1155 }
1156} else {
1157 for (232..236) {
1158 print "not ok $_\n";
1159 }
1160}
1161$_ = "\x{100}";
1162if (/(\C)/g) {
1163 print "ok 237\n";
73d6d589 1164 # currently \C are still tagged as UTF-8
3baa4c62
JH
1165 if ($1 eq "\xC4") {
1166 print "ok 238\n";
1167 } else {
1168 print "not ok 238\n";
1169 }
1170} else {
1171 for (237..238) {
1172 print "not ok $_\n";
1173 }
1174}
1175if (/(\C)/g) {
1176 print "ok 239\n";
73d6d589 1177 # currently \C are still tagged as UTF-8
3baa4c62
JH
1178 if ($1 eq "\x80") {
1179 print "ok 240\n";
1180 } else {
1181 print "not ok 240\n";
1182 }
1183} else {
1184 for (239..240) {
1185 print "not ok $_\n";
1186 }
1187}
b485d051 1188
db615365
JP
1189{
1190 # japhy -- added 03/03/2001
1191 () = (my $str = "abc") =~ /(...)/;
1192 $str = "def";
1193 print "not " if $1 ne "abc";
fd291da9
JH
1194 print "ok 241\n";
1195}
1196
1197# The 242 and 243 go with the 244 and 245.
1198# The trick is that in EBCDIC the explicit numeric range should match
1199# (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1200
1201if ("\x8e" =~ /[\x89-\x91]/) {
1202 print "ok 242\n";
1203} else {
1204 print "not ok 242\n";
1205}
1206
1207if ("\xce" =~ /[\xc9-\xd1]/) {
db615365 1208 print "ok 243\n";
fd291da9
JH
1209} else {
1210 print "not ok 243\n";
1211}
1212
1213# In most places these tests would succeed since \x8e does not
1214# in most character sets match 'i' or 'j' nor would \xce match
1215# 'I' or 'J', but strictly speaking these tests are here for
1216# the good of EBCDIC, so let's test these only there.
1217if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1218 if ("\x8e" !~ /[i-j]/) {
1219 print "ok 244\n";
1220 } else {
1221 print "not ok 244\n";
1222 }
1223 if ("\xce" !~ /[I-J]/) {
1224 print "ok 245\n";
1225 } else {
1226 print "not ok 245\n";
1227 }
1228} else {
1229 for (244..245) {
60425c38 1230 print "ok $_ # Skip: only in EBCDIC\n";
fd291da9 1231 }
db615365 1232}
4765795a
JH
1233
1234print "not " unless "\x{ab}" =~ /\x{ab}/;
1235print "ok 246\n";
1236
1237print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1238print "ok 247\n";
1239
1240{
1241 # bug id 20001008.001
1242
4765795a
JH
1243 my $test = 248;
1244 my @x = ("stra\337e 138","stra\337e 138");
1245 for (@x) {
1246 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1247 my($latin) = /^(.+)(?:\s+\d)/;
1248 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1249 "#latin[$latin]\nnot ok $test\n";
1250 $test++;
1251 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1252 use utf8;
1253 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1254 }
1255}
1256
1257{
1258 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1259 print "ok 250\n";
1260
1261 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1262 print "ok 251\n";
1263
1264 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1265 print "ok 252\n";
1266
1267 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1268 print "ok 253\n";
1269
1270 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1271 print "ok 254\n";
1272
1273 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1274 print "ok 255\n";
1275
1276 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1277 print "ok 256\n";
1278
1279 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1280 print "ok 257\n";
1281}
1282
1283{
1284 # the first half of 20001028.003
1285
1286 my $X = chr(1448);
1287 my ($Y) = $X =~ /(.*)/;
1288 print "not " unless $Y eq v1448 && length($Y) == 1;
1289 print "ok 258\n";
1290}
1291
1292{
1293 # 20001108.001
1294
1295 my $X = "Szab\x{f3},Bal\x{e1}zs";
1296 my $Y = $X;
1297 $Y =~ s/(B)/$1/ for 0..3;
1298 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1299 print "ok 259\n";
1300}
1301
1302{
1303 # the second half of 20001028.003
1304
1305 $X =~ s/^/chr(1488)/e;
1306 print "not " unless length $X == 1 && ord($X) == 1488;
1307 print "ok 260\n";
1308}
1309
1310{
1311 # 20000517.001
1312
1313 my $x = "\x{100}A";
1314
1315 $x =~ s/A/B/;
1316
1317 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1318 print "ok 261\n";
1319}
1320
1321{
1322 # bug id 20001230.002
1323
1324 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1325 print "ok 262\n";
1326
1327 print "not " unless "École" =~ /^\C\C(c)/;
1328 print "ok 263\n";
1329}
1330
1331{
1332 my $test = 264; # till 575
1333
1334 use charnames ':full';
1335
1336 # This is far from complete testing, there are dozens of character
1337 # classes in Unicode. The mixing of literals and \N{...} is
1338 # intentional so that in non-Latin-1 places we test the native
1339 # characters, not the Unicode code points.
1340
1341 my %s = (
1342 "a" => 'Ll',
1343 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1344 "A" => 'Lu',
1345 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1346 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1347 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1348 "0" => 'Nd',
1349 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1350 "_" => 'N',
1351 "!" => 'P',
1352 " " => 'Zs',
1353 "\0" => 'Cc',
1354 );
73d6d589 1355
4765795a
JH
1356 for my $char (keys %s) {
1357 my $class = $s{$char};
1358 my $code = sprintf("%04x", ord($char));
1359 printf "# 0x$code\n";
1360 print "# IsAlpha\n";
1361 if ($class =~ /^[LM]/) {
1362 print "not " unless $char =~ /\p{IsAlpha}/;
1363 print "ok $test\n"; $test++;
1364 print "not " if $char =~ /\P{IsAlpha}/;
1365 print "ok $test\n"; $test++;
1366 } else {
1367 print "not " if $char =~ /\p{IsAlpha}/;
1368 print "ok $test\n"; $test++;
1369 print "not " unless $char =~ /\P{IsAlpha}/;
1370 print "ok $test\n"; $test++;
1371 }
1372 print "# IsAlnum\n";
1373 if ($class =~ /^[LMN]/ && $char ne "_") {
1374 print "not " unless $char =~ /\p{IsAlnum}/;
1375 print "ok $test\n"; $test++;
1376 print "not " if $char =~ /\P{IsAlnum}/;
1377 print "ok $test\n"; $test++;
1378 } else {
1379 print "not " if $char =~ /\p{IsAlnum}/;
1380 print "ok $test\n"; $test++;
1381 print "not " unless $char =~ /\P{IsAlnum}/;
1382 print "ok $test\n"; $test++;
1383 }
1384 print "# IsASCII\n";
1385 if ($code <= 127) {
1386 print "not " unless $char =~ /\p{IsASCII}/;
1387 print "ok $test\n"; $test++;
1388 print "not " if $char =~ /\P{IsASCII}/;
1389 print "ok $test\n"; $test++;
1390 } else {
1391 print "not " if $char =~ /\p{IsASCII}/;
1392 print "ok $test\n"; $test++;
1393 print "not " unless $char =~ /\P{IsASCII}/;
1394 print "ok $test\n"; $test++;
1395 }
1396 print "# IsCntrl\n";
1397 if ($class =~ /^C/) {
1398 print "not " unless $char =~ /\p{IsCntrl}/;
1399 print "ok $test\n"; $test++;
1400 print "not " if $char =~ /\P{IsCntrl}/;
1401 print "ok $test\n"; $test++;
1402 } else {
1403 print "not " if $char =~ /\p{IsCntrl}/;
1404 print "ok $test\n"; $test++;
1405 print "not " unless $char =~ /\P{IsCntrl}/;
1406 print "ok $test\n"; $test++;
1407 }
1408 print "# IsBlank\n";
1409 if ($class =~ /^Z[lp]/ || $char eq " ") {
1410 print "not " unless $char =~ /\p{IsBlank}/;
1411 print "ok $test\n"; $test++;
1412 print "not " if $char =~ /\P{IsBlank}/;
1413 print "ok $test\n"; $test++;
1414 } else {
1415 print "not " if $char =~ /\p{IsBlank}/;
1416 print "ok $test\n"; $test++;
1417 print "not " unless $char =~ /\P{IsBlank}/;
1418 print "ok $test\n"; $test++;
1419 }
1420 print "# IsDigit\n";
1421 if ($class =~ /^Nd$/) {
1422 print "not " unless $char =~ /\p{IsDigit}/;
1423 print "ok $test\n"; $test++;
1424 print "not " if $char =~ /\P{IsDigit}/;
1425 print "ok $test\n"; $test++;
1426 } else {
1427 print "not " if $char =~ /\p{IsDigit}/;
1428 print "ok $test\n"; $test++;
1429 print "not " unless $char =~ /\P{IsDigit}/;
1430 print "ok $test\n"; $test++;
1431 }
1432 print "# IsGraph\n";
1433 if ($class =~ /^([LMNPS])|Co/) {
1434 print "not " unless $char =~ /\p{IsGraph}/;
1435 print "ok $test\n"; $test++;
1436 print "not " if $char =~ /\P{IsGraph}/;
1437 print "ok $test\n"; $test++;
1438 } else {
1439 print "not " if $char =~ /\p{IsGraph}/;
1440 print "ok $test\n"; $test++;
1441 print "not " unless $char =~ /\P{IsGraph}/;
1442 print "ok $test\n"; $test++;
1443 }
1444 print "# IsLower\n";
1445 if ($class =~ /^Ll$/) {
1446 print "not " unless $char =~ /\p{IsLower}/;
1447 print "ok $test\n"; $test++;
1448 print "not " if $char =~ /\P{IsLower}/;
1449 print "ok $test\n"; $test++;
1450 } else {
1451 print "not " if $char =~ /\p{IsLower}/;
1452 print "ok $test\n"; $test++;
1453 print "not " unless $char =~ /\P{IsLower}/;
1454 print "ok $test\n"; $test++;
1455 }
1456 print "# IsPrint\n";
1457 if ($class =~ /^([LMNPS])|Co|Zs/) {
1458 print "not " unless $char =~ /\p{IsPrint}/;
1459 print "ok $test\n"; $test++;
1460 print "not " if $char =~ /\P{IsPrint}/;
1461 print "ok $test\n"; $test++;
1462 } else {
1463 print "not " if $char =~ /\p{IsPrint}/;
1464 print "ok $test\n"; $test++;
1465 print "not " unless $char =~ /\P{IsPrint}/;
1466 print "ok $test\n"; $test++;
1467 }
1468 print "# IsPunct\n";
1469 if ($class =~ /^P/ || $char eq "_") {
1470 print "not " unless $char =~ /\p{IsPunct}/;
1471 print "ok $test\n"; $test++;
1472 print "not " if $char =~ /\P{IsPunct}/;
1473 print "ok $test\n"; $test++;
1474 } else {
1475 print "not " if $char =~ /\p{IsPunct}/;
1476 print "ok $test\n"; $test++;
1477 print "not " unless $char =~ /\P{IsPunct}/;
1478 print "ok $test\n"; $test++;
1479 }
1480 print "# IsSpace\n";
1481 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1482 print "not " unless $char =~ /\p{IsSpace}/;
1483 print "ok $test\n"; $test++;
1484 print "not " if $char =~ /\P{IsSpace}/;
1485 print "ok $test\n"; $test++;
1486 } else {
1487 print "not " if $char =~ /\p{IsSpace}/;
1488 print "ok $test\n"; $test++;
1489 print "not " unless $char =~ /\P{IsSpace}/;
1490 print "ok $test\n"; $test++;
1491 }
1492 print "# IsUpper\n";
1493 if ($class =~ /^L[ut]/) {
1494 print "not " unless $char =~ /\p{IsUpper}/;
1495 print "ok $test\n"; $test++;
1496 print "not " if $char =~ /\P{IsUpper}/;
1497 print "ok $test\n"; $test++;
1498 } else {
1499 print "not " if $char =~ /\p{IsUpper}/;
1500 print "ok $test\n"; $test++;
1501 print "not " unless $char =~ /\P{IsUpper}/;
1502 print "ok $test\n"; $test++;
1503 }
1504 print "# IsWord\n";
1505 if ($class =~ /^[LMN]/ || $char eq "_") {
1506 print "not " unless $char =~ /\p{IsWord}/;
1507 print "ok $test\n"; $test++;
1508 print "not " if $char =~ /\P{IsWord}/;
1509 print "ok $test\n"; $test++;
1510 } else {
1511 print "not " if $char =~ /\p{IsWord}/;
1512 print "ok $test\n"; $test++;
1513 print "not " unless $char =~ /\P{IsWord}/;
1514 print "ok $test\n"; $test++;
1515 }
1516 }
1517}
1518
1519{
1520 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1521
1522 if (/(.\x{300})./) {
1523 print "ok 576\n";
1524
1525 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
73d6d589 1526 print "ok 577\n";
4765795a
JH
1527
1528 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
73d6d589 1529 print "ok 578\n";
4765795a
JH
1530
1531 print "not " unless $' eq "\x{400}defg" && length($') == 5;
73d6d589 1532 print "ok 579\n";
4765795a
JH
1533
1534 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
73d6d589 1535 print "ok 580\n";
a8a2fe91
JH
1536 } else {
1537 for (576..580) { print "not ok $_\n" }
4765795a
JH
1538 }
1539}
8269fa76
JH
1540
1541{
1542 # bug id 20010306.008
1543
1544 $a = "a\x{1234}";
1545 # The original bug report had 'no utf8' here but that was irrelevant.
1546 $a =~ m/\w/; # used to core dump
1547
1548 print "ok 581\n";
1549}