source: trunk/essentials/dev-lang/perl/t/op/pat.t

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 83.6 KB
Line 
1#!./perl
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.
6
7$| = 1;
8
9print "1..1187\n";
10
11BEGIN {
12 chdir 't' if -d 't';
13 @INC = '../lib';
14}
15
16eval 'use Config'; # Defaults assumed if this fails
17
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";}
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
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');
81while ($_ = shift(@XXX)) {
82 ?(.*)? && (print $1,"\n");
83 /not/ && reset;
84 if (/not ok 26/) {
85 if ($^O eq 'VMS') {
86 $_ = shift(@XXX);
87 }
88 else {
89 reset 'X';
90 }
91 }
92}
93
94if ($^O ne 'VMS') {
95 while (($key,$val) = each(%XXX)) {
96 print "not ok 27\n";
97 exit;
98 }
99}
100
101print "ok 27\n";
102
103'cde' =~ /[^ab]*/;
104'xyz' =~ //;
105if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
106
107$foo = '[^ab]*';
108'cde' =~ /$foo/;
109'xyz' =~ //;
110if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
111
112$foo = '[^ab]*';
113'cde' =~ /$foo/;
114'xyz' =~ /$null/;
115if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
116
117$_ = 'abcdefghi';
118/def/; # optimized up to cmd
119if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
120
121/cde/ + 0; # optimized only to spat
122if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
123
124/[d][e][f]/; # not optimized
125if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
126
127$_ = 'now is the {time for all} good men to come to.';
128/ {([^}]*)}/;
129if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
130
131$_ = 'xxx {3,4} yyy zzz';
132print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
133print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
134print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
135print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
136print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
137print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
138print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
139print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
140print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
141
142$_ = "now is the time for all good men to come to.";
143@words = /(\w+)/g;
144print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
145 ? "ok 44\n"
146 : "not ok 44\n";
147
148@words = ();
149while (/\w+/g) {
150 push(@words, $&);
151}
152print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
153 ? "ok 45\n"
154 : "not ok 45\n";
155
156@words = ();
157pos = 0;
158while (/to/g) {
159 push(@words, $&);
160}
161print join(':',@words) eq "to:to"
162 ? "ok 46\n"
163 : "not ok 46 `@words'\n";
164
165pos $_ = 0;
166@words = /to/g;
167print join(':',@words) eq "to:to"
168 ? "ok 47\n"
169 : "not ok 47 `@words'\n";
170
171$_ = "abcdefghi";
172
173$pat1 = 'def';
174$pat2 = '^def';
175$pat3 = '.def.';
176$pat4 = 'abc';
177$pat5 = '^abc';
178$pat6 = 'abc$';
179$pat7 = 'ghi';
180$pat8 = '\w*ghi';
181$pat9 = 'ghi$';
182
183$t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
184
185for $iter (1..5) {
186 $t1++ if /$pat1/o;
187 $t2++ if /$pat2/o;
188 $t3++ if /$pat3/o;
189 $t4++ if /$pat4/o;
190 $t5++ if /$pat5/o;
191 $t6++ if /$pat6/o;
192 $t7++ if /$pat7/o;
193 $t8++ if /$pat8/o;
194 $t9++ if /$pat9/o;
195}
196
197$x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
198print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
199
200$xyz = 'xyz';
201print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
202
203# perl 4.009 says "unmatched ()"
204eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
205print $@ eq "" ? "ok 50\n" : "not ok 50\n";
206print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
207
208
209$_="abcfooabcbar";
210$x=/abc/g;
211print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
212$x=/abc/g;
213print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
214$x=/abc/g;
215print $x == 0 ? "ok 54\n" : "not ok 54\n";
216pos = 0;
217$x=/ABC/gi;
218print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
219$x=/ABC/gi;
220print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
221$x=/ABC/gi;
222print $x == 0 ? "ok 57\n" : "not ok 57\n";
223pos = 0;
224$x=/abc/g;
225print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
226$x=/abc/g;
227print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
228$_ .= '';
229@x=/abc/g;
230print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
231
232$_ = "abdc";
233pos $_ = 2;
234/\Gc/gc;
235print "not " if (pos $_) != 2;
236print "ok 61\n";
237/\Gc/g;
238print "not " if defined pos $_;
239print "ok 62\n";
240
241$out = 1;
242'abc' =~ m'a(?{ $out = 2 })b';
243print "not " if $out != 2;
244print "ok 63\n";
245
246$out = 1;
247'abc' =~ m'a(?{ $out = 3 })c';
248print "not " if $out != 1;
249print "ok 64\n";
250
251$_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
252@out = /(?<!foo)bar./g;
253print "not " if "@out" ne 'bar2 barf';
254print "ok 65\n";
255
256# Tests which depend on REG_INFTY
257$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
258$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
259
260# As well as failing if the pattern matches do unexpected things, the
261# next three tests will fail if you should have picked up a lower-than-
262# default value for $reg_infty from Config.pm, but have not.
263
264undef $@;
265print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
266print "ok 66\n";
267
268undef $@;
269print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
270print "ok 67\n";
271
272undef $@;
273print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
274print "ok 68\n";
275
276undef $@;
277eval "'aaa' =~ /a{1,$reg_infty}/";
278print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
279print "ok 69\n";
280
281eval "'aaa' =~ /a{1,$reg_infty_p}/";
282print "not "
283 if $@ !~ m%^\QQuantifier in {,} bigger than%;
284print "ok 70\n";
285undef $@;
286
287# Poke a couple more parse failures
288
289$context = 'x' x 256;
290eval qq("${context}y" =~ /(?<=$context)y/);
291print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
292print "ok 71\n";
293
294# removed test
295print "ok 72\n";
296
297# Long Monsters
298$test = 73;
299for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
300 $a = 'a' x $l;
301 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
302 print "ok $test\n";
303 $test++;
304
305 print "not " if "b$a=" =~ /a$a=/;
306 print "ok $test\n";
307 $test++;
308}
309
310# 20000 nodes, each taking 3 words per string, and 1 per branch
311$long_constant_len = join '|', 12120 .. 32645;
312$long_var_len = join '|', 8120 .. 28645;
313%ans = ( 'ax13876y25677lbc' => 1,
314 'ax13876y25677mcb' => 0, # not b.
315 'ax13876y35677nbc' => 0, # Num too big
316 'ax13876y25677y21378obc' => 1,
317 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
318 'ax13876y25677y21378y21378kbc' => 1,
319 'ax13876y25677y21378y21378kcb' => 0, # Not b.
320 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
321 );
322
323for ( keys %ans ) {
324 print "# const-len `$_' not => $ans{$_}\nnot "
325 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
326 print "ok $test\n";
327 $test++;
328 print "# var-len `$_' not => $ans{$_}\nnot "
329 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
330 print "ok $test\n";
331 $test++;
332}
333
334$_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
335$expect = "(bla()) ((l)u((e))) (l(e)e)";
336
337sub matchit {
338 m/
339 (
340 \(
341 (?{ $c = 1 }) # Initialize
342 (?:
343 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
344 (?!
345 ) # Fail: will unwind one iteration back
346 )
347 (?:
348 [^()]+ # Match a big chunk
349 (?=
350 [()]
351 ) # Do not try to match subchunks
352 |
353 \(
354 (?{ ++$c })
355 |
356 \)
357 (?{ --$c })
358 )
359 )+ # This may not match with different subblocks
360 )
361 (?(?{ $c != 0 })
362 (?!
363 ) # Fail
364 ) # Otherwise the chunk 1 may succeed with $c>0
365 /xg;
366}
367
368@ans = ();
369push @ans, $res while $res = matchit;
370
371print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
372print "ok $test\n";
373$test++;
374
375@ans = matchit;
376
377print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
378print "ok $test\n";
379$test++;
380
381print "not " unless "abc" =~ /^(??{"a"})b/;
382print "ok $test\n";
383$test++;
384
385my $matched;
386$matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
387
388@ans = @ans1 = ();
389push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
390
391print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
392print "ok $test\n";
393$test++;
394
395print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
396print "ok $test\n";
397$test++;
398
399@ans = m/$matched/g;
400
401print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
402print "ok $test\n";
403$test++;
404
405@ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
406print "not " if "@ans" ne 'a/ b';
407print "ok $test\n";
408$test++;
409
410$code = '{$blah = 45}';
411$blah = 12;
412eval { /(?$code)/ };
413print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
414print "ok $test\n";
415$test++;
416
417for $code ('{$blah = 45}','=xx') {
418 $blah = 12;
419 $res = eval { "xx" =~ /(?$code)/o };
420 if ($code eq '=xx') {
421 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
422 } else {
423 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
424 }
425 print "ok $test\n";
426 $test++;
427}
428
429$code = '{$blah = 45}';
430$blah = 12;
431eval "/(?$code)/";
432print "not " if $blah != 45;
433print "ok $test\n";
434$test++;
435
436$blah = 12;
437/(?{$blah = 45})/;
438print "not " if $blah != 45;
439print "ok $test\n";
440$test++;
441
442$x = 'banana';
443$x =~ /.a/g;
444print "not " unless pos($x) == 2;
445print "ok $test\n";
446$test++;
447
448$x =~ /.z/gc;
449print "not " unless pos($x) == 2;
450print "ok $test\n";
451$test++;
452
453sub f {
454 my $p = $_[0];
455 return $p;
456}
457
458$x =~ /.a/g;
459print "not " unless f(pos($x)) == 4;
460print "ok $test\n";
461$test++;
462
463$x = $^R = 67;
464'foot' =~ /foo(?{$x = 12; 75})[t]/;
465print "not " unless $^R eq '75';
466print "ok $test\n";
467$test++;
468
469$x = $^R = 67;
470'foot' =~ /foo(?{$x = 12; 75})[xy]/;
471print "not " unless $^R eq '67' and $x eq '12';
472print "ok $test\n";
473$test++;
474
475$x = $^R = 67;
476'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
477print "not " unless $^R eq '79' and $x eq '12';
478print "ok $test\n";
479$test++;
480
481print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
482print "ok $test\n";
483$test++;
484
485print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
486print "ok $test\n";
487$test++;
488
489print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
490print "ok $test\n";
491$test++;
492
493print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
494print "ok $test\n";
495$test++;
496
497print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
498print "ok $test\n";
499$test++;
500
501print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
502print "ok $test\n";
503$test++;
504
505$_ = 'xabcx';
506foreach $ans ('', 'c') {
507 /(?<=(?=a)..)((?=c)|.)/g;
508 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
509 print "ok $test\n";
510 $test++;
511}
512
513$_ = 'a';
514foreach $ans ('', 'a', '') {
515 /^|a|$/g;
516 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
517 print "ok $test\n";
518 $test++;
519}
520
521sub prefixify {
522 my($v,$a,$b,$res) = @_;
523 $v =~ s/\Q$a\E/$b/;
524 print "not " unless $res eq $v;
525 print "ok $test\n";
526 $test++;
527}
528prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
529prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
530
531$_ = 'var="foo"';
532/(\")/;
533print "not " unless $1 and /$1/;
534print "ok $test\n";
535$test++;
536
537$a=qr/(?{++$b})/;
538$b = 7;
539/$a$a/;
540print "not " unless $b eq '9';
541print "ok $test\n";
542$test++;
543
544$c="$a";
545/$a$a/;
546print "not " unless $b eq '11';
547print "ok $test\n";
548$test++;
549
550{
551 use re "eval";
552 /$a$c$a/;
553 print "not " unless $b eq '14';
554 print "ok $test\n";
555 $test++;
556
557 local $lex_a = 2;
558 my $lex_a = 43;
559 my $lex_b = 17;
560 my $lex_c = 27;
561 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
562 print "not " unless $lex_res eq '1';
563 print "ok $test\n";
564 $test++;
565 print "not " unless $lex_a eq '44';
566 print "ok $test\n";
567 $test++;
568 print "not " unless $lex_c eq '43';
569 print "ok $test\n";
570 $test++;
571
572
573 no re "eval";
574 $match = eval { /$a$c$a/ };
575 print "not "
576 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
577 print "ok $test\n";
578 $test++;
579}
580
581{
582 local $lex_a = 2;
583 my $lex_a = 43;
584 my $lex_b = 17;
585 my $lex_c = 27;
586 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
587 print "not " unless $lex_res eq '1';
588 print "ok $test\n";
589 $test++;
590 print "not " unless $lex_a eq '44';
591 print "ok $test\n";
592 $test++;
593 print "not " unless $lex_c eq '43';
594 print "ok $test\n";
595 $test++;
596}
597
598{
599 package aa;
600 $c = 2;
601 $::c = 3;
602 '' =~ /(?{ $c = 4 })/;
603 print "not " unless $c == 4;
604}
605print "ok $test\n";
606$test++;
607print "not " unless $c == 3;
608print "ok $test\n";
609$test++;
610
611sub must_warn_pat {
612 my $warn_pat = shift;
613 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
614}
615
616sub must_warn {
617 my ($warn_pat, $code) = @_;
618 local %SIG;
619 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
620 print "ok $test\n";
621 $test++;
622}
623
624
625sub make_must_warn {
626 my $warn_pat = shift;
627 return sub { must_warn(must_warn_pat($warn_pat)) }
628}
629
630my $for_future = make_must_warn('reserved for future extensions');
631
632&$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
633
634#&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
635print "ok $test\n"; $test++; # now a fatal croak
636
637#&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
638print "ok $test\n"; $test++; # now a fatal croak
639
640# test if failure of patterns returns empty list
641$_ = 'aaa';
642@_ = /bbb/;
643print "not " if @_;
644print "ok $test\n";
645$test++;
646
647@_ = /bbb/g;
648print "not " if @_;
649print "ok $test\n";
650$test++;
651
652@_ = /(bbb)/;
653print "not " if @_;
654print "ok $test\n";
655$test++;
656
657@_ = /(bbb)/g;
658print "not " if @_;
659print "ok $test\n";
660$test++;
661
662/a(?=.$)/;
663print "not " if $#+ != 0 or $#- != 0;
664print "ok $test\n";
665$test++;
666
667print "not " if $+[0] != 2 or $-[0] != 1;
668print "ok $test\n";
669$test++;
670
671print "not "
672 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
673print "ok $test\n";
674$test++;
675
676/a(a)(a)/;
677print "not " if $#+ != 2 or $#- != 2;
678print "ok $test\n";
679$test++;
680
681print "not " if $+[0] != 3 or $-[0] != 0;
682print "ok $test\n";
683$test++;
684
685print "not " if $+[1] != 2 or $-[1] != 1;
686print "ok $test\n";
687$test++;
688
689print "not " if $+[2] != 3 or $-[2] != 2;
690print "ok $test\n";
691$test++;
692
693print "not "
694 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
695print "ok $test\n";
696$test++;
697
698/.(a)(b)?(a)/;
699print "not " if $#+ != 3 or $#- != 3;
700print "ok $test\n";
701$test++;
702
703print "not " if $+[0] != 3 or $-[0] != 0;
704print "ok $test\n";
705$test++;
706
707print "not " if $+[1] != 2 or $-[1] != 1;
708print "ok $test\n";
709$test++;
710
711print "not " if $+[3] != 3 or $-[3] != 2;
712print "ok $test\n";
713$test++;
714
715print "not "
716 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
717print "ok $test\n";
718$test++;
719
720/.(a)/;
721print "not " if $#+ != 1 or $#- != 1;
722print "ok $test\n";
723$test++;
724
725print "not " if $+[0] != 2 or $-[0] != 0;
726print "ok $test\n";
727$test++;
728
729print "not " if $+[1] != 2 or $-[1] != 1;
730print "ok $test\n";
731$test++;
732
733print "not "
734 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
735print "ok $test\n";
736$test++;
737
738eval { $+[0] = 13; };
739print "not "
740 if $@ !~ /^Modification of a read-only value attempted/;
741print "ok $test\n";
742$test++;
743
744eval { $-[0] = 13; };
745print "not "
746 if $@ !~ /^Modification of a read-only value attempted/;
747print "ok $test\n";
748$test++;
749
750eval { @+ = (7, 6, 5); };
751print "not "
752 if $@ !~ /^Modification of a read-only value attempted/;
753print "ok $test\n";
754$test++;
755
756eval { @- = qw(foo bar); };
757print "not "
758 if $@ !~ /^Modification of a read-only value attempted/;
759print "ok $test\n";
760$test++;
761
762/.(a)(ba*)?/;
763print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
764print "ok $test\n";
765$test++;
766
767$_ = 'aaa';
768pos = 1;
769@a = /\Ga/g;
770print "not " unless "@a" eq "a a";
771print "ok $test\n";
772$test++;
773
774$str = 'abcde';
775pos $str = 2;
776
777print "not " if $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/;
786print "ok $test\n";
787$test++;
788
789print "not " if $str =~ /^...\G/;
790print "ok $test\n";
791$test++;
792
793print "not " unless $str =~ /.\G./ and $& eq 'bc';
794print "ok $test\n";
795$test++;
796
797print "not " unless $str =~ /\G../ and $& eq 'cd';
798print "ok $test\n";
799$test++;
800
801undef $foo; undef $bar;
802print "#'$str','$foo','$bar'\nnot "
803 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
804 and $foo eq 'abcde' and $bar eq 2;
805print "ok $test\n";
806$test++;
807
808undef $foo; undef $bar;
809pos $str = undef;
810print "#'$str','$foo','$bar'\nnot "
811 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
812 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
813print "ok $test\n";
814$test++;
815
816$_ = $str;
817
818undef $foo; undef $bar;
819print "#'$str','$foo','$bar'\nnot "
820 unless /b(?{$foo = $_; $bar = pos})c/
821 and $foo eq 'abcde' and $bar eq 2;
822print "ok $test\n";
823$test++;
824
825undef $foo; undef $bar;
826print "#'$str','$foo','$bar'\nnot "
827 unless /b(?{$foo = $_; $bar = pos})c/g
828 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
829print "ok $test\n";
830$test++;
831
832undef $foo; undef $bar;
833pos = undef;
8341 while /b(?{$foo = $_; $bar = pos})c/g;
835print "#'$str','$foo','$bar'\nnot "
836 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
837print "ok $test\n";
838$test++;
839
840undef $foo; undef $bar;
841$_ = 'abcde|abcde';
842print "#'$str','$foo','$bar','$_'\nnot "
843 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
844 and $bar eq 8 and $_ eq 'axde|axde';
845print "ok $test\n";
846$test++;
847
848@res = ();
849# List context:
850$_ = 'abcde|abcde';
851@dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
852@res = map {defined $_ ? "'$_'" : 'undef'} @res;
853$res = "@res";
854print "#'@res' '$_'\nnot "
855 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
856print "ok $test\n";
857$test++;
858
859@res = ();
860@dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
861@res = map {defined $_ ? "'$_'" : 'undef'} @res;
862$res = "@res";
863print "#'@res' '$_'\nnot "
864 unless "@res" eq
865 "'' 'ab' 'cde|abcde' " .
866 "'' 'abc' 'de|abcde' " .
867 "'abcd' 'e|' 'abcde' " .
868 "'abcde|' 'ab' 'cde' " .
869 "'abcde|' 'abc' 'de'" ;
870print "ok $test\n";
871$test++;
872
873#Some more \G anchor checks
874$foo='aabbccddeeffgg';
875
876pos($foo)=1;
877
878$foo=~/.\G(..)/g;
879print "not " unless($1 eq 'ab');
880print "ok $test\n";
881$test++;
882
883pos($foo) += 1;
884$foo=~/.\G(..)/g;
885print "not " unless($1 eq 'cc');
886print "ok $test\n";
887$test++;
888
889pos($foo) += 1;
890$foo=~/.\G(..)/g;
891print "not " unless($1 eq 'de');
892print "ok $test\n";
893$test++;
894
895print "not " unless $foo =~ /\Gef/g;
896print "ok $test\n";
897$test++;
898
899undef pos $foo;
900
901$foo=~/\G(..)/g;
902print "not " unless($1 eq 'aa');
903print "ok $test\n";
904$test++;
905
906$foo=~/\G(..)/g;
907print "not " unless($1 eq 'bb');
908print "ok $test\n";
909$test++;
910
911pos($foo)=5;
912$foo=~/\G(..)/g;
913print "not " unless($1 eq 'cd');
914print "ok $test\n";
915$test++;
916
917$_='123x123';
918@res = /(\d*|x)/g;
919print "not " unless('123||x|123|' eq join '|', @res);
920print "ok $test\n";
921$test++;
922
923# see if matching against temporaries (created via pp_helem()) is safe
924{ foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
925print "$1\n";
926$test++;
927
928# See if $i work inside (?{}) in the presense of saved substrings and
929# changing $_
930@a = qw(foo bar);
931@b = ();
932s/(\w)(?{push @b, $1})/,$1,/g for @a;
933
934print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
935print "ok $test\n";
936$test++;
937
938print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
939print "ok $test\n";
940$test++;
941
942$brackets = qr{
943 { (?> [^{}]+ | (??{ $brackets }) )* }
944 }x;
945
946"{{}" =~ $brackets;
947print "ok $test\n"; # Did we survive?
948$test++;
949
950"something { long { and } hairy" =~ $brackets;
951print "ok $test\n"; # Did we survive?
952$test++;
953
954"something { long { and } hairy" =~ m/((??{ $brackets }))/;
955print "not " unless $1 eq "{ and }";
956print "ok $test\n";
957$test++;
958
959$_ = "a-a\nxbb";
960pos=1;
961m/^-.*bb/mg and print "not ";
962print "ok $test\n";
963$test++;
964
965$text = "aaXbXcc";
966pos($text)=0;
967$text =~ /\GXb*X/g and print 'not ';
968print "ok $test\n";
969$test++;
970
971$text = "xA\n" x 500;
972$text =~ /^\s*A/m and print 'not ';
973print "ok $test\n";
974$test++;
975
976$text = "abc dbf";
977@res = ($text =~ /.*?(b).*?\b/g);
978"@res" eq 'b b' or print 'not ';
979print "ok $test\n";
980$test++;
981
982@a = map chr,0..255;
983
984@b = grep(/\S/,@a);
985@c = grep(/[^\s]/,@a);
986print "not " if "@b" ne "@c";
987print "ok $test\n";
988$test++;
989
990@b = grep(/\S/,@a);
991@c = grep(/[\S]/,@a);
992print "not " if "@b" ne "@c";
993print "ok $test\n";
994$test++;
995
996@b = grep(/\s/,@a);
997@c = grep(/[^\S]/,@a);
998print "not " if "@b" ne "@c";
999print "ok $test\n";
1000$test++;
1001
1002@b = grep(/\s/,@a);
1003@c = grep(/[\s]/,@a);
1004print "not " if "@b" ne "@c";
1005print "ok $test\n";
1006$test++;
1007
1008@b = grep(/\D/,@a);
1009@c = grep(/[^\d]/,@a);
1010print "not " if "@b" ne "@c";
1011print "ok $test\n";
1012$test++;
1013
1014@b = grep(/\D/,@a);
1015@c = grep(/[\D]/,@a);
1016print "not " if "@b" ne "@c";
1017print "ok $test\n";
1018$test++;
1019
1020@b = grep(/\d/,@a);
1021@c = grep(/[^\D]/,@a);
1022print "not " if "@b" ne "@c";
1023print "ok $test\n";
1024$test++;
1025
1026@b = grep(/\d/,@a);
1027@c = grep(/[\d]/,@a);
1028print "not " if "@b" ne "@c";
1029print "ok $test\n";
1030$test++;
1031
1032@b = grep(/\W/,@a);
1033@c = grep(/[^\w]/,@a);
1034print "not " if "@b" ne "@c";
1035print "ok $test\n";
1036$test++;
1037
1038@b = grep(/\W/,@a);
1039@c = grep(/[\W]/,@a);
1040print "not " if "@b" ne "@c";
1041print "ok $test\n";
1042$test++;
1043
1044@b = grep(/\w/,@a);
1045@c = grep(/[^\W]/,@a);
1046print "not " if "@b" ne "@c";
1047print "ok $test\n";
1048$test++;
1049
1050@b = grep(/\w/,@a);
1051@c = grep(/[\w]/,@a);
1052print "not " if "@b" ne "@c";
1053print "ok $test\n";
1054$test++;
1055
1056# see if backtracking optimization works correctly
1057"\n\n" =~ /\n $ \n/x or print "not ";
1058print "ok $test\n";
1059$test++;
1060
1061"\n\n" =~ /\n* $ \n/x or print "not ";
1062print "ok $test\n";
1063$test++;
1064
1065"\n\n" =~ /\n+ $ \n/x or print "not ";
1066print "ok $test\n";
1067$test++;
1068
1069[] =~ /^ARRAY/ or print "# [] \nnot ";
1070print "ok $test\n";
1071$test++;
1072
1073eval << 'EOE';
1074{
1075 package S;
1076 use overload '""' => sub { 'Object S' };
1077 sub new { bless [] }
1078}
1079$a = 'S'->new;
1080EOE
1081
1082$a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1083print "ok $test\n";
1084$test++;
1085
1086# test result of match used as match (!)
1087'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1088print "ok $test\n";
1089$test++;
1090
1091'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1092print "ok $test\n";
1093$test++;
1094
1095$w = 0;
1096{
1097 local $SIG{__WARN__} = sub { $w = 1 };
1098 local $^W = 1;
1099 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1100}
1101print $w ? "not " : "", "ok $test\n";
1102$test++;
1103
1104my %space = ( spc => " ",
1105 tab => "\t",
1106 cr => "\r",
1107 lf => "\n",
1108 ff => "\f",
1109# There's no \v but the vertical tabulator seems miraculously
1110# be 11 both in ASCII and EBCDIC.
1111 vt => chr(11),
1112 false => "space" );
1113
1114my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1115my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1116my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1117
1118print "not " unless "@space0" eq "cr ff lf spc tab";
1119print "ok $test # @space0\n";
1120$test++;
1121
1122print "not " unless "@space1" eq "cr ff lf spc tab vt";
1123print "ok $test # @space1\n";
1124$test++;
1125
1126print "not " unless "@space2" eq "spc tab";
1127print "ok $test # @space2\n";
1128$test++;
1129
1130# bugid 20001021.005 - this caused a SEGV
1131print "not " unless undef =~ /^([^\/]*)(.*)$/;
1132print "ok $test\n";
1133$test++;
1134
1135# bugid 20000731.001
1136
1137print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1138print "ok $test\n";
1139$test++;
1140
1141my $ordA = ord('A');
1142
1143$_ = "a\x{100}b";
1144if (/(.)(\C)(\C)(.)/) {
1145 print "ok 232\n";
1146 if ($1 eq "a") {
1147 print "ok 233\n";
1148 } else {
1149 print "not ok 233\n";
1150 }
1151 if ($ordA == 65) { # ASCII (or equivalent), should be UTF-8
1152 if ($2 eq "\xC4") {
1153 print "ok 234\n";
1154 } else {
1155 print "not ok 234\n";
1156 }
1157 if ($3 eq "\x80") {
1158 print "ok 235\n";
1159 } else {
1160 print "not ok 235\n";
1161 }
1162 } elsif ($ordA == 193) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1163 if ($2 eq "\x8C") {
1164 print "ok 234\n";
1165 } else {
1166 print "not ok 234\n";
1167 }
1168 if ($3 eq "\x41") {
1169 print "ok 235\n";
1170 } else {
1171 print "not ok 235\n";
1172 }
1173 } else {
1174 for (234..235) {
1175 print "not ok $_ # ord('A') == $ordA\n";
1176 }
1177 }
1178 if ($4 eq "b") {
1179 print "ok 236\n";
1180 } else {
1181 print "not ok 236\n";
1182 }
1183} else {
1184 for (232..236) {
1185 print "not ok $_\n";
1186 }
1187}
1188$_ = "\x{100}";
1189if (/(\C)/g) {
1190 print "ok 237\n";
1191 # currently \C are still tagged as UTF-8
1192 if ($ordA == 65) {
1193 if ($1 eq "\xC4") {
1194 print "ok 238\n";
1195 } else {
1196 print "not ok 238\n";
1197 }
1198 } elsif ($ordA == 193) {
1199 if ($1 eq "\x8C") {
1200 print "ok 238\n";
1201 } else {
1202 print "not ok 238\n";
1203 }
1204 } else {
1205 print "not ok 238 # ord('A') == $ordA\n";
1206 }
1207} else {
1208 for (237..238) {
1209 print "not ok $_\n";
1210 }
1211}
1212if (/(\C)/g) {
1213 print "ok 239\n";
1214 # currently \C are still tagged as UTF-8
1215 if ($ordA == 65) {
1216 if ($1 eq "\x80") {
1217 print "ok 240\n";
1218 } else {
1219 print "not ok 240\n";
1220 }
1221 } elsif ($ordA == 193) {
1222 if ($1 eq "\x41") {
1223 print "ok 240\n";
1224 } else {
1225 print "not ok 240\n";
1226 }
1227 } else {
1228 print "not ok 240 # ord('A') == $ordA\n";
1229 }
1230} else {
1231 for (239..240) {
1232 print "not ok $_\n";
1233 }
1234}
1235
1236{
1237 # japhy -- added 03/03/2001
1238 () = (my $str = "abc") =~ /(...)/;
1239 $str = "def";
1240 print "not " if $1 ne "abc";
1241 print "ok 241\n";
1242}
1243
1244# The 242 and 243 go with the 244 and 245.
1245# The trick is that in EBCDIC the explicit numeric range should match
1246# (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1247
1248if ("\x8e" =~ /[\x89-\x91]/) {
1249 print "ok 242\n";
1250} else {
1251 print "not ok 242\n";
1252}
1253
1254if ("\xce" =~ /[\xc9-\xd1]/) {
1255 print "ok 243\n";
1256} else {
1257 print "not ok 243\n";
1258}
1259
1260# In most places these tests would succeed since \x8e does not
1261# in most character sets match 'i' or 'j' nor would \xce match
1262# 'I' or 'J', but strictly speaking these tests are here for
1263# the good of EBCDIC, so let's test these only there.
1264if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1265 if ("\x8e" !~ /[i-j]/) {
1266 print "ok 244\n";
1267 } else {
1268 print "not ok 244\n";
1269 }
1270 if ("\xce" !~ /[I-J]/) {
1271 print "ok 245\n";
1272 } else {
1273 print "not ok 245\n";
1274 }
1275} else {
1276 for (244..245) {
1277 print "ok $_ # Skip: only in EBCDIC\n";
1278 }
1279}
1280
1281print "not " unless "\x{ab}" =~ /\x{ab}/;
1282print "ok 246\n";
1283
1284print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1285print "ok 247\n";
1286
1287{
1288 # bug id 20001008.001
1289
1290 my $test = 248;
1291 my @x = ("stra\337e 138","stra\337e 138");
1292 for (@x) {
1293 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1294 my($latin) = /^(.+)(?:\s+\d)/;
1295 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1296 "#latin[$latin]\nnot ok $test\n";
1297 $test++;
1298 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1299 use utf8; # needed for the raw UTF-8
1300 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1301 }
1302}
1303
1304{
1305 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1306 print "ok 250\n";
1307
1308 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1309 print "ok 251\n";
1310
1311 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1312 print "ok 252\n";
1313
1314 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1315 print "ok 253\n";
1316
1317 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1318 print "ok 254\n";
1319
1320 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1321 print "ok 255\n";
1322
1323 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1324 print "ok 256\n";
1325
1326 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1327 print "ok 257\n";
1328}
1329
1330{
1331 # the first half of 20001028.003
1332
1333 my $X = chr(1448);
1334 my ($Y) = $X =~ /(.*)/;
1335 print "not " unless $Y eq v1448 && length($Y) == 1;
1336 print "ok 258\n";
1337}
1338
1339{
1340 # 20001108.001
1341
1342 my $X = "Szab\x{f3},Bal\x{e1}zs";
1343 my $Y = $X;
1344 $Y =~ s/(B)/$1/ for 0..3;
1345 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1346 print "ok 259\n";
1347}
1348
1349{
1350 # the second half of 20001028.003
1351
1352 my $X = '';
1353 $X =~ s/^/chr(1488)/e;
1354 print "not " unless length $X == 1 && ord($X) == 1488;
1355 print "ok 260\n";
1356}
1357
1358{
1359 # 20000517.001
1360
1361 my $x = "\x{100}A";
1362
1363 $x =~ s/A/B/;
1364
1365 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1366 print "ok 261\n";
1367}
1368
1369{
1370 # bug id 20001230.002
1371
1372 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1373 print "ok 262\n";
1374
1375 print "not " unless "École" =~ /^\C\C(c)/;
1376 print "ok 263\n";
1377}
1378
1379SKIP: {
1380 my $test = 264; # till 575
1381
1382 use charnames ":full";
1383
1384 # This is far from complete testing, there are dozens of character
1385 # classes in Unicode. The mixing of literals and \N{...} is
1386 # intentional so that in non-Latin-1 places we test the native
1387 # characters, not the Unicode code points.
1388
1389 my %s = (
1390 "a" => 'Ll',
1391 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1392 "A" => 'Lu',
1393 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1394 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1395 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1396 "0" => 'Nd',
1397 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1398 "_" => 'N',
1399 "!" => 'P',
1400 " " => 'Zs',
1401 "\0" => 'Cc',
1402 );
1403
1404 for my $char (map { s/^\S+ //; $_ }
1405 sort map { sprintf("%06x", ord($_))." $_" } keys %s) {
1406 my $class = $s{$char};
1407 my $code = sprintf("%06x", ord($char));
1408 printf "#\n# 0x$code\n#\n";
1409 print "# IsAlpha\n";
1410 if ($class =~ /^[LM]/) {
1411 print "not " unless $char =~ /\p{IsAlpha}/;
1412 print "ok $test\n"; $test++;
1413 print "not " if $char =~ /\P{IsAlpha}/;
1414 print "ok $test\n"; $test++;
1415 } else {
1416 print "not " if $char =~ /\p{IsAlpha}/;
1417 print "ok $test\n"; $test++;
1418 print "not " unless $char =~ /\P{IsAlpha}/;
1419 print "ok $test\n"; $test++;
1420 }
1421 print "# IsAlnum\n";
1422 if ($class =~ /^[LMN]/ && $char ne "_") {
1423 print "not " unless $char =~ /\p{IsAlnum}/;
1424 print "ok $test\n"; $test++;
1425 print "not " if $char =~ /\P{IsAlnum}/;
1426 print "ok $test\n"; $test++;
1427 } else {
1428 print "not " if $char =~ /\p{IsAlnum}/;
1429 print "ok $test\n"; $test++;
1430 print "not " unless $char =~ /\P{IsAlnum}/;
1431 print "ok $test\n"; $test++;
1432 }
1433 print "# IsASCII\n";
1434 if (ord("A") == 193) {
1435 print "ok $test # Skip: in EBCDIC\n"; $test++;
1436 print "ok $test # Skip: in EBCDIC\n"; $test++;
1437 } else {
1438 if ($code le '00007f') {
1439 print "not " unless $char =~ /\p{IsASCII}/;
1440 print "ok $test\n"; $test++;
1441 print "not " if $char =~ /\P{IsASCII}/;
1442 print "ok $test\n"; $test++;
1443 } else {
1444 print "not " if $char =~ /\p{IsASCII}/;
1445 print "ok $test\n"; $test++;
1446 print "not " unless $char =~ /\P{IsASCII}/;
1447 print "ok $test\n"; $test++;
1448 }
1449 }
1450 print "# IsCntrl\n";
1451 if ($class =~ /^C/) {
1452 print "not " unless $char =~ /\p{IsCntrl}/;
1453 print "ok $test\n"; $test++;
1454 print "not " if $char =~ /\P{IsCntrl}/;
1455 print "ok $test\n"; $test++;
1456 } else {
1457 print "not " if $char =~ /\p{IsCntrl}/;
1458 print "ok $test\n"; $test++;
1459 print "not " unless $char =~ /\P{IsCntrl}/;
1460 print "ok $test\n"; $test++;
1461 }
1462 print "# IsBlank\n";
1463 if ($class =~ /^Z[lp]/ || $char eq " ") {
1464 print "not " unless $char =~ /\p{IsBlank}/;
1465 print "ok $test\n"; $test++;
1466 print "not " if $char =~ /\P{IsBlank}/;
1467 print "ok $test\n"; $test++;
1468 } else {
1469 print "not " if $char =~ /\p{IsBlank}/;
1470 print "ok $test\n"; $test++;
1471 print "not " unless $char =~ /\P{IsBlank}/;
1472 print "ok $test\n"; $test++;
1473 }
1474 print "# IsDigit\n";
1475 if ($class =~ /^Nd$/) {
1476 print "not " unless $char =~ /\p{IsDigit}/;
1477 print "ok $test\n"; $test++;
1478 print "not " if $char =~ /\P{IsDigit}/;
1479 print "ok $test\n"; $test++;
1480 } else {
1481 print "not " if $char =~ /\p{IsDigit}/;
1482 print "ok $test\n"; $test++;
1483 print "not " unless $char =~ /\P{IsDigit}/;
1484 print "ok $test\n"; $test++;
1485 }
1486 print "# IsGraph\n";
1487 if ($class =~ /^([LMNPS])|Co/) {
1488 print "not " unless $char =~ /\p{IsGraph}/;
1489 print "ok $test\n"; $test++;
1490 print "not " if $char =~ /\P{IsGraph}/;
1491 print "ok $test\n"; $test++;
1492 } else {
1493 print "not " if $char =~ /\p{IsGraph}/;
1494 print "ok $test\n"; $test++;
1495 print "not " unless $char =~ /\P{IsGraph}/;
1496 print "ok $test\n"; $test++;
1497 }
1498 print "# IsLower\n";
1499 if ($class =~ /^Ll$/) {
1500 print "not " unless $char =~ /\p{IsLower}/;
1501 print "ok $test\n"; $test++;
1502 print "not " if $char =~ /\P{IsLower}/;
1503 print "ok $test\n"; $test++;
1504 } else {
1505 print "not " if $char =~ /\p{IsLower}/;
1506 print "ok $test\n"; $test++;
1507 print "not " unless $char =~ /\P{IsLower}/;
1508 print "ok $test\n"; $test++;
1509 }
1510 print "# IsPrint\n";
1511 if ($class =~ /^([LMNPS])|Co|Zs/) {
1512 print "not " unless $char =~ /\p{IsPrint}/;
1513 print "ok $test\n"; $test++;
1514 print "not " if $char =~ /\P{IsPrint}/;
1515 print "ok $test\n"; $test++;
1516 } else {
1517 print "not " if $char =~ /\p{IsPrint}/;
1518 print "ok $test\n"; $test++;
1519 print "not " unless $char =~ /\P{IsPrint}/;
1520 print "ok $test\n"; $test++;
1521 }
1522 print "# IsPunct\n";
1523 if ($class =~ /^P/ || $char eq "_") {
1524 print "not " unless $char =~ /\p{IsPunct}/;
1525 print "ok $test\n"; $test++;
1526 print "not " if $char =~ /\P{IsPunct}/;
1527 print "ok $test\n"; $test++;
1528 } else {
1529 print "not " if $char =~ /\p{IsPunct}/;
1530 print "ok $test\n"; $test++;
1531 print "not " unless $char =~ /\P{IsPunct}/;
1532 print "ok $test\n"; $test++;
1533 }
1534 print "# IsSpace\n";
1535 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1536 print "not " unless $char =~ /\p{IsSpace}/;
1537 print "ok $test\n"; $test++;
1538 print "not " if $char =~ /\P{IsSpace}/;
1539 print "ok $test\n"; $test++;
1540 } else {
1541 print "not " if $char =~ /\p{IsSpace}/;
1542 print "ok $test\n"; $test++;
1543 print "not " unless $char =~ /\P{IsSpace}/;
1544 print "ok $test\n"; $test++;
1545 }
1546 print "# IsUpper\n";
1547 if ($class =~ /^L[ut]/) {
1548 print "not " unless $char =~ /\p{IsUpper}/;
1549 print "ok $test\n"; $test++;
1550 print "not " if $char =~ /\P{IsUpper}/;
1551 print "ok $test\n"; $test++;
1552 } else {
1553 print "not " if $char =~ /\p{IsUpper}/;
1554 print "ok $test\n"; $test++;
1555 print "not " unless $char =~ /\P{IsUpper}/;
1556 print "ok $test\n"; $test++;
1557 }
1558 print "# IsWord\n";
1559 if ($class =~ /^[LMN]/ || $char eq "_") {
1560 print "not " unless $char =~ /\p{IsWord}/;
1561 print "ok $test\n"; $test++;
1562 print "not " if $char =~ /\P{IsWord}/;
1563 print "ok $test\n"; $test++;
1564 } else {
1565 print "not " if $char =~ /\p{IsWord}/;
1566 print "ok $test\n"; $test++;
1567 print "not " unless $char =~ /\P{IsWord}/;
1568 print "ok $test\n"; $test++;
1569 }
1570 }
1571}
1572
1573{
1574 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1575
1576 if (/(.\x{300})./) {
1577 print "ok 576\n";
1578
1579 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1580 print "ok 577\n";
1581
1582 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1583 print "ok 578\n";
1584
1585 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1586 print "ok 579\n";
1587
1588 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1589 print "ok 580\n";
1590 } else {
1591 for (576..580) { print "not ok $_\n" }
1592 }
1593}
1594
1595{
1596 # bug id 20010306.008
1597
1598 $a = "a\x{1234}";
1599 # The original bug report had 'no utf8' here but that was irrelevant.
1600 $a =~ m/\w/; # used to core dump
1601
1602 print "ok 581\n";
1603}
1604
1605{
1606 $test = 582;
1607
1608 # bugid 20010410.006
1609 for my $rx (
1610 '/(.*?)\{(.*?)\}/csg',
1611 '/(.*?)\{(.*?)\}/cg',
1612 '/(.*?)\{(.*?)\}/sg',
1613 '/(.*?)\{(.*?)\}/g',
1614 '/(.+?)\{(.+?)\}/csg',
1615 )
1616 {
1617 my($input, $i);
1618
1619 $i = 0;
1620 $input = "a{b}c{d}";
1621 eval <<EOT;
1622 while (eval \$input =~ $rx) {
1623 print "# \\\$1 = '\$1' \\\$2 = '\$2'\n";
1624 ++\$i;
1625 }
1626EOT
1627 print "not " unless $i == 2;
1628 print "ok " . $test++ . "\n";
1629 }
1630}
1631
1632{
1633 # from Robin Houston
1634
1635 my $x = "\x{10FFFD}";
1636 $x =~ s/(.)/$1/g;
1637 print "not " unless ord($x) == 0x10FFFD && length($x) == 1;
1638 print "ok 587\n";
1639}
1640
1641{
1642 my $x = "\x7f";
1643
1644 print "not " if $x =~ /[\x80-\xff]/;
1645 print "ok 588\n";
1646
1647 print "not " if $x =~ /[\x80-\x{100}]/;
1648 print "ok 589\n";
1649
1650 print "not " if $x =~ /[\x{100}]/;
1651 print "ok 590\n";
1652
1653 print "not " if $x =~ /\p{InLatin1Supplement}/;
1654 print "ok 591\n";
1655
1656 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1657 print "ok 592\n";
1658
1659 print "not " if $x =~ /\p{InLatinExtendedA}/;
1660 print "ok 593\n";
1661
1662 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1663 print "ok 594\n";
1664}
1665
1666{
1667 my $x = "\x80";
1668
1669 print "not " unless $x =~ /[\x80-\xff]/;
1670 print "ok 595\n";
1671
1672 print "not " unless $x =~ /[\x80-\x{100}]/;
1673 print "ok 596\n";
1674
1675 print "not " if $x =~ /[\x{100}]/;
1676 print "ok 597\n";
1677
1678 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1679 print "ok 598\n";
1680
1681 print "not " if $x =~ /\P{InLatin1Supplement}/;
1682 print "ok 599\n";
1683
1684 print "not " if $x =~ /\p{InLatinExtendedA}/;
1685 print "ok 600\n";
1686
1687 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1688 print "ok 601\n";
1689}
1690
1691{
1692 my $x = "\xff";
1693
1694 print "not " unless $x =~ /[\x80-\xff]/;
1695 print "ok 602\n";
1696
1697 print "not " unless $x =~ /[\x80-\x{100}]/;
1698 print "ok 603\n";
1699
1700 print "not " if $x =~ /[\x{100}]/;
1701 print "ok 604\n";
1702
1703 # the next two tests must be ignored on EBCDIC
1704 print "not " unless $x =~ /\p{InLatin1Supplement}/ or ord("A") == 193;
1705 print "ok 605\n";
1706
1707 print "not " if $x =~ /\P{InLatin1Supplement}/ and ord("A") != 193;
1708 print "ok 606\n";
1709
1710 print "not " if $x =~ /\p{InLatinExtendedA}/;
1711 print "ok 607\n";
1712
1713 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1714 print "ok 608\n";
1715}
1716
1717{
1718 my $x = "\x{100}";
1719
1720 print "not " if $x =~ /[\x80-\xff]/;
1721 print "ok 609\n";
1722
1723 print "not " unless $x =~ /[\x80-\x{100}]/;
1724 print "ok 610\n";
1725
1726 print "not " unless $x =~ /[\x{100}]/;
1727 print "ok 611\n";
1728
1729 print "not " if $x =~ /\p{InLatin1Supplement}/;
1730 print "ok 612\n";
1731
1732 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1733 print "ok 613\n";
1734
1735 print "not " unless $x =~ /\p{InLatinExtendedA}/;
1736 print "ok 614\n";
1737
1738 print "not " if $x =~ /\P{InLatinExtendedA}/;
1739 print "ok 615\n";
1740}
1741
1742{
1743 # from japhy
1744 my $w;
1745 use warnings;
1746 local $SIG{__WARN__} = sub { $w .= shift };
1747
1748 $w = "";
1749 eval 'qr/(?c)/';
1750 print "not " if $w !~ /^Useless \(\?c\)/;
1751 print "ok 616\n";
1752
1753 $w = "";
1754 eval 'qr/(?-c)/';
1755 print "not " if $w !~ /^Useless \(\?-c\)/;
1756 print "ok 617\n";
1757
1758 $w = "";
1759 eval 'qr/(?g)/';
1760 print "not " if $w !~ /^Useless \(\?g\)/;
1761 print "ok 618\n";
1762
1763 $w = "";
1764 eval 'qr/(?-g)/';
1765 print "not " if $w !~ /^Useless \(\?-g\)/;
1766 print "ok 619\n";
1767
1768 $w = "";
1769 eval 'qr/(?o)/';
1770 print "not " if $w !~ /^Useless \(\?o\)/;
1771 print "ok 620\n";
1772
1773 $w = "";
1774 eval 'qr/(?-o)/';
1775 print "not " if $w !~ /^Useless \(\?-o\)/;
1776 print "ok 621\n";
1777
1778 # now test multi-error regexes
1779
1780 $w = "";
1781 eval 'qr/(?g-o)/';
1782 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-o\)/;
1783 print "ok 622\n";
1784
1785 $w = "";
1786 eval 'qr/(?g-c)/';
1787 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-c\)/;
1788 print "ok 623\n";
1789
1790 $w = "";
1791 eval 'qr/(?o-cg)/'; # (?c) means (?g) error won't be thrown
1792 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?-c\)/;
1793 print "ok 624\n";
1794
1795 $w = "";
1796 eval 'qr/(?ogc)/';
1797 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?g\).*\nUseless \(\?c\)/;
1798 print "ok 625\n";
1799}
1800
1801# More Unicode "class" tests
1802
1803{
1804 use charnames ':full';
1805
1806 print "not " unless "\N{LATIN CAPITAL LETTER A}" =~ /\p{InBasicLatin}/;
1807 print "ok 626\n";
1808
1809 print "not " unless "\N{LATIN CAPITAL LETTER A WITH GRAVE}" =~ /\p{InLatin1Supplement}/;
1810 print "ok 627\n";
1811
1812 print "not " unless "\N{LATIN CAPITAL LETTER A WITH MACRON}" =~ /\p{InLatinExtendedA}/;
1813 print "ok 628\n";
1814
1815 print "not " unless "\N{LATIN SMALL LETTER B WITH STROKE}" =~ /\p{InLatinExtendedB}/;
1816 print "ok 629\n";
1817
1818 print "not " unless "\N{KATAKANA LETTER SMALL A}" =~ /\p{InKatakana}/;
1819 print "ok 630\n";
1820}
1821
1822$_ = "foo";
1823
1824eval <<"EOT"; die if $@;
1825 /f
1826 o\r
1827 o
1828 \$
1829 /x && print "ok 631\n";
1830EOT
1831
1832eval <<"EOT"; die if $@;
1833 /f
1834 o
1835 o
1836 \$\r
1837 /x && print "ok 632\n";
1838EOT
1839
1840#test /o feature
1841sub test_o { $_[0] =~/$_[1]/o; return $1}
1842if(test_o('abc','(.)..') eq 'a') {
1843 print "ok 633\n";
1844} else {
1845 print "not ok 633\n";
1846}
1847if(test_o('abc','..(.)') eq 'a') {
1848 print "ok 634\n";
1849} else {
1850 print "not ok 634\n";
1851}
1852
1853# 635..639: ID 20010619.003 (only the space character is
1854# supposed to be [:print:], not the whole isprint()).
1855
1856print "not " if "\n" =~ /[[:print:]]/;
1857print "ok 635\n";
1858
1859print "not " if "\t" =~ /[[:print:]]/;
1860print "ok 636\n";
1861
1862# Amazingly vertical tabulator is the same in ASCII and EBCDIC.
1863print "not " if "\014" =~ /[[:print:]]/;
1864print "ok 637\n";
1865
1866print "not " if "\r" =~ /[[:print:]]/;
1867print "ok 638\n";
1868
1869print "not " unless " " =~ /[[:print:]]/;
1870print "ok 639\n";
1871
1872##
1873## Test basic $^N usage outside of a regex
1874##
1875$x = "abcdef";
1876$T="ok 640\n";if ($x =~ /cde/ and not defined $^N) {print $T} else {print "not $T"};
1877$T="ok 641\n";if ($x =~ /(cde)/ and $^N eq "cde") {print $T} else {print "not $T"};
1878$T="ok 642\n";if ($x =~ /(c)(d)(e)/ and $^N eq "e") {print $T} else {print "not $T"};
1879$T="ok 643\n";if ($x =~ /(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1880$T="ok 644\n";if ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1881$T="ok 645\n";if ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde") {print $T} else {print "not $T"};
1882$T="ok 646\n";if ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc") {print $T} else {print "not $T"};
1883$T="ok 647\n";if ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde") {print $T} else {print "not $T"};
1884$T="ok 648\n";if ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde") {print $T} else {print "not $T"};
1885$T="ok 649\n";if ($x =~ /(?:c(d)e)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1886$T="ok 650\n";if ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1887$T="ok 651\n";if ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1888$T="ok 652\n";if ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1889$T="ok 653\n";if ($x =~ /(([ace])|([bd]))*/ and $^N eq "e" ){print $T} else {print "not $T"};
1890{
1891 $T="ok 654\n";if($x =~ /(([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1892}
1893## test to see if $^N is automatically localized -- it should now
1894## have the value set in test 653
1895$T="ok 655\n";if ($^N eq "e" ){print $T} else {print "not $T"};
1896
1897##
1898## Now test inside (?{...})
1899##
1900$T="ok 656\n";if ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b" ){print $T} else {print "not $T"};
1901$T="ok 657\n";if ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1902$T="ok 658\n";if ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1903$T="ok 659\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc" and $z eq "abcd")
1904 {print $T} else {print "not $T"};
1905$T="ok 660\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc" and $z eq "abcde")
1906 {print $T} else {print "not $T"};
1907
1908# Test the Unicode script classes
1909
1910print "not " unless chr(0x100) =~ /\p{IsLatin}/; # outside Latin-1
1911print "ok 661\n";
1912
1913print "not " unless chr(0x212b) =~ /\p{IsLatin}/; # Angstrom sign, very outside
1914print "ok 662\n";
1915
1916print "not " unless chr(0x5d0) =~ /\p{IsHebrew}/; # inside InHebrew
1917print "ok 663\n";
1918
1919print "not " unless chr(0xfb4f) =~ /\p{IsHebrew}/; # outside InHebrew
1920print "ok 664\n";
1921
1922# # singleton (not in a range, this test must be ignored on EBCDIC)
1923# print "not " unless chr(0xb5) =~ /\p{IsGreek}/ or ord("A") == 193;
1924# print "ok 665\n";
1925print "ok 665 # 0xb5 moved from Greek to Common with Unicode 4.0.1\n";
1926
1927print "not " unless chr(0x37a) =~ /\p{IsGreek}/; # singleton
1928print "ok 666\n";
1929
1930print "not " unless chr(0x386) =~ /\p{IsGreek}/; # singleton
1931print "ok 667\n";
1932
1933print "not " unless chr(0x387) =~ /\P{IsGreek}/; # not there
1934print "ok 668\n";
1935
1936print "not " unless chr(0x388) =~ /\p{IsGreek}/; # range
1937print "ok 669\n";
1938
1939print "not " unless chr(0x38a) =~ /\p{IsGreek}/; # range
1940print "ok 670\n";
1941
1942print "not " unless chr(0x38b) =~ /\P{IsGreek}/; # not there
1943print "ok 671\n";
1944
1945print "not " unless chr(0x38c) =~ /\p{IsGreek}/; # singleton
1946print "ok 672\n";
1947
1948if (ord("A") == 65) {
1949##
1950## Test [:cntrl:]...
1951##
1952## Should probably put in tests for all the POSIX stuff, but not sure how to
1953## guarantee a specific locale......
1954##
1955 $AllBytes = join('', map { chr($_) } 0..255);
1956 ($x = $AllBytes) =~ s/[[:cntrl:]]//g;
1957 if ($x ne join('', map { chr($_) } 0x20..0x7E, 0x80..0xFF)) {
1958 print "not ";
1959 }
1960 print "ok 673\n";
1961
1962 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1963 if ($x ne join('', map { chr($_) } 0..0x1F, 0x7F)) { print "not " }
1964 print "ok 674\n";
1965} else {
1966 print "ok $_ # Skip: EBCDIC\n" for 673..674;
1967}
1968
1969# With /s modifier UTF8 chars were interpreted as bytes
1970{
1971 my $a = "Hello \x{263A} World";
1972
1973 my @a = ($a =~ /./gs);
1974
1975 print "not " unless $#a == 12;
1976 print "ok 675\n";
1977}
1978
1979@a = ("foo\nbar" =~ /./g);
1980print "ok 676\n" if @a == 6 && "@a" eq "f o o b a r";
1981
1982@a = ("foo\nbar" =~ /./gs);
1983print "ok 677\n" if @a == 7 && "@a" eq "f o o \n b a r";
1984
1985@a = ("foo\nbar" =~ /\C/g);
1986print "ok 678\n" if @a == 7 && "@a" eq "f o o \n b a r";
1987
1988@a = ("foo\nbar" =~ /\C/gs);
1989print "ok 679\n" if @a == 7 && "@a" eq "f o o \n b a r";
1990
1991@a = ("foo\n\x{100}bar" =~ /./g);
1992print "ok 680\n" if @a == 7 && "@a" eq "f o o \x{100} b a r";
1993
1994@a = ("foo\n\x{100}bar" =~ /./gs);
1995print "ok 681\n" if @a == 8 && "@a" eq "f o o \n \x{100} b a r";
1996
1997($a, $b) = map { chr } ord('A') == 65 ? (0xc4, 0x80) : (0x8c, 0x41);
1998
1999@a = ("foo\n\x{100}bar" =~ /\C/g);
2000print "ok 682\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
2001
2002@a = ("foo\n\x{100}bar" =~ /\C/gs);
2003print "ok 683\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
2004
2005{
2006 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
2007 $_ = "ababacadaea";
2008 $a = join ":", /b./gc;
2009 $b = join ":", /a./gc;
2010 $c = pos;
2011 print "$a $b $c" eq 'ba:ba ad:ae 10' ? "ok 684\n" : "not ok 684\t# $a $b $c\n";
2012}
2013
2014{
2015 # [ID 20010407.006] matching utf8 return values from functions does not work
2016
2017 package ID_20010407_006;
2018
2019 sub x {
2020 "a\x{1234}";
2021 }
2022
2023 my $x = x;
2024 my $y;
2025
2026 $x =~ /(..)/; $y = $1;
2027 print "not " unless length($y) == 2 && $y eq $x;
2028 print "ok 685\n";
2029
2030 x =~ /(..)/; $y = $1;
2031 print "not " unless length($y) == 2 && $y eq $x;
2032 print "ok 686\n";
2033}
2034
2035
2036my $test = 687;
2037
2038# Force scalar context on the patern match
2039sub ok ($$) {
2040 my($ok, $name) = @_;
2041
2042 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test, $name;
2043
2044 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
2045
2046 $test++;
2047 return $ok;
2048}
2049
2050{
2051 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
2052 $x = "\x4e" . "E";
2053 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
2054
2055 $x = "\x4e" . "i";
2056 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
2057
2058 $x = "\x4" . "j";
2059 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
2060
2061 $x = "\x0" . "k";
2062 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
2063
2064 $x = "\x0" . "x";
2065 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
2066
2067 $x = "\x0" . "xa";
2068 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
2069
2070 $x = "\x9" . "_b";
2071 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
2072
2073 print "# and now again in [] ranges\n";
2074
2075 $x = "\x4e" . "E";
2076 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
2077
2078 $x = "\x4e" . "i";
2079 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
2080
2081 $x = "\x4" . "j";
2082 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
2083
2084 $x = "\x0" . "k";
2085 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
2086
2087 $x = "\x0" . "x";
2088 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
2089
2090 $x = "\x0" . "xa";
2091 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
2092
2093 $x = "\x9" . "_b";
2094 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
2095
2096}
2097
2098{
2099 # Check that \x{##} works. 5.6.1 fails quite a few of these.
2100
2101 $x = "\x9b";
2102 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
2103
2104 $x = "\x9b" . "y";
2105 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
2106
2107 $x = "\x9b" . "y";
2108 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
2109
2110 $x = "\x9b" . "y";
2111 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
2112
2113 $x = "\x0" . "y";
2114 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
2115
2116 $x = "\x0" . "y";
2117 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
2118
2119 $x = "\x9b" . "y";
2120 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
2121
2122 print "# and now again in [] ranges\n";
2123
2124 $x = "\x9b";
2125 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
2126
2127 $x = "\x9b" . "y";
2128 ok ($x =~ /^[\x{9_b}y]{2}$/, "\\x{9_b} is to be treated as \\x9b (again)");
2129
2130 $x = "\x9b" . "y";
2131 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
2132
2133 $x = "\x9b" . "y";
2134 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
2135
2136 $x = "\x0" . "y";
2137 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
2138
2139 $x = "\x0" . "y";
2140 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
2141
2142 $x = "\x9b" . "y";
2143 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
2144}
2145
2146{
2147 # high bit bug -- japhy
2148 my $x = "ab\200d";
2149 $x =~ /.*?\200/ or print "not ";
2150 print "ok 715\n";
2151}
2152
2153print "# some Unicode properties\n";
2154
2155{
2156 # Dashes, underbars, case.
2157 print "not " unless "\x80" =~ /\p{in-latin1_SUPPLEMENT}/;
2158 print "ok 716\n";
2159
2160 # Complement, leading and trailing whitespace.
2161 print "not " unless "\x80" =~ /\P{ ^ In Latin 1 Supplement }/;
2162 print "ok 717\n";
2163
2164 # No ^In, dashes, case, dash, any intervening (word-break) whitespace.
2165 # (well, newlines don't work...)
2166 print "not " unless "\x80" =~ /\p{latin-1 supplement}/;
2167 print "ok 718\n";
2168}
2169
2170{
2171 print "not " unless "a" =~ /\pL/;
2172 print "ok 719\n";
2173
2174 print "not " unless "a" =~ /\p{IsLl}/;
2175 print "ok 720\n";
2176
2177 print "not " if "a" =~ /\p{IsLu}/;
2178 print "ok 721\n";
2179
2180 print "not " unless "a" =~ /\p{Ll}/;
2181 print "ok 722\n";
2182
2183 print "not " if "a" =~ /\p{Lu}/;
2184 print "ok 723\n";
2185
2186 print "not " unless "A" =~ /\pL/;
2187 print "ok 724\n";
2188
2189 print "not " unless "A" =~ /\p{IsLu}/;
2190 print "ok 725\n";
2191
2192 print "not " if "A" =~ /\p{IsLl}/;
2193 print "ok 726\n";
2194
2195 print "not " unless "A" =~ /\p{Lu}/;
2196 print "ok 727\n";
2197
2198 print "not " if "A" =~ /\p{Ll}/;
2199 print "ok 728\n";
2200
2201 print "not " if "a" =~ /\PL/;
2202 print "ok 729\n";
2203
2204 print "not " if "a" =~ /\P{IsLl}/;
2205 print "ok 730\n";
2206
2207 print "not " unless "a" =~ /\P{IsLu}/;
2208 print "ok 731\n";
2209
2210 print "not " if "a" =~ /\P{Ll}/;
2211 print "ok 732\n";
2212
2213 print "not " unless "a" =~ /\P{Lu}/;
2214 print "ok 733\n";
2215
2216 print "not " if "A" =~ /\PL/;
2217 print "ok 734\n";
2218
2219 print "not " if "A" =~ /\P{IsLu}/;
2220 print "ok 735\n";
2221
2222 print "not " unless "A" =~ /\P{IsLl}/;
2223 print "ok 736\n";
2224
2225 print "not " if "A" =~ /\P{Lu}/;
2226 print "ok 737\n";
2227
2228 print "not " unless "A" =~ /\P{Ll}/;
2229 print "ok 738\n";
2230
2231}
2232
2233{
2234 print "not " if "a" =~ /\p{Common}/;
2235 print "ok 739\n";
2236
2237 print "not " unless "1" =~ /\p{Common}/;
2238 print "ok 740\n";
2239}
2240
2241{
2242 print "not " if "a" =~ /\p{Inherited}/;
2243 print "ok 741\n";
2244
2245 print "not " unless "\x{300}" =~ /\p{Inherited}/;
2246 print "ok 742\n";
2247}
2248
2249{
2250 # L& and LC are the same
2251 print "not " unless "a" =~ /\p{LC}/ and "a" =~ /\p{L&}/;
2252 print "ok 743\n";
2253
2254 print "not " if "1" =~ /\p{LC}/ or "1" =~ /\p{L&}/;
2255 print "ok 744\n";
2256}
2257
2258{
2259 print "not " unless "a" =~ /\p{Lowercase Letter}/;
2260 print "ok 745\n";
2261
2262 print "not " if "A" =~ /\p{lowercaseletter}/;
2263 print "ok 746\n";
2264}
2265
2266{
2267 print "not " unless "\x{AC00}" =~ /\p{HangulSyllables}/;
2268 print "ok 747\n";
2269}
2270
2271{
2272 # Script=, Block=, Category=
2273
2274 print "not " unless "\x{0100}" =~ /\p{Script=Latin}/;
2275 print "ok 748\n";
2276
2277 print "not " unless "\x{0100}" =~ /\p{Block=LatinExtendedA}/;
2278 print "ok 749\n";
2279
2280 print "not " unless "\x{0100}" =~ /\p{Category=UppercaseLetter}/;
2281 print "ok 750\n";
2282}
2283
2284{
2285 print "# the basic character classes and Unicode \n";
2286
2287 # 0100;LATIN CAPITAL LETTER A WITH MACRON;Lu;0;L;0041 0304;;;;N;LATIN CAPITAL LETTER A MACRON;;;0101;
2288 print "not " unless "\x{0100}" =~ /\w/;
2289 print "ok 751\n";
2290
2291 # 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;;
2292 print "not " unless "\x{0660}" =~ /\d/;
2293 print "ok 752\n";
2294
2295 # 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
2296 print "not " unless "\x{1680}" =~ /\s/;
2297 print "ok 753\n";
2298}
2299
2300{
2301 print "# folding matches and Unicode\n";
2302
2303 print "not " unless "a\x{100}" =~ /A/i;
2304 print "ok 754\n";
2305
2306 print "not " unless "A\x{100}" =~ /a/i;
2307 print "ok 755\n";
2308
2309 print "not " unless "a\x{100}" =~ /a/i;
2310 print "ok 756\n";
2311
2312 print "not " unless "A\x{100}" =~ /A/i;
2313 print "ok 757\n";
2314
2315 print "not " unless "\x{101}a" =~ /\x{100}/i;
2316 print "ok 758\n";
2317
2318 print "not " unless "\x{100}a" =~ /\x{100}/i;
2319 print "ok 759\n";
2320
2321 print "not " unless "\x{101}a" =~ /\x{101}/i;
2322 print "ok 760\n";
2323
2324 print "not " unless "\x{100}a" =~ /\x{101}/i;
2325 print "ok 761\n";
2326
2327 print "not " unless "a\x{100}" =~ /A\x{100}/i;
2328 print "ok 762\n";
2329
2330 print "not " unless "A\x{100}" =~ /a\x{100}/i;
2331 print "ok 763\n";
2332
2333 print "not " unless "a\x{100}" =~ /a\x{100}/i;
2334 print "ok 764\n";
2335
2336 print "not " unless "A\x{100}" =~ /A\x{100}/i;
2337 print "ok 765\n";
2338
2339 print "not " unless "a\x{100}" =~ /[A]/i;
2340 print "ok 766\n";
2341
2342 print "not " unless "A\x{100}" =~ /[a]/i;
2343 print "ok 767\n";
2344
2345 print "not " unless "a\x{100}" =~ /[a]/i;
2346 print "ok 768\n";
2347
2348 print "not " unless "A\x{100}" =~ /[A]/i;
2349 print "ok 769\n";
2350
2351 print "not " unless "\x{101}a" =~ /[\x{100}]/i;
2352 print "ok 770\n";
2353
2354 print "not " unless "\x{100}a" =~ /[\x{100}]/i;
2355 print "ok 771\n";
2356
2357 print "not " unless "\x{101}a" =~ /[\x{101}]/i;
2358 print "ok 772\n";
2359
2360 print "not " unless "\x{100}a" =~ /[\x{101}]/i;
2361 print "ok 773\n";
2362
2363}
2364
2365{
2366 use charnames ':full';
2367
2368 print "# LATIN LETTER A WITH GRAVE\n";
2369 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
2370 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
2371
2372 print $lower =~ m/$UPPER/i ? "ok 774\n" : "not ok 774\n";
2373 print $UPPER =~ m/$lower/i ? "ok 775\n" : "not ok 775\n";
2374 print $lower =~ m/[$UPPER]/i ? "ok 776\n" : "not ok 776\n";
2375 print $UPPER =~ m/[$lower]/i ? "ok 777\n" : "not ok 777\n";
2376
2377 print "# GREEK LETTER ALPHA WITH VRACHY\n";
2378
2379 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
2380 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
2381
2382 print $lower =~ m/$UPPER/i ? "ok 778\n" : "not ok 778\n";
2383 print $UPPER =~ m/$lower/i ? "ok 779\n" : "not ok 779\n";
2384 print $lower =~ m/[$UPPER]/i ? "ok 780\n" : "not ok 780\n";
2385 print $UPPER =~ m/[$lower]/i ? "ok 781\n" : "not ok 781\n";
2386
2387 print "# LATIN LETTER Y WITH DIAERESIS\n";
2388
2389 $lower = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
2390 $UPPER = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
2391 print $lower =~ m/$UPPER/i ? "ok 782\n" : "not ok 782\n";
2392 print $UPPER =~ m/$lower/i ? "ok 783\n" : "not ok 783\n";
2393 print $lower =~ m/[$UPPER]/i ? "ok 784\n" : "not ok 784\n";
2394 print $UPPER =~ m/[$lower]/i ? "ok 785\n" : "not ok 785\n";
2395}
2396
2397{
2398 use warnings;
2399 use charnames ':full';
2400
2401 print "# GREEK CAPITAL LETTER SIGMA vs COMBINING GREEK PERISPOMENI\n";
2402
2403 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
2404 my $char = "\N{COMBINING GREEK PERISPOMENI}";
2405
2406 # Before #13843 this was failing by matching falsely.
2407 print "_:$char:_" =~ m/_:$SIGMA:_/i ? "not ok 786\n" : "ok 786\n";
2408}
2409
2410{
2411 print "# \\X\n";
2412
2413 use charnames ':full';
2414
2415 print "a!" =~ /^(\X)!/ && $1 eq "a" ?
2416 "ok 787\n" : "not ok 787 # $1\n";
2417 print "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF" ?
2418 "ok 788\n" : "not ok 788 # $1\n";
2419 print "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}" ?
2420 "ok 789\n" : "not ok 789 # $1\n";
2421 print "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}" ?
2422 "ok 790\n" : "not ok 790 # $1\n";
2423 print "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
2424 $1 eq "\N{LATIN CAPITAL LETTER E}" ?
2425 "ok 791\n" : "not ok 791 # $1\n";
2426 print "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!" =~
2427 /^(\X)!/ &&
2428 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}" ?
2429 "ok 792\n" : "not ok 792 # $1\n";
2430}
2431
2432{
2433 print "#\\C and \\X\n";
2434
2435 print "!abc!" =~ /a\Cc/ ? "ok 793\n" : "not ok 793\n";
2436 print "!abc!" =~ /a\Xc/ ? "ok 794\n" : "not ok 794\n";
2437}
2438
2439{
2440 print "# FINAL SIGMA\n";
2441
2442 my $SIGMA = "\x{03A3}"; # CAPITAL
2443 my $Sigma = "\x{03C2}"; # SMALL FINAL
2444 my $sigma = "\x{03C3}"; # SMALL
2445
2446 print $SIGMA =~ /$SIGMA/i ? "ok 795\n" : "not ok 795\n";
2447 print $SIGMA =~ /$Sigma/i ? "ok 796\n" : "not ok 796\n";
2448 print $SIGMA =~ /$sigma/i ? "ok 797\n" : "not ok 797\n";
2449
2450 print $Sigma =~ /$SIGMA/i ? "ok 798\n" : "not ok 798\n";
2451 print $Sigma =~ /$Sigma/i ? "ok 799\n" : "not ok 799\n";
2452 print $Sigma =~ /$sigma/i ? "ok 800\n" : "not ok 800\n";
2453
2454 print $sigma =~ /$SIGMA/i ? "ok 801\n" : "not ok 801\n";
2455 print $sigma =~ /$Sigma/i ? "ok 802\n" : "not ok 802\n";
2456 print $sigma =~ /$sigma/i ? "ok 803\n" : "not ok 803\n";
2457
2458 print $SIGMA =~ /[$SIGMA]/i ? "ok 804\n" : "not ok 804\n";
2459 print $SIGMA =~ /[$Sigma]/i ? "ok 805\n" : "not ok 805\n";
2460 print $SIGMA =~ /[$sigma]/i ? "ok 806\n" : "not ok 806\n";
2461
2462 print $Sigma =~ /[$SIGMA]/i ? "ok 807\n" : "not ok 807\n";
2463 print $Sigma =~ /[$Sigma]/i ? "ok 808\n" : "not ok 808\n";
2464 print $Sigma =~ /[$sigma]/i ? "ok 809\n" : "not ok 809\n";
2465
2466 print $sigma =~ /[$SIGMA]/i ? "ok 810\n" : "not ok 810\n";
2467 print $sigma =~ /[$Sigma]/i ? "ok 811\n" : "not ok 811\n";
2468 print $sigma =~ /[$sigma]/i ? "ok 812\n" : "not ok 812\n";
2469}
2470
2471{
2472 print "# parlez-vous?\n";
2473
2474 use charnames ':full';
2475
2476 print "fran\N{LATIN SMALL LETTER C}ais" =~
2477 /fran.ais/ &&
2478 $& eq "francais" ?
2479 "ok 813\n" : "not ok 813\n";
2480
2481 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2482 /fran.ais/ &&
2483 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2484 "ok 814\n" : "not ok 814\n";
2485
2486 print "fran\N{LATIN SMALL LETTER C}ais" =~
2487 /fran\Cais/ &&
2488 $& eq "francais" ?
2489 "ok 815\n" : "not ok 815\n";
2490
2491 print "franc\N{COMBINING CEDILLA}ais" =~
2492 /franc\C\Cais/ ? # COMBINING CEDILLA is two bytes when encoded
2493 "ok 816\n" : "not ok 816\n";
2494
2495 print "fran\N{LATIN SMALL LETTER C}ais" =~
2496 /fran\Xais/ &&
2497 $& eq "francais" ?
2498 "ok 817\n" : "not ok 817\n";
2499
2500 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2501 /fran\Xais/ &&
2502 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2503 "ok 818\n" : "not ok 818\n";
2504
2505 print "franc\N{COMBINING CEDILLA}ais" =~
2506 /fran\Xais/ &&
2507 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2508 "ok 819\n" : "not ok 819\n";
2509
2510 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2511 /fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
2512 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2513 "ok 820\n" : "not ok 820\n";
2514
2515 print "franc\N{COMBINING CEDILLA}ais" =~
2516 /franc\N{COMBINING CEDILLA}ais/ &&
2517 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2518 "ok 821\n" : "not ok 821\n";
2519
2520 print "fran\N{LATIN SMALL LETTER C}ais" =~
2521 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2522 $& eq "francais" ?
2523 "ok 822\n" : "not ok 822\n";
2524
2525 print "fran\N{LATIN SMALL LETTER C}ais" =~
2526 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2527 $& eq "francais" ?
2528 "ok 823\n" : "not ok 823\n";
2529
2530 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2531 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2532 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2533 "ok 824\n" : "not ok 824\n";
2534
2535 print "franc\N{COMBINING CEDILLA}ais" =~
2536 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2537 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2538 "ok 825\n" : "not ok 825\n";
2539}
2540
2541{
2542 print "# Does lingering (and useless) UTF8 flag mess up /i matching?\n";
2543
2544 {
2545 my $regex = "ABcde";
2546 my $string = "abcDE\x{100}";
2547 chop($string);
2548 if ($string =~ m/$regex/i) {
2549 print "ok 826\n";
2550 } else {
2551 print "not ok 826\n";
2552 }
2553 }
2554
2555 {
2556 my $regex = "ABcde\x{100}";
2557 my $string = "abcDE";
2558 chop($regex);
2559 if ($string =~ m/$regex/i) {
2560 print "ok 827\n";
2561 } else {
2562 print "not ok 827\n";
2563 }
2564 }
2565
2566 {
2567 my $regex = "ABcde\x{100}";
2568 my $string = "abcDE\x{100}";
2569 chop($regex);
2570 chop($string);
2571 if ($string =~ m/$regex/i) {
2572 print "ok 828\n";
2573 } else {
2574 print "not ok 828\n";
2575 }
2576 }
2577}
2578
2579{
2580 print "# more SIGMAs\n";
2581
2582 my $SIGMA = "\x{03A3}"; # CAPITAL
2583 my $Sigma = "\x{03C2}"; # SMALL FINAL
2584 my $sigma = "\x{03C3}"; # SMALL
2585
2586 my $S3 = "$SIGMA$Sigma$sigma";
2587
2588 print ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma ?
2589 "ok 829\n" : "not ok 829\n";
2590 print ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2591 "ok 830\n" : "not ok 830\n";
2592 print ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2593 "ok 831\n" : "not ok 831\n";
2594
2595 print ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma ?
2596 "ok 832\n" : "not ok 832\n";
2597 print ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2598 "ok 833\n" : "not ok 833\n";
2599 print ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2600 "ok 834\n" : "not ok 834\n";
2601}
2602
2603{
2604 print "# LATIN SMALL LETTER SHARP S\n";
2605
2606 use charnames ':full';
2607
2608 print "\N{LATIN SMALL LETTER SHARP S}" =~
2609 /\N{LATIN SMALL LETTER SHARP S}/ ? "ok 835\n" : "not ok 835\n";
2610
2611 print "\N{LATIN SMALL LETTER SHARP S}" =~
2612 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 836\n" : "not ok 836\n";
2613
2614 print "\N{LATIN SMALL LETTER SHARP S}" =~
2615 /[\N{LATIN SMALL LETTER SHARP S}]/ ? "ok 837\n" : "not ok 837\n";
2616
2617 print "\N{LATIN SMALL LETTER SHARP S}" =~
2618 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 838\n" : "not ok 838\n";
2619
2620 print "ss" =~
2621 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 839\n" : "not ok 839\n";
2622
2623 print "SS" =~
2624 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 840\n" : "not ok 840\n";
2625
2626 print "ss" =~
2627 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 841\n" : "not ok 841\n";
2628
2629 print "SS" =~
2630 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 842\n" : "not ok 842\n";
2631
2632 print "\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i ?
2633 "ok 843\n" : "not ok 843\n";
2634
2635 print "\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i ?
2636 "ok 844\n" : "not ok 844\n";
2637}
2638
2639{
2640 print "# more whitespace: U+0085, U+2028, U+2029\n";
2641
2642 # U+0085 needs to be forced to be Unicode, the \x{100} does that.
2643 print "<\x{100}\x{0085}>" =~ /<\x{100}\s>/ ? "ok 845\n" : "not ok 845\n";
2644 print "<\x{2028}>" =~ /<\s>/ ? "ok 846\n" : "not ok 846\n";
2645 print "<\x{2029}>" =~ /<\s>/ ? "ok 847\n" : "not ok 847\n";
2646}
2647
2648{
2649 print "# . with /s should work on characters, as opposed to bytes\n";
2650
2651 my $s = "\x{e4}\x{100}";
2652
2653 # This is not expected to match: the point is that
2654 # neither should we get "Malformed UTF-8" warnings.
2655 print $s =~ /\G(.+?)\n/gcs ?
2656 "not ok 848\n" : "ok 848\n";
2657
2658 my @c;
2659
2660 while ($s =~ /\G(.)/gs) {
2661 push @c, $1;
2662 }
2663
2664 print join("", @c) eq $s ? "ok 849\n" : "not ok 849\n";
2665
2666 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}"; # test only chars < 256
2667 my $r1 = "";
2668 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2669 $r1 .= $1 . $2;
2670 }
2671
2672 my $t2 = $t1 . "\x{100}"; # repeat with a larger char
2673 my $r2 = "";
2674 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2675 $r2 .= $1 . $2;
2676 }
2677 $r2 =~ s/\x{100}//;
2678 print $r1 eq $r2 ? "ok 850\n" : "not ok 850\n";
2679}
2680
2681{
2682 print "# Unicode lookbehind\n";
2683
2684 print "A\x{100}B" =~ /(?<=A.)B/ ? "ok 851\n" : "not ok 851\n";
2685 print "A\x{200}\x{300}B" =~ /(?<=A..)B/ ? "ok 852\n" : "not ok 852\n";
2686 print "\x{400}AB" =~ /(?<=\x{400}.)B/ ? "ok 853\n" : "not ok 853\n";
2687 print "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/ ? "ok 854\n" : "not ok 854\n";
2688}
2689
2690{
2691 print "# UTF-8 hash keys and /\$/\n";
2692 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-01/msg01327.html
2693
2694 my $u = "a\x{100}";
2695 my $v = substr($u,0,1);
2696 my $w = substr($u,1,1);
2697 my %u = ( $u => $u, $v => $v, $w => $w );
2698 my $i = 855;
2699 for (keys %u) {
2700 my $m1 = /^\w*$/ ? 1 : 0;
2701 my $m2 = $u{$_}=~/^\w*$/ ? 1 : 0;
2702 print $m1 == $m2 ? "ok $i\n" : "not ok $i # $m1 $m2\n";
2703 $i++;
2704 }
2705}
2706
2707{
2708 print "# [ID 20020124.005]\n";
2709 # Fixed by #14795.
2710 my $i = 858;
2711 for my $char ("a", "\x{df}", "\x{100}"){
2712 $x = "$char b $char";
2713 $x =~ s{($char)}{
2714 "c" =~ /c/;
2715 "x";
2716 }ge;
2717 print substr($x,0,1) eq substr($x,-1,1) ?
2718 "ok $i\n" : "not ok $i # debug: $x\n";
2719 $i++;
2720 }
2721}
2722
2723{
2724 print "# SEGV in s/// and UTF-8\n";
2725 $s = "s#\x{100}" x 4;
2726 $s =~ s/[^\w]/ /g;
2727 print $s eq "s \x{100}" x 4 ? "ok 861\n" : "not ok 861\n";
2728}
2729
2730{
2731 print "# UTF-8 bug (maybe alreayd known?)\n";
2732 my $u;
2733
2734 $u = "foo";
2735 $u =~ s/./\x{100}/g;
2736 print $u eq "\x{100}\x{100}\x{100}" ? "ok 862\n" : "not ok 862\n";
2737
2738 $u = "foobar";
2739 $u =~ s/[ao]/\x{100}/g;
2740 print $u eq "f\x{100}\x{100}b\x{100}r" ? "ok 863\n" : "not ok 863\n";
2741
2742 $u =~ s/\x{100}/e/g;
2743 print $u eq "feeber" ? "ok 864\n" : "not ok 864\n";
2744}
2745
2746{
2747 print "# UTF-8 bug with s///\n";
2748 # check utf8/non-utf8 mixtures
2749 # try to force all float/anchored check combinations
2750 my $c = "\x{100}";
2751 my $test = 865;
2752 my $subst;
2753 for my $re (
2754 "xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x", "xx.*(?=$c)", "(?=$c).*xx",
2755 ) {
2756 print "xxx" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2757 ++$test;
2758 print +($subst = "xxx") =~ s/$re// ? "not ok $test\n" : "ok $test\n";
2759 ++$test;
2760 }
2761 for my $re ("xx.*$c*", "$c*.*xx") {
2762 print "xxx" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2763 ++$test;
2764 ($subst = "xxx") =~ s/$re//;
2765 print $subst eq '' ? "ok $test\n" : "not ok $test\t# $subst\n";
2766 ++$test;
2767 }
2768 for my $re ("xxy*", "y*xx") {
2769 print "xx$c" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2770 ++$test;
2771 ($subst = "xx$c") =~ s/$re//;
2772 print $subst eq $c ? "ok $test\n" : "not ok $test\n";
2773 ++$test;
2774 print "xy$c" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2775 ++$test;
2776 print +($subst = "xy$c") =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2777 ++$test;
2778 }
2779 for my $re ("xy$c*z", "x$c*yz") {
2780 print "xyz" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2781 ++$test;
2782 ($subst = "xyz") =~ s/$re//;
2783 print $subst eq '' ? "ok $test\n" : "not ok $test\n";
2784 ++$test;
2785 }
2786}
2787
2788{
2789 print "# qr/.../x\n";
2790 my $test = 893;
2791
2792 my $R = qr/ A B C # D E/x;
2793
2794 print eval {"ABCDE" =~ $R} ? "ok $test\n" : "not ok $test\n";
2795 $test++;
2796
2797 print eval {"ABCDE" =~ m/$R/} ? "ok $test\n" : "not ok $test\n";
2798 $test++;
2799
2800 print eval {"ABCDE" =~ m/($R)/} ? "ok $test\n" : "not ok $test\n";
2801 $test++;
2802}
2803
2804{
2805 print "# illegal Unicode properties\n";
2806 my $test = 896;
2807
2808 print eval { "a" =~ /\pq / } ? "not ok $test\n" : "ok $test\n";
2809 $test++;
2810
2811 print eval { "a" =~ /\p{qrst} / } ? "not ok $test\n" : "ok $test\n";
2812 $test++;
2813}
2814
2815{
2816 print "# [ID 20020412.005] wrong pmop flags checked when empty pattern\n";
2817 # requires reuse of last successful pattern
2818 my $test = 898;
2819 $test =~ /\d/;
2820 for (0 .. 1) {
2821 my $match = ?? + 0;
2822 if ($match != $_) {
2823 print "ok $test\n";
2824 } else {
2825 printf "not ok %s\t# 'match once' %s on %s iteration\n", $test,
2826 $match ? 'succeeded' : 'failed', $_ ? 'second' : 'first';
2827 }
2828 ++$test;
2829 }
2830 $test =~ /(\d)/;
2831 my $result = join '', $test =~ //g;
2832 if ($result eq $test) {
2833 print "ok $test\n";
2834 } else {
2835 printf "not ok %s\t# expected '%s', got '%s'\n", $test, $test, $result;
2836 }
2837 ++$test;
2838}
2839
2840print "# user-defined character properties\n";
2841
2842sub InKana1 {
2843 return <<'END';
28443040 309F
284530A0 30FF
2846END
2847}
2848
2849sub InKana2 {
2850 return <<'END';
2851+utf8::InHiragana
2852+utf8::InKatakana
2853END
2854}
2855
2856sub InKana3 {
2857 return <<'END';
2858+utf8::InHiragana
2859+utf8::InKatakana
2860-utf8::IsCn
2861END
2862}
2863
2864sub InNotKana {
2865 return <<'END';
2866!utf8::InHiragana
2867-utf8::InKatakana
2868+utf8::IsCn
2869END
2870}
2871
2872$test = 901;
2873
2874print "\x{3040}" =~ /\p{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2875print "\x{303F}" =~ /\P{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2876
2877print "\x{3040}" =~ /\p{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2878print "\x{303F}" =~ /\P{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2879
2880print "\x{3041}" =~ /\p{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2881print "\x{3040}" =~ /\P{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2882
2883print "\x{3040}" =~ /\p{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2884print "\x{3041}" =~ /\P{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2885
2886sub InConsonant { # Not EBCDIC-aware.
2887 return <<EOF;
28880061 007f
2889-0061
2890-0065
2891-0069
2892-006f
2893-0075
2894EOF
2895}
2896
2897print "d" =~ /\p{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2898print "e" =~ /\P{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2899
2900{
2901 print "# [ID 20020630.002] utf8 regex only matches 32k\n";
2902 $test = 911;
2903 for ([ 'byte', "\x{ff}" ], [ 'utf8', "\x{1ff}" ]) {
2904 my($type, $char) = @$_;
2905 for my $len (32000, 32768, 33000) {
2906 my $s = $char . "f" x $len;
2907 my $r = $s =~ /$char([f]*)/gc;
2908 print $r ? "ok $test\n" : "not ok $test\t# <$type x $len> fail\n";
2909 ++$test;
2910 print +(!$r or pos($s) == $len + 1) ? "ok $test\n"
2911 : "not ok $test\t# <$type x $len> pos @{[ pos($s) ]}\n";
2912 ++$test;
2913 }
2914 }
2915}
2916
2917$test = 923;
2918
2919$a = bless qr/foo/, 'Foo';
2920print(('goodfood' =~ $a ? '' : 'not '),
2921 "ok $test\t# reblessed qr// matches\n");
2922++$test;
2923
2924print(($a eq '(?-xism:foo)' ? '' : 'not '),
2925 "ok $test\t# reblessed qr// stringizes\n");
2926++$test;
2927
2928$x = "\x{3fe}";
2929$z=$y = "\317\276"; # $y is byte representation of $x
2930
2931$a = qr/$x/;
2932print(($x =~ $a ? '' : 'not '), "ok $test - utf8 interpolation in qr//\n");
2933++$test;
2934
2935print(("a$a" =~ $x ? '' : 'not '),
2936 "ok $test - stringifed qr// preserves utf8\n");
2937++$test;
2938
2939print(("a$x" =~ /^a$a\z/ ? '' : 'not '),
2940 "ok $test - interpolated qr// preserves utf8\n");
2941++$test;
2942
2943print(("a$x" =~ /^a(??{$a})\z/ ? '' : 'not '),
2944 "ok $test - postponed interpolation of qr// preserves utf8\n");
2945++$test;
2946
2947print((length(qr/##/x) == 12 ? '' : 'not '),
2948 "ok $test - ## in qr// doesn't corrupt memory [perl #17776]\n");
2949++$test;
2950
2951{ use re 'eval';
2952
2953print(("$x$x" =~ /^$x(??{$x})\z/ ? '' : 'not '),
2954 "ok $test - postponed utf8 string in utf8 re matches utf8\n");
2955++$test;
2956
2957print(("$y$x" =~ /^$y(??{$x})\z/ ? '' : 'not '),
2958 "ok $test - postponed utf8 string in non-utf8 re matches utf8\n");
2959++$test;
2960
2961print(("$y$x" !~ /^$y(??{$y})\z/ ? '' : 'not '),
2962 "ok $test - postponed non-utf8 string in non-utf8 re doesn't match utf8\n");
2963++$test;
2964
2965print(("$x$x" !~ /^$x(??{$y})\z/ ? '' : 'not '),
2966 "ok $test - postponed non-utf8 string in utf8 re doesn't match utf8\n");
2967++$test;
2968
2969print(("$y$y" =~ /^$y(??{$y})\z/ ? '' : 'not '),
2970 "ok $test - postponed non-utf8 string in non-utf8 re matches non-utf8\n");
2971++$test;
2972
2973print(("$x$y" =~ /^$x(??{$y})\z/ ? '' : 'not '),
2974 "ok $test - postponed non-utf8 string in utf8 re matches non-utf8\n");
2975++$test;
2976$y = $z; # reset $y after upgrade
2977
2978print(("$x$y" !~ /^$x(??{$x})\z/ ? '' : 'not '),
2979 "ok $test - postponed utf8 string in utf8 re doesn't match non-utf8\n");
2980++$test;
2981$y = $z; # reset $y after upgrade
2982
2983print(("$y$y" !~ /^$y(??{$x})\z/ ? '' : 'not '),
2984 "ok $test - postponed utf8 string in non-utf8 re doesn't match non-utf8\n");
2985++$test;
2986
2987} # no re 'eval'
2988
2989print "# more user-defined character properties\n";
2990
2991sub IsSyriac1 {
2992 return <<'END';
29930712 072C
29940730 074A
2995END
2996}
2997
2998print "\x{0712}" =~ /\p{IsSyriac1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2999print "\x{072F}" =~ /\P{IsSyriac1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
3000
3001sub Syriac1 {
3002 return <<'END';
30030712 072C
30040730 074A
3005END
3006}
3007
3008print "\x{0712}" =~ /\p{Syriac1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
3009print "\x{072F}" =~ /\P{Syriac1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
3010
3011{
3012 print "# Change #18179\n";
3013 # previously failed with "panic: end_shift
3014 my $s = "\x{100}" x 5;
3015 my $ok = $s =~ /(\x{100}{4})/;
3016 my($ord, $len) = (ord $1, length $1);
3017 print +($ok && $ord == 0x100 && $len == 4)
3018 ? "ok $test\n" : "not ok $test\t# $ok/$ord/$len\n";
3019 ++$test;
3020}
3021
3022{
3023 print "# [perl #15763]\n";
3024
3025 $a = "x\x{100}";
3026 chop $a; # but leaves the UTF-8 flag
3027 $a .= "y"; # 1 byte before "y"
3028
3029 ok($a =~ /^\C/, 'match one \C on 1-byte UTF-8');
3030 ok($a =~ /^\C{1}/, 'match \C{1}');
3031
3032 ok($a =~ /^\Cy/, 'match \Cy');
3033 ok($a =~ /^\C{1}y/, 'match \C{1}y');
3034
3035 $a = "\x{100}y"; # 2 bytes before "y"
3036
3037 ok($a =~ /^\C/, 'match one \C on 2-byte UTF-8');
3038 ok($a =~ /^\C{1}/, 'match \C{1}');
3039 ok($a =~ /^\C\C/, 'match two \C');
3040 ok($a =~ /^\C{2}/, 'match \C{2}');
3041
3042 ok($a =~ /^\C\C\C/, 'match three \C on 2-byte UTF-8 and a byte');
3043 ok($a =~ /^\C{3}/, 'match \C{3}');
3044
3045 ok($a =~ /^\C\Cy/, 'match two \C');
3046 ok($a =~ /^\C{2}y/, 'match \C{2}');
3047
3048 ok($a !~ /^\C\C\Cy/, q{don't match three \Cy});
3049 ok($a !~ /^\C{2}\Cy/, q{don't match \C{3}y});
3050
3051 $a = "\x{1000}y"; # 3 bytes before "y"
3052
3053 ok($a =~ /^\C/, 'match one \C on three-byte UTF-8');
3054 ok($a =~ /^\C{1}/, 'match \C{1}');
3055 ok($a =~ /^\C\C/, 'match two \C');
3056 ok($a =~ /^\C{2}/, 'match \C{2}');
3057 ok($a =~ /^\C\C\C/, 'match three \C');
3058 ok($a =~ /^\C{3}/, 'match \C{3}');
3059
3060 ok($a =~ /^\C\C\C\C/, 'match four \C on three-byte UTF-8 and a byte');
3061 ok($a =~ /^\C{4}/, 'match \C{4}');
3062
3063 ok($a =~ /^\C\C\Cy/, 'match three \Cy');
3064 ok($a =~ /^\C{3}y/, 'match \C{3}y');
3065
3066 ok($a !~ /^\C\C\C\C\y/, q{don't match four \Cy});
3067 ok($a !~ /^\C{4}y/, q{don't match \C{4}y});
3068}
3069
3070$_ = 'aaaaaaaaaa';
3071utf8::upgrade($_); chop $_; $\="\n";
3072ok(/[^\s]+/, "m/[^\s]/ utf8");
3073ok(/[^\d]+/, "m/[^\d]/ utf8");
3074ok(($a = $_, $_ =~ s/[^\s]+/./g), "s/[^\s]/ utf8");
3075ok(($a = $_, $a =~ s/[^\d]+/./g), "s/[^\s]/ utf8");
3076
3077ok("\x{100}" =~ /\x{100}/, "[perl #15397]");
3078ok("\x{100}" =~ /(\x{100})/, "[perl #15397]");
3079ok("\x{100}" =~ /(\x{100}){1}/, "[perl #15397]");
3080ok("\x{100}\x{100}" =~ /(\x{100}){2}/, "[perl #15397]");
3081ok("\x{100}\x{100}" =~ /(\x{100})(\x{100})/, "[perl #15397]");
3082
3083$x = "CD";
3084$x =~ /(AB)*?CD/;
3085ok(!defined $1, "[perl #7471]");
3086
3087$x = "CD";
3088$x =~ /(AB)*CD/;
3089ok(!defined $1, "[perl #7471]");
3090
3091$pattern = "^(b+?|a){1,2}c";
3092ok("bac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3093ok("bbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3094ok("bbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3095ok("bbbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3096
3097{
3098 # [perl #18232]
3099 "\x{100}" =~ /(.)/;
3100 ok( $1 eq "\x{100}", '$1 is utf-8 [perl #18232]' );
3101 { 'a' =~ /./; }
3102 ok( $1 eq "\x{100}", '$1 is still utf-8' );
3103 ok( $1 ne "\xC4\x80", '$1 is not non-utf-8' );
3104}
3105
3106{
3107 use utf8;
3108 my $attr = 'Name-1' ;
3109
3110 my $NormalChar = qr/[\p{IsDigit}\p{IsLower}\p{IsUpper}]/;
3111 my $NormalWord = qr/${NormalChar}+?/;
3112 my $PredNameHyphen = qr/^${NormalWord}(\-${NormalWord})*?$/;
3113
3114 $attr =~ /^$/;
3115 ok( $attr =~ $PredNameHyphen, "[perl #19767] original test" );
3116}
3117
3118{
3119 use utf8;
3120 "a" =~ m/[b]/;
3121 ok ( "0" =~ /\p{N}+\z/, "[perl #19767] variant test" );
3122}
3123
3124{
3125
3126 $p = 1;
3127 foreach (1,2,3,4) {
3128 $p++ if /(??{ $p })/
3129 }
3130 ok ($p == 5, "[perl #20683] (??{ }) returns stale values");
3131 { package P; $a=1; sub TIESCALAR { bless[] } sub FETCH { $a++ } }
3132 tie $p, P;
3133 foreach (1,2,3,4) {
3134 /(??{ $p })/
3135 }
3136 ok ( $p == 5, "(??{ }) returns stale values");
3137}
3138
3139{
3140 # Subject: Odd regexp behavior
3141 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
3142 # Date: Wed, 26 Feb 2003 16:53:12 +0000
3143 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
3144 # To: perl-unicode@perl.org
3145
3146 $x = "\x{2019}\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3147 ok($x eq "\x{2019} k", "Markus Kuhn 2003-02-26");
3148
3149 $x = "b\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3150 ok($x eq "b k", "Markus Kuhn 2003-02-26");
3151
3152 ok("\x{2019}" =~ /\S/, "Markus Kuhn 2003-02-26");
3153}
3154
3155{
3156 my $i;
3157 ok('-1-3-5-' eq join('', split /((??{$i++}))/, '-1-3-5-'),
3158 "[perl #21411] (??{ .. }) corrupts split's stack");
3159 split /(?{'WOW'})/, 'abc';
3160 ok('a|b|c' eq join ('|', @_),
3161 "[perl #21411] (?{ .. }) version of the above");
3162}
3163
3164{
3165 split /(?{ split "" })/, "abc";
3166 ok(1,'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0');
3167}
3168
3169{
3170 ok("\x{100}\n" =~ /\x{100}\n$/, "UTF8 length cache and fbm_compile");
3171}
3172
3173{
3174 package Str;
3175 use overload q/""/ => sub { ${$_[0]}; };
3176 sub new { my ($c, $v) = @_; bless \$v, $c; }
3177
3178 package main;
3179 $_ = Str->new("a\x{100}/\x{100}b");
3180 ok(join(":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr");
3181}
3182
3183{
3184 $_ = "code: 'x' { '...' }\n"; study;
3185 my @x; push @x, $& while m/'[^\']*'/gx;
3186 ok(join(":", @x) eq "'x':'...'",
3187 "[perl #17757] Parse::RecDescent triggers infinite loop");
3188}
3189
3190{
3191 my $re = qq/^([^X]*)X/;
3192 utf8::upgrade($re);
3193 ok("\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED");
3194}
3195
3196ok(1, 'skip - $* not deprecated in Perl 5.8') for 1..6;
3197
3198# bug #19049
3199$_="abcdef\n";
3200@x = m/./g;
3201ok("abcde" eq "$`", '# TODO #19049 - global match not setting $`');
3202
3203ok("123\x{100}" =~ /^.*1.*23\x{100}$/, 'uft8 + multiple floating substr');
3204
3205# LATIN SMALL/CAPITAL LETTER A WITH MACRON
3206ok(" \x{101}" =~ qr/\x{100}/i,
3207 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3208
3209# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
3210ok(" \x{1E01}" =~ qr/\x{1E00}/i,
3211 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3212
3213# DESERET SMALL/CAPITAL LETTER LONG I
3214ok(" \x{10428}" =~ qr/\x{10400}/i,
3215 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3216
3217# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3218ok(" \x{1E01}x" =~ qr/\x{1E00}X/i,
3219 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3220
3221{
3222 # [perl #23769] Unicode regex broken on simple example
3223 # regrepeat() didn't handle UTF-8 EXACT case right.
3224
3225 my $s = "\x{a0}\x{a0}\x{a0}\x{100}"; chop $s;
3226
3227 ok($s =~ /\x{a0}/, "[perl #23769]");
3228 ok($s =~ /\x{a0}+/, "[perl #23769]");
3229 ok($s =~ /\x{a0}\x{a0}/, "[perl #23769]");
3230
3231 ok("aaa\x{100}" =~ /(a+)/, "[perl #23769] easy invariant");
3232 ok($1 eq "aaa", "[perl #23769]");
3233
3234 ok("\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/, "[perl #23769] regrepeat invariant");
3235 ok($1 eq "\xa0\xa0\xa0", "[perl #23769]");
3236
3237 ok("ababab\x{100} " =~ /((?:ab)+)/, "[perl #23769] hard invariant");
3238 ok($1 eq "ababab", "[perl #23769]");
3239
3240 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+)/, "[perl #23769] hard variant");
3241 ok($1 eq "\xa0\xa1\xa0\xa1\xa0\xa1", "[perl #23769]");
3242
3243 ok("aaa\x{100} " =~ /(a+?)/, "[perl #23769] easy invariant");
3244 ok($1 eq "a", "[perl #23769]");
3245
3246 ok("\xa0\xa0\xa0\x{100} " =~ /(\xa0+?)/, "[perl #23769] regrepeat variant");
3247 ok($1 eq "\xa0", "[perl #23769]");
3248
3249 ok("ababab\x{100} " =~ /((?:ab)+?)/, "[perl #23769] hard invariant");
3250 ok($1 eq "ab", "[perl #23769]");
3251
3252 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+?)/, "[perl #23769] hard variant");
3253 ok($1 eq "\xa0\xa1", "[perl #23769]");
3254
3255 ok("\xc4\xc4\xc4" !~ /(\x{100}+)/, "[perl #23769] don't match first byte of utf8 representation");
3256 ok("\xc4\xc4\xc4" !~ /(\x{100}+?)/, "[perl #23769] don't match first byte of utf8 representation");
3257}
3258
3259for (120 .. 130) {
3260 my $head = 'x' x $_;
3261 for my $tail ('\x{0061}', '\x{1234}') {
3262 ok(
3263 eval qq{ "$head$tail" =~ /$head$tail/ },
3264 '\x{...} misparsed in regexp near 127 char EXACT limit'
3265 );
3266 }
3267}
3268
3269# perl #25269: panic: pp_match start/end pointers
3270ok("a-bc" eq eval {
3271 my($x, $y) = "bca" =~ /^(?=.*(a)).*(bc)/;
3272 "$x-$y";
3273}, 'captures can move backwards in string');
3274
3275# perl #27940: \cA not recognized in character classes
3276ok("a\cAb" =~ /\cA/, '\cA in pattern');
3277ok("a\cAb" =~ /[\cA]/, '\cA in character class');
3278ok("a\cAb" =~ /[\cA-\cB]/, '\cA in character class range');
3279ok("abc" =~ /[^\cA-\cB]/, '\cA in negated character class range');
3280ok("a\cBb" =~ /[\cA-\cC]/, '\cB in character class range');
3281ok("a\cCbc" =~ /[^\cA-\cB]/, '\cC in negated character class range');
3282ok("a\cAb" =~ /(??{"\cA"})/, '\cA in ??{} pattern');
3283
3284# perl #28532: optional zero-width match at end of string is ignored
3285ok(("abc" =~ /^abc(\z)?/) && defined($1),
3286 'optional zero-width match at end of string');
3287ok(("abc" =~ /^abc(\z)??/) && !defined($1),
3288 'optional zero-width match at end of string');
3289
3290
3291
3292{ # TRIE related
3293 my @got=();
3294 "words"=~/(word|word|word)(?{push @got,$1})s$/;
3295 ok(@got==1,"TRIE optimation is working") or warn "# @got";
3296 @got=();
3297 "words"=~/(word|word|word)(?{push @got,$1})s$/i;
3298 ok(@got==1,"TRIEF optimisation is working") or warn "# @got";
3299
3300 my @nums=map {int rand 1000} 1..100;
3301 my $re="(".(join "|",@nums).")";
3302 $re=qr/\b$re\b/;
3303
3304 foreach (@nums) {
3305 ok($_=~/$re/,"Trie nums");
3306 }
3307 $_=join " ", @nums;
3308 @got=();
3309 push @got,$1 while /$re/g;
3310
3311 my %count;
3312 $count{$_}++ for @got;
3313 my $ok=1;
3314 for (@nums) {
3315 $ok=0 if --$count{$_}<0;
3316 }
3317 ok($ok,"Trie min count matches");
3318}
3319
3320
3321# TRIE related
3322# LATIN SMALL/CAPITAL LETTER A WITH MACRON
3323ok(("foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i) && $1 eq "\x{101}foo",
3324 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON");
3325
3326# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
3327ok(("foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i) && $1 eq "\x{1E01}foo",
3328 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW");
3329
3330# DESERET SMALL/CAPITAL LETTER LONG I
3331ok(("foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i) && $1 eq "\x{10428}foo",
3332 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I");
3333
3334# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3335ok(("foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i) && $1 eq "\x{1E01}xfoo",
3336 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'");
3337
3338{# TRIE related
3339
3340use charnames ':full';
3341
3342$s="\N{LATIN SMALL LETTER SHARP S}";
3343ok(("foba ba$s" =~ qr/(foo|Ba$s|bar)/i)
3344 && $1 eq "ba$s",
3345 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3346ok(("foba ba$s" =~ qr/(Ba$s|foo|bar)/i)
3347 && $1 eq "ba$s",
3348 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3349ok(("foba ba$s" =~ qr/(foo|bar|Ba$s)/i)
3350 && $1 eq "ba$s",
3351 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3352
3353ok(("foba ba$s" =~ qr/(foo|Bass|bar)/i)
3354 && $1 eq "ba$s",
3355 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3356
3357ok(("foba ba$s" =~ qr/(foo|BaSS|bar)/i)
3358 && $1 eq "ba$s",
3359 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS");
3360}
3361
3362
3363
3364{
3365 my @normal=qw(these are some normal words);
3366 my $psycho=join "|",@normal,map chr $_,255..20000;
3367 ok(('these'=~/($psycho)/) && $1 eq 'these','Pyscho');
3368}
3369
3370# [perl #36207] mixed utf8 / latin-1 and case folding
3371
3372{
3373 my $utf8 = "\xe9\x{100}"; chop $utf8;
3374 my $latin1 = "\xe9";
3375
3376 ok($utf8 =~ /\xe9/i, "utf8/latin");
3377 ok($utf8 =~ /$latin1/i, "utf8/latin runtime");
3378 ok($utf8 =~ /(abc|\xe9)/i, "utf8/latin trie");
3379 ok($utf8 =~ /(abc|$latin1)/i, "utf8/latin trie runtime");
3380
3381 ok("\xe9" =~ /$utf8/i, "# TODO latin/utf8");
3382 ok("\xe9" =~ /(abc|$utf8)/i, "# latin/utf8 trie");
3383 ok($latin1 =~ /$utf8/i, "# TODO latin/utf8 runtime");
3384 ok($latin1 =~ /(abc|$utf8)/i, "# latin/utf8 trie runtime");
3385}
3386
3387# [perl #37038] Global regular matches generate invalid pointers
3388
3389{
3390 my $s = "abcd";
3391 $s =~ /(..)(..)/g;
3392 $s = $1;
3393 $s = $2;
3394 ok($s eq 'cd',
3395 "# assigning to original string should not corrupt match vars");
3396}
3397
3398# last test 1187
3399
Note: See TracBrowser for help on using the repository browser.