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