1#!./perl 2# 3# This is a home for regular expression tests that don't fit into 4# the format supported by re/regexp.t. If you want to add a test 5# that does fit that format, add it to re/re_tests, not here. 6 7use strict; 8use warnings; 9use 5.010; 10 11 12sub run_tests; 13 14$| = 1; 15 16 17BEGIN { 18 chdir 't' if -d 't'; 19 @INC = ('../lib','.'); 20 require './test.pl'; 21 skip_all_if_miniperl("miniperl can't load Tie::Hash::NamedCapture, need for %+ and %-"); 22} 23 24run_tests() unless caller; 25 26# 27# Tests start here. 28# 29sub run_tests { 30 31 { 32 my $message = '\C matches octet'; 33 $_ = "a\x{100}b"; 34 ok(/(.)(\C)(\C)(.)/, $message); 35 is($1, "a", $message); 36 if ($::IS_ASCII) { # ASCII (or equivalent), should be UTF-8 37 is($2, "\xC4", $message); 38 is($3, "\x80", $message); 39 } 40 elsif ($::IS_EBCDIC) { # EBCDIC (or equivalent), should be UTF-EBCDIC 41 is($2, "\x8C", $message); 42 is($3, "\x41", $message); 43 } 44 else { 45 SKIP: { 46 ok 0, "Unexpected platform", "ord ('A') =" . ord 'A'; 47 skip "Unexpected platform"; 48 } 49 } 50 is($4, "b", $message); 51 } 52 53 { 54 my $message = '\C matches octet'; 55 $_ = "\x{100}"; 56 ok(/(\C)/g, $message); 57 if ($::IS_ASCII) { 58 is($1, "\xC4", $message); 59 } 60 elsif ($::IS_EBCDIC) { 61 is($1, "\x8C", $message); 62 } 63 else { 64 ok 0, "Unexpected platform", "ord ('A') = " . ord 'A'; 65 } 66 ok(/(\C)/g, $message); 67 if ($::IS_ASCII) { 68 is($1, "\x80", $message); 69 } 70 elsif ($::IS_EBCDIC) { 71 is($1, "\x41", $message); 72 } 73 else { 74 ok 0, "Unexpected platform", "ord ('A') = " . ord 'A'; 75 } 76 } 77 78 { 79 # Japhy -- added 03/03/2001 80 () = (my $str = "abc") =~ /(...)/; 81 $str = "def"; 82 is($1, "abc", 'Changing subject does not modify $1'); 83 } 84 85 SKIP: 86 { 87 # The trick is that in EBCDIC the explicit numeric range should 88 # match (as also in non-EBCDIC) but the explicit alphabetic range 89 # should not match. 90 ok "\x8e" =~ /[\x89-\x91]/, '"\x8e" =~ /[\x89-\x91]/'; 91 ok "\xce" =~ /[\xc9-\xd1]/, '"\xce" =~ /[\xc9-\xd1]/'; 92 93 skip "Not an EBCDIC platform", 2 unless ord ('i') == 0x89 && 94 ord ('J') == 0xd1; 95 96 # In most places these tests would succeed since \x8e does not 97 # in most character sets match 'i' or 'j' nor would \xce match 98 # 'I' or 'J', but strictly speaking these tests are here for 99 # the good of EBCDIC, so let's test these only there. 100 unlike("\x8e", qr/[i-j]/, '"\x8e" !~ /[i-j]/'); 101 unlike("\xce", qr/[I-J]/, '"\xce" !~ /[I-J]/'); 102 } 103 104 { 105 ok "\x{ab}" =~ /\x{ab}/, '"\x{ab}" =~ /\x{ab}/ '; 106 ok "\x{abcd}" =~ /\x{abcd}/, '"\x{abcd}" =~ /\x{abcd}/'; 107 } 108 109 { 110 my $message = 'bug id 20001008.001'; 111 112 my @x = ("stra\337e 138", "stra\337e 138"); 113 for (@x) { 114 ok(s/(\d+)\s*([\w\-]+)/$1 . uc $2/e, $message); 115 ok(my ($latin) = /^(.+)(?:\s+\d)/, $message); 116 is($latin, "stra\337e", $message); 117 ok($latin =~ s/stra\337e/straße/, $message); 118 # 119 # Previous code follows, but outcommented - there were no tests. 120 # 121 # $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a 122 # use utf8; # needed for the raw UTF-8 123 # $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a 124 } 125 } 126 127 { 128 my $message = 'Test \x escapes'; 129 ok("ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4", $message); 130 ok("ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}", $message); 131 ok("ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}", $message); 132 ok("ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4", $message); 133 ok("ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4", $message); 134 ok("ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}", $message); 135 ok("ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}", $message); 136 ok("ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4", $message); 137 } 138 139 { 140 my $message = 'Match code points > 255'; 141 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg"; 142 ok(/(.\x{300})./, $message); 143 ok($` eq "abc\x{100}" && length ($`) == 4, $message); 144 ok($& eq "\x{200}\x{300}\x{380}" && length ($&) == 3, $message); 145 ok($' eq "\x{400}defg" && length ($') == 5, $message); 146 ok($1 eq "\x{200}\x{300}" && length ($1) == 2, $message); 147 } 148 149 { 150 my $x = "\x{10FFFD}"; 151 $x =~ s/(.)/$1/g; 152 ok ord($x) == 0x10FFFD && length($x) == 1, "From Robin Houston"; 153 } 154 155 { 156 my %d = ( 157 "7f" => [0, 0, 0], 158 "80" => [1, 1, 0], 159 "ff" => [1, 1, 0], 160 "100" => [0, 1, 1], 161 ); 162 163 while (my ($code, $match) = each %d) { 164 my $message = "Properties of \\x$code"; 165 my $char = eval qq ["\\x{$code}"]; 166 167 is(0 + ($char =~ /[\x80-\xff]/), $$match[0], $message); 168 is(0 + ($char =~ /[\x80-\x{100}]/), $$match[1], $message); 169 is(0 + ($char =~ /[\x{100}]/), $$match[2], $message); 170 } 171 } 172 173 { 174 # From Japhy 175 foreach (qw(c g o)) { 176 warning_like(sub {'' =~ "(?$_)"}, qr/^Useless \(\?$_\)/); 177 warning_like(sub {'' =~ "(?-$_)"}, qr/^Useless \(\?-$_\)/); 178 } 179 180 # Now test multi-error regexes 181 foreach (['(?g-o)', qr/^Useless \(\?g\)/, qr/^Useless \(\?-o\)/], 182 ['(?g-c)', qr/^Useless \(\?g\)/, qr/^Useless \(\?-c\)/], 183 # (?c) means (?g) error won't be thrown 184 ['(?o-cg)', qr/^Useless \(\?o\)/, qr/^Useless \(\?-c\)/], 185 ['(?ogc)', qr/^Useless \(\?o\)/, qr/^Useless \(\?g\)/, 186 qr/^Useless \(\?c\)/], 187 ) { 188 my ($re, @warnings) = @$_; 189 warnings_like(sub {eval "qr/$re/"}, \@warnings, "qr/$re/ warns"); 190 } 191 } 192 193 { 194 my $message = "/x tests"; 195 $_ = "foo"; 196 foreach my $pat (<<" --", <<" --") { 197 /f 198 o\r 199 o 200 \$ 201 /x 202 -- 203 /f 204 o 205 o 206 \$\r 207 /x 208 -- 209 is(eval $pat, 1, $message); 210 is($@, '', $message); 211 } 212 } 213 214 { 215 my $message = "/o feature"; 216 sub test_o {$_ [0] =~ /$_[1]/o; return $1} 217 is(test_o ('abc', '(.)..'), 'a', $message); 218 is(test_o ('abc', '..(.)'), 'a', $message); 219 } 220 221 { 222 # Test basic $^N usage outside of a regex 223 my $message = '$^N usage outside of a regex'; 224 my $x = "abcdef"; 225 ok(($x =~ /cde/ and !defined $^N), $message); 226 ok(($x =~ /(cde)/ and $^N eq "cde"), $message); 227 ok(($x =~ /(c)(d)(e)/ and $^N eq "e"), $message); 228 ok(($x =~ /(c(d)e)/ and $^N eq "cde"), $message); 229 ok(($x =~ /(foo)|(c(d)e)/ and $^N eq "cde"), $message); 230 ok(($x =~ /(c(d)e)|(foo)/ and $^N eq "cde"), $message); 231 ok(($x =~ /(c(d)e)|(abc)/ and $^N eq "abc"), $message); 232 ok(($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde"), $message); 233 ok(($x =~ /(c(d)e)(abc)?/ and $^N eq "cde"), $message); 234 ok(($x =~ /(?:c(d)e)/ and $^N eq "d"), $message); 235 ok(($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d"), $message); 236 ok(($x =~ /(?:([abc])|([def]))*/ and $^N eq "f"), $message); 237 ok(($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f"), $message); 238 ok(($x =~ /(([ace])|([bd]))*/ and $^N eq "e"), $message); 239 {ok(($x =~ /(([ace])|([bdf]))*/ and $^N eq "f"), $message);} 240 ## Test to see if $^N is automatically localized -- it should now 241 ## have the value set in the previous test. 242 is($^N, "e", '$^N is automatically localized'); 243 244 # Now test inside (?{ ... }) 245 $message = '$^N usage inside (?{ ... })'; 246 our ($y, $z); 247 ok(($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b"), $message); 248 ok(($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"), $message); 249 ok(($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"), $message); 250 ok(($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc" 251 and $z eq "abcd"), $message); 252 ok(($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc" 253 and $z eq "abcde"), $message); 254 255 } 256 257 SKIP: 258 { 259 ## Should probably put in tests for all the POSIX stuff, 260 ## but not sure how to guarantee a specific locale...... 261 262 skip "Not an ASCII platform", 2 unless $::IS_ASCII; 263 my $message = 'Test [[:cntrl:]]'; 264 my $AllBytes = join "" => map {chr} 0 .. 255; 265 (my $x = $AllBytes) =~ s/[[:cntrl:]]//g; 266 is($x, join("", map {chr} 0x20 .. 0x7E, 0x80 .. 0xFF), $message); 267 268 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g; 269 is($x, (join "", map {chr} 0x00 .. 0x1F, 0x7F), $message); 270 } 271 272 { 273 # With /s modifier UTF8 chars were interpreted as bytes 274 my $message = "UTF-8 chars aren't bytes"; 275 my $a = "Hello \x{263A} World"; 276 my @a = ($a =~ /./gs); 277 is($#a, 12, $message); 278 } 279 280 { 281 my $message = '. matches \n with /s'; 282 my $str1 = "foo\nbar"; 283 my $str2 = "foo\n\x{100}bar"; 284 my ($a, $b) = map {chr} $::IS_ASCII ? (0xc4, 0x80) : (0x8c, 0x41); 285 my @a; 286 @a = $str1 =~ /./g; is(@a, 6, $message); is("@a", "f o o b a r", $message); 287 @a = $str1 =~ /./gs; is(@a, 7, $message); is("@a", "f o o \n b a r", $message); 288 @a = $str1 =~ /\C/g; is(@a, 7, $message); is("@a", "f o o \n b a r", $message); 289 @a = $str1 =~ /\C/gs; is(@a, 7, $message); is("@a", "f o o \n b a r", $message); 290 @a = $str2 =~ /./g; is(@a, 7, $message); is("@a", "f o o \x{100} b a r", $message); 291 @a = $str2 =~ /./gs; is(@a, 8, $message); is("@a", "f o o \n \x{100} b a r", $message); 292 @a = $str2 =~ /\C/g; is(@a, 9, $message); is("@a", "f o o \n $a $b b a r", $message); 293 @a = $str2 =~ /\C/gs; is(@a, 9, $message); is("@a", "f o o \n $a $b b a r", $message); 294 } 295 296 { 297 no warnings 'digit'; 298 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these. 299 my $x; 300 $x = "\x4e" . "E"; 301 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched."); 302 303 $x = "\x4e" . "i"; 304 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)"); 305 306 $x = "\x4" . "j"; 307 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)"); 308 309 $x = "\x0" . "k"; 310 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)"); 311 312 $x = "\x0" . "x"; 313 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0"); 314 315 $x = "\x0" . "xa"; 316 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa"); 317 318 $x = "\x9" . "_b"; 319 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b"); 320 321 # and now again in [] ranges 322 323 $x = "\x4e" . "E"; 324 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched."); 325 326 $x = "\x4e" . "i"; 327 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)"); 328 329 $x = "\x4" . "j"; 330 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)"); 331 332 $x = "\x0" . "k"; 333 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)"); 334 335 $x = "\x0" . "x"; 336 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0"); 337 338 $x = "\x0" . "xa"; 339 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa"); 340 341 $x = "\x9" . "_b"; 342 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b"); 343 344 # Check that \x{##} works. 5.6.1 fails quite a few of these. 345 346 $x = "\x9b"; 347 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b"); 348 349 $x = "\x9b" . "y"; 350 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)"); 351 352 $x = "\x9b" . "y"; 353 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b"); 354 355 $x = "\x9b" . "y"; 356 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b"); 357 358 $x = "\x0" . "y"; 359 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0"); 360 361 $x = "\x0" . "y"; 362 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0"); 363 364 $x = "\x9b" . "y"; 365 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b"); 366 367 $x = "\x9b"; 368 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b"); 369 370 $x = "\x9b" . "y"; 371 ok ($x =~ /^[\x{9_b}y]{2}$/, 372 "\\x{9_b} is to be treated as \\x9b (again)"); 373 374 $x = "\x9b" . "y"; 375 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b"); 376 377 $x = "\x9b" . "y"; 378 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b"); 379 380 $x = "\x0" . "y"; 381 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0"); 382 383 $x = "\x0" . "y"; 384 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0"); 385 386 $x = "\x9b" . "y"; 387 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b"); 388 389 } 390 391 { 392 # High bit bug -- japhy 393 my $x = "ab\200d"; 394 ok $x =~ /.*?\200/, "High bit fine"; 395 } 396 397 { 398 # The basic character classes and Unicode 399 ok "\x{0100}" =~ /\w/, 'LATIN CAPITAL LETTER A WITH MACRON in /\w/'; 400 ok "\x{0660}" =~ /\d/, 'ARABIC-INDIC DIGIT ZERO in /\d/'; 401 ok "\x{1680}" =~ /\s/, 'OGHAM SPACE MARK in /\s/'; 402 } 403 404 { 405 my $message = "Folding matches and Unicode"; 406 like("a\x{100}", qr/A/i, $message); 407 like("A\x{100}", qr/a/i, $message); 408 like("a\x{100}", qr/a/i, $message); 409 like("A\x{100}", qr/A/i, $message); 410 like("\x{101}a", qr/\x{100}/i, $message); 411 like("\x{100}a", qr/\x{100}/i, $message); 412 like("\x{101}a", qr/\x{101}/i, $message); 413 like("\x{100}a", qr/\x{101}/i, $message); 414 like("a\x{100}", qr/A\x{100}/i, $message); 415 like("A\x{100}", qr/a\x{100}/i, $message); 416 like("a\x{100}", qr/a\x{100}/i, $message); 417 like("A\x{100}", qr/A\x{100}/i, $message); 418 like("a\x{100}", qr/[A]/i, $message); 419 like("A\x{100}", qr/[a]/i, $message); 420 like("a\x{100}", qr/[a]/i, $message); 421 like("A\x{100}", qr/[A]/i, $message); 422 like("\x{101}a", qr/[\x{100}]/i, $message); 423 like("\x{100}a", qr/[\x{100}]/i, $message); 424 like("\x{101}a", qr/[\x{101}]/i, $message); 425 like("\x{100}a", qr/[\x{101}]/i, $message); 426 } 427 428 { 429 use charnames ':full'; 430 my $message = "Folding 'LATIN LETTER A WITH GRAVE'"; 431 432 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}"; 433 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}"; 434 435 like($lower, qr/$UPPER/i, $message); 436 like($UPPER, qr/$lower/i, $message); 437 like($lower, qr/[$UPPER]/i, $message); 438 like($UPPER, qr/[$lower]/i, $message); 439 440 $message = "Folding 'GREEK LETTER ALPHA WITH VRACHY'"; 441 442 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}"; 443 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}"; 444 445 like($lower, qr/$UPPER/i, $message); 446 like($UPPER, qr/$lower/i, $message); 447 like($lower, qr/[$UPPER]/i, $message); 448 like($UPPER, qr/[$lower]/i, $message); 449 450 $message = "Folding 'LATIN LETTER Y WITH DIAERESIS'"; 451 452 $lower = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}"; 453 $UPPER = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}"; 454 455 like($lower, qr/$UPPER/i, $message); 456 like($UPPER, qr/$lower/i, $message); 457 like($lower, qr/[$UPPER]/i, $message); 458 like($UPPER, qr/[$lower]/i, $message); 459 } 460 461 { 462 use charnames ':full'; 463 my $message = "GREEK CAPITAL LETTER SIGMA vs " . 464 "COMBINING GREEK PERISPOMENI"; 465 466 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}"; 467 my $char = "\N{COMBINING GREEK PERISPOMENI}"; 468 469 warning_is(sub {unlike("_:$char:_", qr/_:$SIGMA:_/i, $message)}, undef, 470 'Did not warn [change a5961de5f4215b5c]'); 471 } 472 473 { 474 my $message = '\X'; 475 use charnames ':full'; 476 477 ok("a!" =~ /^(\X)!/ && $1 eq "a", $message); 478 ok("\xDF!" =~ /^(\X)!/ && $1 eq "\xDF", $message); 479 ok("\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}", $message); 480 ok("\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}", $message); 481 ok("\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ && 482 $1 eq "\N{LATIN CAPITAL LETTER E}", $message); 483 ok("\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!" 484 =~ /^(\X)!/ && 485 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}", $message); 486 487 $message = '\C and \X'; 488 like("!abc!", qr/a\Cc/, $message); 489 like("!abc!", qr/a\Xc/, $message); 490 } 491 492 { 493 my $message = "Final Sigma"; 494 495 my $SIGMA = "\x{03A3}"; # CAPITAL 496 my $Sigma = "\x{03C2}"; # SMALL FINAL 497 my $sigma = "\x{03C3}"; # SMALL 498 499 like($SIGMA, qr/$SIGMA/i, $message); 500 like($SIGMA, qr/$Sigma/i, $message); 501 like($SIGMA, qr/$sigma/i, $message); 502 503 like($Sigma, qr/$SIGMA/i, $message); 504 like($Sigma, qr/$Sigma/i, $message); 505 like($Sigma, qr/$sigma/i, $message); 506 507 like($sigma, qr/$SIGMA/i, $message); 508 like($sigma, qr/$Sigma/i, $message); 509 like($sigma, qr/$sigma/i, $message); 510 511 like($SIGMA, qr/[$SIGMA]/i, $message); 512 like($SIGMA, qr/[$Sigma]/i, $message); 513 like($SIGMA, qr/[$sigma]/i, $message); 514 515 like($Sigma, qr/[$SIGMA]/i, $message); 516 like($Sigma, qr/[$Sigma]/i, $message); 517 like($Sigma, qr/[$sigma]/i, $message); 518 519 like($sigma, qr/[$SIGMA]/i, $message); 520 like($sigma, qr/[$Sigma]/i, $message); 521 like($sigma, qr/[$sigma]/i, $message); 522 523 $message = "More final Sigma"; 524 525 my $S3 = "$SIGMA$Sigma$sigma"; 526 527 ok(":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma, $message); 528 ok(":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma, $message); 529 ok(":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma, $message); 530 531 ok(":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma, $message); 532 ok(":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma, $message); 533 ok(":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma, $message); 534 } 535 536 { 537 use charnames ':full'; 538 my $message = "Parlez-Vous " . 539 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais?"; 540 541 ok("Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran.ais/ && 542 $& eq "Francais", $message); 543 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran.ais/ && 544 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message); 545 ok("Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Cais/ && 546 $& eq "Francais", $message); 547 # COMBINING CEDILLA is two bytes when encoded 548 like("Franc\N{COMBINING CEDILLA}ais", qr/Franc\C\Cais/, $message); 549 ok("Fran\N{LATIN SMALL LETTER C}ais" =~ /Fran\Xais/ && 550 $& eq "Francais", $message); 551 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ /Fran\Xais/ && 552 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message); 553 ok("Franc\N{COMBINING CEDILLA}ais" =~ /Fran\Xais/ && 554 $& eq "Franc\N{COMBINING CEDILLA}ais", $message); 555 ok("Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~ 556 /Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ && 557 $& eq "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", $message); 558 ok("Franc\N{COMBINING CEDILLA}ais" =~ /Franc\N{COMBINING CEDILLA}ais/ && 559 $& eq "Franc\N{COMBINING CEDILLA}ais", $message); 560 561 my @f = ( 562 ["Fran\N{LATIN SMALL LETTER C}ais", "Francais"], 563 ["Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais", 564 "Fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais"], 565 ["Franc\N{COMBINING CEDILLA}ais", "Franc\N{COMBINING CEDILLA}ais"], 566 ); 567 foreach my $entry (@f) { 568 my ($subject, $match) = @$entry; 569 ok($subject =~ /Fran(?:c\N{COMBINING CEDILLA}?| 570 \N{LATIN SMALL LETTER C WITH CEDILLA})ais/x && 571 $& eq $match, $message); 572 } 573 } 574 575 { 576 my $message = "Lingering (and useless) UTF8 flag doesn't mess up /i"; 577 my $pat = "ABcde"; 578 my $str = "abcDE\x{100}"; 579 chop $str; 580 like($str, qr/$pat/i, $message); 581 582 $pat = "ABcde\x{100}"; 583 $str = "abcDE"; 584 chop $pat; 585 like($str, qr/$pat/i, $message); 586 587 $pat = "ABcde\x{100}"; 588 $str = "abcDE\x{100}"; 589 chop $pat; 590 chop $str; 591 like($str, qr/$pat/i, $message); 592 } 593 594 { 595 use charnames ':full'; 596 my $message = "LATIN SMALL LETTER SHARP S " . 597 "(\N{LATIN SMALL LETTER SHARP S})"; 598 599 like("\N{LATIN SMALL LETTER SHARP S}", 600 qr/\N{LATIN SMALL LETTER SHARP S}/, $message); 601 like("\N{LATIN SMALL LETTER SHARP S}", 602 qr/\N{LATIN SMALL LETTER SHARP S}/i, $message); 603 like("\N{LATIN SMALL LETTER SHARP S}", 604 qr/[\N{LATIN SMALL LETTER SHARP S}]/, $message); 605 like("\N{LATIN SMALL LETTER SHARP S}", 606 qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message); 607 608 like("ss", qr /\N{LATIN SMALL LETTER SHARP S}/i, $message); 609 like("SS", qr /\N{LATIN SMALL LETTER SHARP S}/i, $message); 610 like("ss", qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message); 611 like("SS", qr/[\N{LATIN SMALL LETTER SHARP S}]/i, $message); 612 613 like("\N{LATIN SMALL LETTER SHARP S}", qr/ss/i, $message); 614 like("\N{LATIN SMALL LETTER SHARP S}", qr/SS/i, $message); 615 616 $message = "Unoptimized named sequence in class"; 617 like("ss", qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message); 618 like("SS", qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message); 619 like("\N{LATIN SMALL LETTER SHARP S}", 620 qr/[\N{LATIN SMALL LETTER SHARP S}x]/, $message); 621 like("\N{LATIN SMALL LETTER SHARP S}", 622 qr/[\N{LATIN SMALL LETTER SHARP S}x]/i, $message); 623 } 624 625 { 626 # More whitespace: U+0085, U+2028, U+2029\n"; 627 628 # U+0085, U+00A0 need to be forced to be Unicode, the \x{100} does that. 629 SKIP: { 630 skip "EBCDIC platform", 4 if $::IS_EBCDIC; 631 # Do \x{0015} and \x{0041} match \s in EBCDIC? 632 ok "<\x{100}\x{0085}>" =~ /<\x{100}\s>/, '\x{0085} in \s'; 633 ok "<\x{0085}>" =~ /<\v>/, '\x{0085} in \v'; 634 ok "<\x{100}\x{00A0}>" =~ /<\x{100}\s>/, '\x{00A0} in \s'; 635 ok "<\x{00A0}>" =~ /<\h>/, '\x{00A0} in \h'; 636 } 637 my @h = map {sprintf "%05x" => $_} 0x01680, 0x0180E, 0x02000 .. 0x0200A, 638 0x0202F, 0x0205F, 0x03000; 639 my @v = map {sprintf "%05x" => $_} 0x02028, 0x02029; 640 641 my @H = map {sprintf "%05x" => $_} 0x01361, 0x0200B, 0x02408, 0x02420, 642 0x0303F, 0xE0020; 643 my @V = map {sprintf "%05x" => $_} 0x0008A .. 0x0008D, 0x00348, 0x10100, 644 0xE005F, 0xE007C; 645 646 for my $hex (@h) { 647 my $str = eval qq ["<\\x{$hex}>"]; 648 ok $str =~ /<\s>/, "\\x{$hex} in \\s"; 649 ok $str =~ /<\h>/, "\\x{$hex} in \\h"; 650 ok $str !~ /<\v>/, "\\x{$hex} not in \\v"; 651 } 652 653 for my $hex (@v) { 654 my $str = eval qq ["<\\x{$hex}>"]; 655 ok $str =~ /<\s>/, "\\x{$hex} in \\s"; 656 ok $str =~ /<\v>/, "\\x{$hex} in \\v"; 657 ok $str !~ /<\h>/, "\\x{$hex} not in \\h"; 658 } 659 660 for my $hex (@H) { 661 my $str = eval qq ["<\\x{$hex}>"]; 662 ok $str =~ /<\S>/, "\\x{$hex} in \\S"; 663 ok $str =~ /<\H>/, "\\x{$hex} in \\H"; 664 } 665 666 for my $hex (@V) { 667 my $str = eval qq ["<\\x{$hex}>"]; 668 ok $str =~ /<\S>/, "\\x{$hex} in \\S"; 669 ok $str =~ /<\V>/, "\\x{$hex} in \\V"; 670 } 671 } 672 673 { 674 # . with /s should work on characters, as opposed to bytes 675 my $message = ". with /s works on characters, not bytes"; 676 677 my $s = "\x{e4}\x{100}"; 678 # This is not expected to match: the point is that 679 # neither should we get "Malformed UTF-8" warnings. 680 warning_is(sub {$s =~ /\G(.+?)\n/gcs}, undef, 681 "No 'Malformed UTF-8' warning"); 682 683 my @c; 684 push @c => $1 while $s =~ /\G(.)/gs; 685 686 local $" = ""; 687 is("@c", $s, $message); 688 689 # Test only chars < 256 690 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}"; 691 my $r1 = ""; 692 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) { 693 $r1 .= $1 . $2; 694 } 695 696 my $t2 = $t1 . "\x{100}"; # Repeat with a larger char 697 my $r2 = ""; 698 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) { 699 $r2 .= $1 . $2; 700 } 701 $r2 =~ s/\x{100}//; 702 703 is($r1, $r2, $message); 704 } 705 706 { 707 my $message = "Unicode lookbehind"; 708 like("A\x{100}B" , qr/(?<=A.)B/, $message); 709 like("A\x{200}\x{300}B", qr/(?<=A..)B/, $message); 710 like("\x{400}AB" , qr/(?<=\x{400}.)B/, $message); 711 like("\x{500}\x{600}B" , qr/(?<=\x{500}.)B/, $message); 712 713 # Original code also contained: 714 # ok "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/; 715 # but that looks like a typo. 716 } 717 718 { 719 my $message = 'UTF-8 hash keys and /$/'; 720 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters 721 # /2002-01/msg01327.html 722 723 my $u = "a\x{100}"; 724 my $v = substr ($u, 0, 1); 725 my $w = substr ($u, 1, 1); 726 my %u = ($u => $u, $v => $v, $w => $w); 727 for (keys %u) { 728 my $m1 = /^\w*$/ ? 1 : 0; 729 my $m2 = $u {$_} =~ /^\w*$/ ? 1 : 0; 730 is($m1, $m2, $message); 731 } 732 } 733 734 { 735 my $message = "No SEGV in s/// and UTF-8"; 736 my $s = "s#\x{100}" x 4; 737 ok($s =~ s/[^\w]/ /g, $message); 738 if ( 1 or $ENV{PERL_TEST_LEGACY_POSIX_CC} ) { 739 is($s, "s \x{100}" x 4, $message); 740 } 741 else { 742 is($s, "s " x 4, $message); 743 } 744 } 745 746 { 747 my $message = "UTF-8 bug (maybe already known?)"; 748 my $u = "foo"; 749 $u =~ s/./\x{100}/g; 750 is($u, "\x{100}\x{100}\x{100}", $message); 751 752 $u = "foobar"; 753 $u =~ s/[ao]/\x{100}/g; 754 is($u, "f\x{100}\x{100}b\x{100}r", $message); 755 756 $u =~ s/\x{100}/e/g; 757 is($u, "feeber", $message); 758 } 759 760 { 761 my $message = "UTF-8 bug with s///"; 762 # check utf8/non-utf8 mixtures 763 # try to force all float/anchored check combinations 764 765 my $c = "\x{100}"; 766 my $subst; 767 for my $re ("xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x", 768 "xx.*(?=$c)", "(?=$c).*xx",) { 769 unlike("xxx", qr/$re/, $message); 770 ok(+($subst = "xxx") !~ s/$re//, $message); 771 } 772 for my $re ("xx.*$c*", "$c*.*xx") { 773 like("xxx", qr/$re/, $message); 774 ok(+($subst = "xxx") =~ s/$re//, $message); 775 is($subst, "", $message); 776 } 777 for my $re ("xxy*", "y*xx") { 778 like("xx$c", qr/$re/, $message); 779 ok(+($subst = "xx$c") =~ s/$re//, $message); 780 is($subst, $c, $message); 781 unlike("xy$c", qr/$re/, $message); 782 ok(+($subst = "xy$c") !~ s/$re//, $message); 783 } 784 for my $re ("xy$c*z", "x$c*yz") { 785 like("xyz", qr/$re/, $message); 786 ok(+($subst = "xyz") =~ s/$re//, $message); 787 is($subst, "", $message); 788 } 789 } 790 791 { 792 # The second half of RT #114808 793 warning_is(sub {'aa' =~ /.+\x{100}/}, undef, 794 'utf8-only floating substr, non-utf8 target, no warning'); 795 } 796 797 { 798 my $message = "qr /.../x"; 799 my $R = qr / A B C # D E/x; 800 ok("ABCDE" =~ $R && $& eq "ABC", $message); 801 ok("ABCDE" =~ /$R/ && $& eq "ABC", $message); 802 ok("ABCDE" =~ m/$R/ && $& eq "ABC", $message); 803 ok("ABCDE" =~ /($R)/ && $1 eq "ABC", $message); 804 ok("ABCDE" =~ m/($R)/ && $1 eq "ABC", $message); 805 } 806 807 { 808 local $\; 809 $_ = 'aaaaaaaaaa'; 810 utf8::upgrade($_); chop $_; $\="\n"; 811 ok /[^\s]+/, 'm/[^\s]/ utf8'; 812 ok /[^\d]+/, 'm/[^\d]/ utf8'; 813 ok +($a = $_, $_ =~ s/[^\s]+/./g), 's/[^\s]/ utf8'; 814 ok +($a = $_, $a =~ s/[^\d]+/./g), 's/[^\s]/ utf8'; 815 } 816 817 { 818 # Subject: Odd regexp behavior 819 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> 820 # Date: Wed, 26 Feb 2003 16:53:12 +0000 821 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk> 822 # To: perl-unicode@perl.org 823 824 my $message = 'Markus Kuhn 2003-02-26'; 825 826 my $x = "\x{2019}\nk"; 827 ok($x =~ s/(\S)\n(\S)/$1 $2/sg, $message); 828 is($x, "\x{2019} k", $message); 829 830 $x = "b\nk"; 831 ok($x =~ s/(\S)\n(\S)/$1 $2/sg, $message); 832 is($x, "b k", $message); 833 834 like("\x{2019}", qr/\S/, $message); 835 } 836 837 { 838 ok "\x{100}\n" =~ /\x{100}\n$/, "UTF-8 length cache and fbm_compile"; 839 } 840 841 { 842 package Str; 843 use overload q /""/ => sub {${$_ [0]};}; 844 sub new {my ($c, $v) = @_; bless \$v, $c;} 845 846 package main; 847 $_ = Str -> new ("a\x{100}/\x{100}b"); 848 ok join (":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr"; 849 } 850 851 { 852 my $re = qq /^([^X]*)X/; 853 utf8::upgrade ($re); 854 ok "\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED"; 855 my $loc_re = qq /(?l:^([^X]*)X)/; 856 utf8::upgrade ($loc_re); 857 ok "\x{100}X" =~ /$loc_re/, "locale, S_cl_and ANYOF_UNICODE & ANYOF_INVERTED"; 858 } 859 860 { 861 ok "123\x{100}" =~ /^.*1.*23\x{100}$/, 862 'UTF-8 + multiple floating substr'; 863 } 864 865 { 866 my $message = '<20030808193656.5109.1@llama.ni-s.u-net.com>'; 867 868 # LATIN SMALL/CAPITAL LETTER A WITH MACRON 869 like(" \x{101}", qr/\x{100}/i, $message); 870 871 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW 872 like(" \x{1E01}", qr/\x{1E00}/i, $message); 873 874 # DESERET SMALL/CAPITAL LETTER LONG I 875 like(" \x{10428}", qr/\x{10400}/i, $message); 876 877 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X' 878 like(" \x{1E01}x", qr/\x{1E00}X/i, $message); 879 } 880 881 { 882 for (120 .. 130, 240 .. 260) { 883 my $head = 'x' x $_; 884 my $message = q [Don't misparse \x{...} in regexp ] . 885 q [near EXACT char count limit]; 886 for my $tail ('\x{0061}', '\x{1234}', '\x61') { 887 eval qq{like("$head$tail", qr/$head$tail/, \$message)}; 888 is($@, '', $message); 889 } 890 $message = q [Don't misparse \N{...} in regexp ] . 891 q [near EXACT char count limit]; 892 for my $tail ('\N{SNOWFLAKE}') { 893 eval qq {use charnames ':full'; 894 like("$head$tail", qr/$head$tail/, \$message)}; 895 is($@, '', $message); 896 } 897 } 898 } 899 900 { # TRIE related 901 our @got = (); 902 "words" =~ /(word|word|word)(?{push @got, $1})s$/; 903 is(@got, 1, "TRIE optimisation"); 904 905 @got = (); 906 "words" =~ /(word|word|word)(?{push @got,$1})s$/i; 907 is(@got, 1,"TRIEF optimisation"); 908 909 my @nums = map {int rand 1000} 1 .. 100; 910 my $re = "(" . (join "|", @nums) . ")"; 911 $re = qr/\b$re\b/; 912 913 foreach (@nums) { 914 ok $_ =~ /$re/, "Trie nums"; 915 } 916 917 $_ = join " ", @nums; 918 @got = (); 919 push @got, $1 while /$re/g; 920 921 my %count; 922 $count {$_} ++ for @got; 923 my $ok = 1; 924 for (@nums) { 925 $ok = 0 if --$count {$_} < 0; 926 } 927 ok $ok, "Trie min count matches"; 928 } 929 930 { 931 # TRIE related 932 # LATIN SMALL/CAPITAL LETTER A WITH MACRON 933 ok "foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i && 934 $1 eq "\x{101}foo", 935 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON"; 936 937 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW 938 ok "foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i && 939 $1 eq "\x{1E01}foo", 940 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW"; 941 942 # DESERET SMALL/CAPITAL LETTER LONG I 943 ok "foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i && 944 $1 eq "\x{10428}foo", 945 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I"; 946 947 # LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X' 948 ok "foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i && 949 $1 eq "\x{1E01}xfoo", 950 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'"; 951 952 use charnames ':full'; 953 954 my $s = "\N{LATIN SMALL LETTER SHARP S}"; 955 ok "foba ba$s" =~ qr/(foo|Ba$s|bar)/i && $1 eq "ba$s", 956 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss"; 957 ok "foba ba$s" =~ qr/(Ba$s|foo|bar)/i && $1 eq "ba$s", 958 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss"; 959 ok "foba ba$s" =~ qr/(foo|bar|Ba$s)/i && $1 eq "ba$s", 960 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss"; 961 962 ok "foba ba$s" =~ qr/(foo|Bass|bar)/i && $1 eq "ba$s", 963 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss"; 964 965 ok "foba ba$s" =~ qr/(foo|BaSS|bar)/i && $1 eq "ba$s", 966 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS"; 967 968 ok "foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i 969 && $1 eq "ba${s}pxySS$s$s", 970 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S"; 971 } 972 973 { 974 BEGIN { 975 unshift @INC, 'lib'; 976 } 977 use Cname; 978 979 ok 'fooB' =~ /\N{foo}[\N{B}\N{b}]/, "Passthrough charname"; 980 my $name = "foo\xDF"; 981 my $result = eval "'A${name}B' =~ /^A\\N{$name}B\$/"; 982 ok !$@ && $result, "Passthrough charname of non-ASCII, Latin1"; 983 # 984 # Why doesn't must_warn work here? 985 # 986 my $w; 987 local $SIG {__WARN__} = sub {$w .= "@_"}; 988 eval 'q(xxWxx) =~ /[\N{WARN}]/'; 989 ok $w && $w =~ /Using just the first character returned by \\N\{} in character class/, 990 "single character in [\\N{}] warning"; 991 992 undef $w; 993 eval q [ok "\0" !~ /[\N{EMPTY-STR}XY]/, 994 "Zerolength charname in charclass doesn't match \\\\0"]; 995 ok $w && $w =~ /Ignoring zero length/, 996 'Ignoring zero length \N{} in character class warning'; 997 undef $w; 998 eval q [ok 'xy' =~ /x[\N{EMPTY-STR} y]/x, 999 'Empty string charname in [] is ignored; finds a following character']; 1000 ok $w && $w =~ /Ignoring zero length/, 1001 'Ignoring zero length \N{} in character class warning'; 1002 undef $w; 1003 eval q [ok 'x ' =~ /x[\N{EMPTY-STR} y]/, 1004 'Empty string charname in [] is ignored; finds a following blank under /x']; 1005 ok $w && $w =~ /Ignoring zero length/, 1006 'Ignoring zero length \N{} in character class warning'; 1007 1008 ok 'AB' =~ /(\N{EVIL})/ && $1 eq 'A', 'Charname caching $1'; 1009 ok 'ABC' =~ /(\N{EVIL})/, 'Charname caching $1'; 1010 ok 'xy' =~ /x\N{EMPTY-STR}y/, 1011 'Empty string charname produces NOTHING node'; 1012 ok '' =~ /\N{EMPTY-STR}/, 1013 'Empty string charname produces NOTHING node'; 1014 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/, 'Verify that long string works'; 1015 ok "\N{LONG-STR}" =~ /^\N{LONG-STR}$/i, 'Verify under folding that long string works'; 1016 1017 eval '/(?[[\N{EMPTY-STR}]])/'; 1018 ok $@ && $@ =~ /Zero length \\N\{}/; 1019 1020 undef $w; 1021 eval q [is("\N{TOO MANY SPACES}", "TOO MANY SPACES", "Multiple spaces in character name works")]; 1022 like ($w, qr/A sequence of multiple spaces in a charnames alias definition is deprecated/, "... but returns a deprecation warning"); 1023 eval q [use utf8; is("\N{TOO MANY SPACES}", "TOO MANY SPACES", "Same under 'use utf8': they work")]; 1024 like ($w, qr/A sequence of multiple spaces in a charnames alias definition is deprecated/, "... but return a deprecation warning"); 1025 { 1026 no warnings 'deprecated'; 1027 undef $w; 1028 eval q ["\N{TOO MANY SPACES}"]; 1029 ok (! defined $w, "... and no warning if warnings are off"); 1030 eval q [use utf8; "\N{TOO MANY SPACES}"]; 1031 ok (! defined $w, "... same under 'use utf8'"); 1032 } 1033 1034 undef $w; 1035 eval q [is("\N{TRAILING SPACE }", "TRAILING SPACE ", "Trailing space in character name works")]; 1036 like ($w, qr/Trailing white-space in a charnames alias definition is deprecated/, "... but returns a deprecation warning"); 1037 eval q [use utf8; is("\N{TRAILING SPACE }", "TRAILING SPACE ", "Same under 'use utf8': they work")]; 1038 like ($w, qr/Trailing white-space in a charnames alias definition is deprecated/, "... but returns a deprecation warning"); 1039 { 1040 no warnings 'deprecated'; 1041 undef $w; 1042 eval q ["\N{TRAILING SPACE }"]; 1043 ok (! defined $w, "... and no warning if warnings are off"); 1044 eval q [use utf8; "\N{TRAILING SPACE }"]; 1045 ok (! defined $w, "... same under 'use utf8'"); 1046 } 1047 1048 # If remove the limitation in regcomp code these should work 1049 # differently 1050 undef $w; 1051 eval q [ok "\N{TOO-LONG-STR}" =~ /^\N{TOO-LONG-STR}$/, 'Verify that what once was too long a string works']; 1052 eval 'q(syntax error) =~ /\N{MALFORMED}/'; 1053 ok $@ && $@ =~ /Malformed/, 'Verify that malformed utf8 gives an error'; 1054 eval 'q() =~ /\N{4F}/'; 1055 ok $@ && $@ =~ /Invalid character/, 'Verify that leading digit in name gives error'; 1056 eval 'q() =~ /\N{COM,MA}/'; 1057 ok $@ && $@ =~ /Invalid character/, 'Verify that comma in name gives error'; 1058 $name = "A\x{D7}O"; 1059 eval "q(W) =~ /\\N{$name}/"; 1060 ok $@ && $@ =~ /Invalid character/, 'Verify that latin1 symbol in name gives error'; 1061 my $utf8_name = "7 CITIES OF GOLD"; 1062 utf8::upgrade($utf8_name); 1063 eval "use utf8; q(W) =~ /\\N{$utf8_name}/"; 1064 ok $@ && $@ =~ /Invalid character/, 'Verify that leading digit in utf8 name gives error'; 1065 $utf8_name = "SHARP #"; 1066 utf8::upgrade($utf8_name); 1067 eval "use utf8; q(W) =~ /\\N{$utf8_name}/"; 1068 ok $@ && $@ =~ /Invalid character/, 'Verify that ASCII symbol in utf8 name gives error'; 1069 $utf8_name = "A HOUSE \xF7 AGAINST ITSELF"; 1070 utf8::upgrade($utf8_name); 1071 eval "use utf8; q(W) =~ /\\N{$utf8_name}/"; 1072 ok $@ && $@ =~ /Invalid character/, 'Verify that latin1 symbol in utf8 name gives error'; 1073 $utf8_name = "\x{664} HORSEMEN}"; 1074 eval "use utf8; q(W) =~ /\\N{$utf8_name}/"; 1075 ok $@ && $@ =~ /Invalid character/, 'Verify that leading above Latin1 digit in utf8 name gives error'; 1076 $utf8_name = "A \x{1F4A9} WOULD SMELL AS SWEET}"; 1077 eval "use utf8; q(W) =~ /\\N{$utf8_name}/"; 1078 ok $@ && $@ =~ /Invalid character/, 'Verify that above Latin1 symbol in utf8 name gives error'; 1079 1080 undef $w; 1081 $name = "A\x{D1}O"; 1082 eval "q(W) =~ /\\N{$name}/"; 1083 ok ! $w, 'Verify that latin1 letter in name doesnt give warning'; 1084 1085 # This tests the code path that restarts the parse when the recursive 1086 # call to S_reg() from within S_grok_bslash_N() discovers that the 1087 # pattern needs to be recalculated as UTF-8. use eval to avoid 1088 # needing literal Unicode in this source file: 1089 my $r = eval "qr/\\N{\x{100}\x{100}}/"; 1090 isnt $r, undef, "Generated regex for multi-char UTF-8 charname" 1091 or diag($@); 1092 ok "\x{100}\x{100}" =~ $r, "which matches"; 1093 } 1094 1095 { 1096 use charnames ':full'; 1097 1098 ok 'aabc' !~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against aabc'; 1099 ok 'a+bc' =~ /a\N{PLUS SIGN}b/, '/a\N{PLUS SIGN}b/ against a+bc'; 1100 1101 ok ' A B' =~ /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/, 1102 'Intermixed named and unicode escapes'; 1103 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~ 1104 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/, 1105 'Intermixed named and unicode escapes'; 1106 ok "\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}" =~ 1107 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/, 1108 'Intermixed named and unicode escapes'; 1109 ok "\0" =~ /^\N{NULL}$/, 'Verify that \N{NULL} works; is not confused with an error'; 1110 } 1111 1112 { 1113 our $brackets; 1114 $brackets = qr{ 1115 { (?> [^{}]+ | (??{ $brackets }) )* } 1116 }x; 1117 1118 ok "{b{c}d" !~ m/^((??{ $brackets }))/, "Bracket mismatch"; 1119 1120 SKIP: { 1121 our @stack = (); 1122 my @expect = qw( 1123 stuff1 1124 stuff2 1125 <stuff1>and<stuff2> 1126 right 1127 <right> 1128 <<right>> 1129 <<<right>>> 1130 <<stuff1>and<stuff2>><<<<right>>>> 1131 ); 1132 1133 local $_ = '<<<stuff1>and<stuff2>><<<<right>>>>>'; 1134 ok /^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/, 1135 "Recursion matches"; 1136 is(@stack, @expect, "Right amount of matches") 1137 or skip "Won't test individual results as count isn't equal", 1138 0 + @expect; 1139 my $idx = 0; 1140 foreach my $expect (@expect) { 1141 is($stack [$idx], $expect, 1142 "Expecting '$expect' at stack pos #$idx"); 1143 $idx ++; 1144 } 1145 } 1146 } 1147 1148 { 1149 my $s = '123453456'; 1150 $s =~ s/(?<digits>\d+)\k<digits>/$+{digits}/; 1151 ok $s eq '123456', 'Named capture (angle brackets) s///'; 1152 $s = '123453456'; 1153 $s =~ s/(?'digits'\d+)\k'digits'/$+{digits}/; 1154 ok $s eq '123456', 'Named capture (single quotes) s///'; 1155 } 1156 1157 { 1158 my @ary = ( 1159 pack('U', 0x00F1), # n-tilde 1160 '_'.pack('U', 0x00F1), # _ + n-tilde 1161 'c'.pack('U', 0x0327), # c + cedilla 1162 pack('U*', 0x00F1, 0x0327), # n-tilde + cedilla 1163 pack('U', 0x0391), # ALPHA 1164 pack('U', 0x0391).'2', # ALPHA + 2 1165 pack('U', 0x0391).'_', # ALPHA + _ 1166 ); 1167 1168 for my $uni (@ary) { 1169 my ($r1, $c1, $r2, $c2) = eval qq { 1170 use utf8; 1171 scalar ("..foo foo.." =~ /(?'${uni}'foo) \\k'${uni}'/), 1172 \$+{${uni}}, 1173 scalar ("..bar bar.." =~ /(?<${uni}>bar) \\k<${uni}>/), 1174 \$+{${uni}}; 1175 }; 1176 ok $r1, "Named capture UTF (?'')"; 1177 ok defined $c1 && $c1 eq 'foo', "Named capture UTF \%+"; 1178 ok $r2, "Named capture UTF (?<>)"; 1179 ok defined $c2 && $c2 eq 'bar', "Named capture UTF \%+"; 1180 } 1181 } 1182 1183 { 1184 my $s = 'foo bar baz'; 1185 my @res; 1186 if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) { 1187 foreach my $name (sort keys(%-)) { 1188 my $ary = $- {$name}; 1189 foreach my $idx (0 .. $#$ary) { 1190 push @res, "$name:$idx:$ary->[$idx]"; 1191 } 1192 } 1193 } 1194 my @expect = qw (A:0:1 A:1:3 B:0:2 B:1:4); 1195 is("@res", "@expect", "Check %-"); 1196 eval' 1197 no warnings "uninitialized"; 1198 print for $- {this_key_doesnt_exist}; 1199 '; 1200 ok !$@,'lvalue $- {...} should not throw an exception'; 1201 } 1202 1203 { 1204 # \, breaks {3,4} 1205 ok "xaaay" !~ /xa{3\,4}y/, '\, in a pattern'; 1206 ok "xa{3,4}y" =~ /xa{3\,4}y/, '\, in a pattern'; 1207 1208 # \c\ followed by _ 1209 ok "x\c_y" !~ /x\c\_y/, '\_ in a pattern'; 1210 ok "x\c\_y" =~ /x\c\_y/, '\_ in a pattern'; 1211 1212 # \c\ followed by other characters 1213 for my $c ("z", "\0", "!", chr(254), chr(256)) { 1214 my $targ = "a\034$c"; 1215 my $reg = "a\\c\\$c"; 1216 ok eval ("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern"; 1217 } 1218 } 1219 1220 { # Test the (*PRUNE) pattern 1221 our $count = 0; 1222 'aaab' =~ /a+b?(?{$count++})(*FAIL)/; 1223 is($count, 9, "Expect 9 for no (*PRUNE)"); 1224 $count = 0; 1225 'aaab' =~ /a+b?(*PRUNE)(?{$count++})(*FAIL)/; 1226 is($count, 3, "Expect 3 with (*PRUNE)"); 1227 local $_ = 'aaab'; 1228 $count = 0; 1229 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g; 1230 is($count, 4, "/.(*PRUNE)/"); 1231 $count = 0; 1232 'aaab' =~ /a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/; 1233 is($count, 3, "Expect 3 with (*PRUNE)"); 1234 local $_ = 'aaab'; 1235 $count = 0; 1236 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g; 1237 is($count, 4, "/.(*PRUNE)/"); 1238 } 1239 1240 { # Test the (*SKIP) pattern 1241 our $count = 0; 1242 'aaab' =~ /a+b?(*SKIP)(?{$count++})(*FAIL)/; 1243 is($count, 1, "Expect 1 with (*SKIP)"); 1244 local $_ = 'aaab'; 1245 $count = 0; 1246 1 while /.(*SKIP)(?{$count++})(*FAIL)/g; 1247 is($count, 4, "/.(*SKIP)/"); 1248 $_ = 'aaabaaab'; 1249 $count = 0; 1250 our @res = (); 1251 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g; 1252 is($count, 2, "Expect 2 with (*SKIP)"); 1253 is("@res", "aaab aaab", "Adjacent (*SKIP) works as expected"); 1254 } 1255 1256 { # Test the (*SKIP) pattern 1257 our $count = 0; 1258 'aaab' =~ /a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/; 1259 is($count, 1, "Expect 1 with (*SKIP)"); 1260 local $_ = 'aaab'; 1261 $count = 0; 1262 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g; 1263 is($count, 4, "/.(*SKIP)/"); 1264 $_ = 'aaabaaab'; 1265 $count = 0; 1266 our @res = (); 1267 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g; 1268 is($count, 2, "Expect 2 with (*SKIP)"); 1269 is("@res", "aaab aaab", "Adjacent (*SKIP) works as expected"); 1270 } 1271 1272 { # Test the (*SKIP) pattern 1273 our $count = 0; 1274 'aaab' =~ /a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/; 1275 is($count, 3, "Expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)"); 1276 local $_ = 'aaabaaab'; 1277 $count = 0; 1278 our @res = (); 1279 1 while 1280 /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g; 1281 is($count, 5, "Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)"); 1282 is("@res", "aaab b aaab b ", 1283 "Adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected"); 1284 } 1285 1286 { # Test the (*COMMIT) pattern 1287 our $count = 0; 1288 'aaabaaab' =~ /a+b?(*COMMIT)(?{$count++})(*FAIL)/; 1289 is($count, 1, "Expect 1 with (*COMMIT)"); 1290 local $_ = 'aaab'; 1291 $count = 0; 1292 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g; 1293 is($count, 1, "/.(*COMMIT)/"); 1294 $_ = 'aaabaaab'; 1295 $count = 0; 1296 our @res = (); 1297 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g; 1298 is($count, 1, "Expect 1 with (*COMMIT)"); 1299 is("@res", "aaab", "Adjacent (*COMMIT) works as expected"); 1300 } 1301 1302 { 1303 # Test named commits and the $REGERROR var 1304 our $REGERROR; 1305 for my $name ('', ':foo') { 1306 for my $pat ("(*PRUNE$name)", 1307 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)", 1308 "(*COMMIT$name)") { 1309 for my $suffix ('(*FAIL)', '') { 1310 'aaaab' =~ /a+b$pat$suffix/; 1311 is($REGERROR, 1312 ($suffix ? ($name ? 'foo' : "1") : ""), 1313 "Test $pat and \$REGERROR $suffix"); 1314 } 1315 } 1316 } 1317 } 1318 1319 { 1320 # Test named commits and the $REGERROR var 1321 package Fnorble; 1322 our $REGERROR; 1323 for my $name ('', ':foo') { 1324 for my $pat ("(*PRUNE$name)", 1325 ($name ? "(*MARK$name)" : "") . "(*SKIP$name)", 1326 "(*COMMIT$name)") { 1327 for my $suffix ('(*FAIL)','') { 1328 'aaaab' =~ /a+b$pat$suffix/; 1329 ::is($REGERROR, 1330 ($suffix ? ($name ? 'foo' : "1") : ""), 1331 "Test $pat and \$REGERROR $suffix"); 1332 } 1333 } 1334 } 1335 } 1336 1337 { 1338 # Test named commits and the $REGERROR var 1339 my $message = '$REGERROR'; 1340 our $REGERROR; 1341 for my $word (qw (bar baz bop)) { 1342 $REGERROR = ""; 1343 "aaaaa$word" =~ 1344 /a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/; 1345 is($REGERROR, $word, $message); 1346 } 1347 } 1348 1349 { 1350 #Mindnumbingly simple test of (*THEN) 1351 for ("ABC","BAX") { 1352 ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test"; 1353 } 1354 } 1355 1356 { 1357 my $message = "Relative Recursion"; 1358 my $parens = qr/(\((?:[^()]++|(?-1))*+\))/; 1359 local $_ = 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))'; 1360 my ($all, $one, $two) = ('', '', ''); 1361 ok(m/foo $parens \s* \+ \s* bar $parens/x, $message); 1362 is($1, '((2*3)+4-3)', $message); 1363 is($2, '(2*(3+4)-1*(2-3))', $message); 1364 is($&, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))', $message); 1365 is($&, $_, $message); 1366 } 1367 1368 { 1369 my $spaces=" "; 1370 local $_ = join 'bar', $spaces, $spaces; 1371 our $count = 0; 1372 s/(?>\s+bar)(?{$count++})//g; 1373 is($_, $spaces, "SUSPEND final string"); 1374 is($count, 1, "Optimiser should have prevented more than one match"); 1375 } 1376 1377 { 1378 # From Message-ID: <877ixs6oa6.fsf@k75.linux.bogus> 1379 my $dow_name = "nada"; 1380 my $parser = "(\$dow_name) = \$time_string =~ /(D\x{e9}\\ " . 1381 "C\x{e9}adaoin|D\x{e9}\\ Sathairn|\\w+|\x{100})/"; 1382 my $time_string = "D\x{e9} C\x{e9}adaoin"; 1383 eval $parser; 1384 ok !$@, "Test Eval worked"; 1385 is($dow_name, $time_string, "UTF-8 trie common prefix extraction"); 1386 } 1387 1388 { 1389 my $v; 1390 ($v = 'bar') =~ /(\w+)/g; 1391 $v = 'foo'; 1392 is("$1", 'bar', 1393 '$1 is safe after /g - may fail due to specialized config in pp_hot.c'); 1394 } 1395 1396 { 1397 my $message = "http://nntp.perl.org/group/perl.perl5.porters/118663"; 1398 my $qr_barR1 = qr/(bar)\g-1/; 1399 like("foobarbarxyz", $qr_barR1, $message); 1400 like("foobarbarxyz", qr/foo${qr_barR1}xyz/, $message); 1401 like("foobarbarxyz", qr/(foo)${qr_barR1}xyz/, $message); 1402 like("foobarbarxyz", qr/(foo)(bar)\g{-1}xyz/, $message); 1403 like("foobarbarxyz", qr/(foo${qr_barR1})xyz/, $message); 1404 like("foobarbarxyz", qr/(foo(bar)\g{-1})xyz/, $message); 1405 } 1406 1407 { 1408 my $message = '$REGMARK'; 1409 our @r = (); 1410 our ($REGMARK, $REGERROR); 1411 like('foofoo', qr/foo (*MARK:foo) (?{push @r,$REGMARK}) /x, $message); 1412 is("@r","foo", $message); 1413 is($REGMARK, "foo", $message); 1414 unlike('foofoo', qr/foo (*MARK:foo) (*FAIL) /x, $message); 1415 is($REGMARK, '', $message); 1416 is($REGERROR, 'foo', $message); 1417 } 1418 1419 { 1420 my $message = '\K test'; 1421 my $x; 1422 $x = "abc.def.ghi.jkl"; 1423 $x =~ s/.*\K\..*//; 1424 is($x, "abc.def.ghi", $message); 1425 1426 $x = "one two three four"; 1427 $x =~ s/o+ \Kthree//g; 1428 is($x, "one two four", $message); 1429 1430 $x = "abcde"; 1431 $x =~ s/(.)\K/$1/g; 1432 is($x, "aabbccddee", $message); 1433 } 1434 1435 { 1436 sub kt { 1437 return '4' if $_[0] eq '09028623'; 1438 } 1439 # Nested EVAL using PL_curpm (via $1 or friends) 1440 my $re; 1441 our $grabit = qr/ ([0-6][0-9]{7}) (??{ kt $1 }) [890] /x; 1442 $re = qr/^ ( (??{ $grabit }) ) $ /x; 1443 my @res = '0902862349' =~ $re; 1444 is(join ("-", @res), "0902862349", 1445 'PL_curpm is set properly on nested eval'); 1446 1447 our $qr = qr/ (o) (??{ $1 }) /x; 1448 ok 'boob'=~/( b (??{ $qr }) b )/x && 1, "PL_curpm, nested eval"; 1449 } 1450 1451 { 1452 use charnames ":full"; 1453 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "I =~ Alphabetic"; 1454 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/, "I =~ Uppercase"; 1455 ok "\N{ROMAN NUMERAL ONE}" !~ /\p{Lowercase}/, "I !~ Lowercase"; 1456 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "I =~ ID_Start"; 1457 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "I =~ ID_Continue"; 1458 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Alphabetic}/, "i =~ Alphabetic"; 1459 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Uppercase}/, "i !~ Uppercase"; 1460 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Uppercase}/i, "i =~ Uppercase under /i"; 1461 ok "\N{SMALL ROMAN NUMERAL ONE}" !~ /\p{Titlecase}/, "i !~ Titlecase"; 1462 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Titlecase}/i, "i =~ Titlecase under /i"; 1463 ok "\N{ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/i, "I =~ Lowercase under /i"; 1464 1465 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{Lowercase}/, "i =~ Lowercase"; 1466 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDStart}/, "i =~ ID_Start"; 1467 ok "\N{SMALL ROMAN NUMERAL ONE}" =~ /\p{IDContinue}/, "i =~ ID_Continue" 1468 } 1469 1470 { # More checking that /i works on the few properties that it makes a 1471 # difference. Uppercase, Lowercase, and Titlecase were done in the 1472 # block above 1473 ok "A" =~ /\p{PosixUpper}/, "A =~ PosixUpper"; 1474 ok "A" =~ /\p{PosixUpper}/i, "A =~ PosixUpper under /i"; 1475 ok "A" !~ /\p{PosixLower}/, "A !~ PosixLower"; 1476 ok "A" =~ /\p{PosixLower}/i, "A =~ PosixLower under /i"; 1477 ok "a" !~ /\p{PosixUpper}/, "a !~ PosixUpper"; 1478 ok "a" =~ /\p{PosixUpper}/i, "a =~ PosixUpper under /i"; 1479 ok "a" =~ /\p{PosixLower}/, "a =~ PosixLower"; 1480 ok "a" =~ /\p{PosixLower}/i, "a =~ PosixLower under /i"; 1481 1482 ok "\xC0" =~ /\p{XPosixUpper}/, "\\xC0 =~ XPosixUpper"; 1483 ok "\xC0" =~ /\p{XPosixUpper}/i, "\\xC0 =~ XPosixUpper under /i"; 1484 ok "\xC0" !~ /\p{XPosixLower}/, "\\xC0 !~ XPosixLower"; 1485 ok "\xC0" =~ /\p{XPosixLower}/i, "\\xC0 =~ XPosixLower under /i"; 1486 ok "\xE0" !~ /\p{XPosixUpper}/, "\\xE0 !~ XPosixUpper"; 1487 ok "\xE0" =~ /\p{XPosixUpper}/i, "\\xE0 =~ XPosixUpper under /i"; 1488 ok "\xE0" =~ /\p{XPosixLower}/, "\\xE0 =~ XPosixLower"; 1489 ok "\xE0" =~ /\p{XPosixLower}/i, "\\xE0 =~ XPosixLower under /i"; 1490 1491 ok "\xC0" =~ /\p{UppercaseLetter}/, "\\xC0 =~ UppercaseLetter"; 1492 ok "\xC0" =~ /\p{UppercaseLetter}/i, "\\xC0 =~ UppercaseLetter under /i"; 1493 ok "\xC0" !~ /\p{LowercaseLetter}/, "\\xC0 !~ LowercaseLetter"; 1494 ok "\xC0" =~ /\p{LowercaseLetter}/i, "\\xC0 =~ LowercaseLetter under /i"; 1495 ok "\xC0" !~ /\p{TitlecaseLetter}/, "\\xC0 !~ TitlecaseLetter"; 1496 ok "\xC0" =~ /\p{TitlecaseLetter}/i, "\\xC0 =~ TitlecaseLetter under /i"; 1497 ok "\xE0" !~ /\p{UppercaseLetter}/, "\\xE0 !~ UppercaseLetter"; 1498 ok "\xE0" =~ /\p{UppercaseLetter}/i, "\\xE0 =~ UppercaseLetter under /i"; 1499 ok "\xE0" =~ /\p{LowercaseLetter}/, "\\xE0 =~ LowercaseLetter"; 1500 ok "\xE0" =~ /\p{LowercaseLetter}/i, "\\xE0 =~ LowercaseLetter under /i"; 1501 ok "\xE0" !~ /\p{TitlecaseLetter}/, "\\xE0 !~ TitlecaseLetter"; 1502 ok "\xE0" =~ /\p{TitlecaseLetter}/i, "\\xE0 =~ TitlecaseLetter under /i"; 1503 ok "\x{1C5}" !~ /\p{UppercaseLetter}/, "\\x{1C5} !~ UppercaseLetter"; 1504 ok "\x{1C5}" =~ /\p{UppercaseLetter}/i, "\\x{1C5} =~ UppercaseLetter under /i"; 1505 ok "\x{1C5}" !~ /\p{LowercaseLetter}/, "\\x{1C5} !~ LowercaseLetter"; 1506 ok "\x{1C5}" =~ /\p{LowercaseLetter}/i, "\\x{1C5} =~ LowercaseLetter under /i"; 1507 ok "\x{1C5}" =~ /\p{TitlecaseLetter}/, "\\x{1C5} =~ TitlecaseLetter"; 1508 ok "\x{1C5}" =~ /\p{TitlecaseLetter}/i, "\\x{1C5} =~ TitlecaseLetter under /i"; 1509 } 1510 1511 { 1512 # requirement of Unicode Technical Standard #18, 1.7 Code Points 1513 # cf. http://www.unicode.org/reports/tr18/#Supplementary_Characters 1514 for my $u (0x7FF, 0x800, 0xFFFF, 0x10000) { 1515 no warnings 'utf8'; # oops 1516 my $c = chr $u; 1517 my $x = sprintf '%04X', $u; 1518 ok "A${c}B" =~ /A[\0-\x{10000}]B/, "Unicode range - $x"; 1519 } 1520 } 1521 1522 { 1523 my $res=""; 1524 1525 if ('1' =~ /(?|(?<digit>1)|(?<digit>2))/) { 1526 $res = "@{$- {digit}}"; 1527 } 1528 is($res, "1", 1529 "Check that (?|...) doesnt cause dupe entries in the names array"); 1530 1531 $res = ""; 1532 if ('11' =~ /(?|(?<digit>1)|(?<digit>2))(?&digit)/) { 1533 $res = "@{$- {digit}}"; 1534 } 1535 is($res, "1", 1536 "Check that (?&..) to a buffer inside a (?|...) goes to the leftmost"); 1537 } 1538 1539 { 1540 use warnings; 1541 my $message = "ASCII pattern that really is UTF-8"; 1542 my @w; 1543 local $SIG {__WARN__} = sub {push @w, "@_"}; 1544 my $c = qq (\x{DF}); 1545 like($c, qr/${c}|\x{100}/, $message); 1546 is("@w", '', $message); 1547 } 1548 1549 { 1550 my $message = "Corruption of match results of qr// across scopes"; 1551 my $qr = qr/(fo+)(ba+r)/; 1552 'foobar' =~ /$qr/; 1553 is("$1$2", "foobar", $message); 1554 { 1555 'foooooobaaaaar' =~ /$qr/; 1556 is("$1$2", 'foooooobaaaaar', $message); 1557 } 1558 is("$1$2", "foobar", $message); 1559 } 1560 1561 { 1562 my $message = "HORIZWS"; 1563 local $_ = "\t \r\n \n \t".chr(11)."\n"; 1564 s/\H/H/g; 1565 s/\h/h/g; 1566 is($_, "hhHHhHhhHH", $message); 1567 $_ = "\t \r\n \n \t" . chr (11) . "\n"; 1568 utf8::upgrade ($_); 1569 s/\H/H/g; 1570 s/\h/h/g; 1571 is($_, "hhHHhHhhHH", $message); 1572 } 1573 1574 { 1575 # Various whitespace special patterns 1576 my @h = map {chr $_} 0x09, 0x20, 0xa0, 0x1680, 0x180e, 0x2000, 1577 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 1578 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f, 1579 0x3000; 1580 my @v = map {chr $_} 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028, 1581 0x2029; 1582 my @lb = ("\x0D\x0A", map {chr $_} 0x0A .. 0x0D, 0x85, 0x2028, 0x2029); 1583 foreach my $t ([\@h, qr/\h/, qr/\h+/], 1584 [\@v, qr/\v/, qr/\v+/], 1585 [\@lb, qr/\R/, qr/\R+/],) { 1586 my $ary = shift @$t; 1587 foreach my $pat (@$t) { 1588 foreach my $str (@$ary) { 1589 my $temp_str = $str; 1590 $temp_str = display($temp_str); 1591 ok $str =~ /($pat)/, $temp_str . " =~ /($pat)"; 1592 my $temp_1 = $1; 1593 is($1, $str, "\$1='" . display($temp_1) . "' eq '" . $temp_str . "' after ($pat)"); 1594 utf8::upgrade ($str); 1595 ok $str =~ /($pat)/, "Upgraded " . $temp_str . " =~ /($pat)/"; 1596 is($1, $str, "\$1='" . display($temp_1) . "' eq '" . $temp_str . "'(upgraded) after ($pat)"); 1597 } 1598 } 1599 } 1600 } 1601 1602 { 1603 # Check that \\xDF match properly in its various forms 1604 # Test that \xDF matches properly. this is pretty hacky stuff, 1605 # but its actually needed. The malarky with '-' is to prevent 1606 # compilation caching from playing any role in the test. 1607 my @df = (chr (0xDF), '-', chr (0xDF)); 1608 utf8::upgrade ($df [2]); 1609 my @strs = ('ss', 'sS', 'Ss', 'SS', chr (0xDF)); 1610 my @ss = map {("$_", "$_")} @strs; 1611 utf8::upgrade ($ss [$_ * 2 + 1]) for 0 .. $#strs; 1612 1613 for my $ssi (0 .. $#ss) { 1614 for my $dfi (0 .. $#df) { 1615 my $pat = $df [$dfi]; 1616 my $str = $ss [$ssi]; 1617 my $utf_df = ($dfi > 1) ? 'utf8' : ''; 1618 my $utf_ss = ($ssi % 2) ? 'utf8' : ''; 1619 (my $sstr = $str) =~ s/\xDF/\\xDF/; 1620 1621 if ($utf_df || $utf_ss || length ($ss [$ssi]) == 1) { 1622 my $ret = $str =~ /$pat/i; 1623 next if $pat eq '-'; 1624 ok $ret, "\"$sstr\" =~ /\\xDF/i " . 1625 "(str is @{[$utf_ss||'latin']}, pat is " . 1626 "@{[$utf_df||'latin']})"; 1627 } 1628 else { 1629 my $ret = $str !~ /$pat/i; 1630 next if $pat eq '-'; 1631 ok $ret, "\"$sstr\" !~ /\\xDF/i " . 1632 "(str is @{[$utf_ss||'latin']}, pat is " . 1633 "@{[$utf_df||'latin']})"; 1634 } 1635 } 1636 } 1637 } 1638 1639 { 1640 my $message = "BBC(Bleadperl Breaks CPAN) Today: String::Multibyte"; 1641 my $re = qr/(?:[\x00-\xFF]{4})/; 1642 my $hyp = "\0\0\0-"; 1643 my $esc = "\0\0\0\\"; 1644 1645 my $str = "$esc$hyp$hyp$esc$esc"; 1646 my @a = ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g); 1647 1648 is(@a,3, $message); 1649 local $" = "="; 1650 is("@a","$esc$hyp=$hyp=$esc$esc", $message); 1651 } 1652 1653 { 1654 # Test for keys in %+ and %- 1655 my $message = 'Test keys in %+ and %-'; 1656 no warnings 'uninitialized', 'deprecated', 'experimental::lexical_topic'; 1657 my $_ = "abcdef"; 1658 /(?<foo>a)|(?<foo>b)/; 1659 is((join ",", sort keys %+), "foo", $message); 1660 is((join ",", sort keys %-), "foo", $message); 1661 is((join ",", sort values %+), "a", $message); 1662 is((join ",", sort map "@$_", values %-), "a ", $message); 1663 /(?<bar>a)(?<bar>b)(?<quux>.)/; 1664 is((join ",", sort keys %+), "bar,quux", $message); 1665 is((join ",", sort keys %-), "bar,quux", $message); 1666 is((join ",", sort values %+), "a,c", $message); # leftmost 1667 is((join ",", sort map "@$_", values %-), "a b,c", $message); 1668 /(?<un>a)(?<deux>c)?/; # second buffer won't capture 1669 is((join ",", sort keys %+), "un", $message); 1670 is((join ",", sort keys %-), "deux,un", $message); 1671 is((join ",", sort values %+), "a", $message); 1672 is((join ",", sort map "@$_", values %-), ",a", $message); 1673 } 1674 1675 { 1676 # length() on captures, the numbered ones end up in Perl_magic_len 1677 no warnings 'deprecated', 'experimental::lexical_topic'; 1678 my $_ = "aoeu \xe6var ook"; 1679 /^ \w+ \s (?<eek>\S+)/x; 1680 1681 is(length $`, 0, q[length $`]); 1682 is(length $', 4, q[length $']); 1683 is(length $&, 9, q[length $&]); 1684 is(length $1, 4, q[length $1]); 1685 is(length $+{eek}, 4, q[length $+{eek} == length $1]); 1686 } 1687 1688 { 1689 my $ok = -1; 1690 1691 $ok = exists ($-{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/; 1692 is($ok, 1, '$-{x} exists after "bar"=~/(?<x>foo)|bar/'); 1693 is(scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/'); 1694 is(scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/'); 1695 1696 $ok = -1; 1697 $ok = exists ($+{x}) ? 1 : 0 if 'bar' =~ /(?<x>foo)|bar/; 1698 is($ok, 0, '$+{x} not exists after "bar"=~/(?<x>foo)|bar/'); 1699 is(scalar (%+), 0, 'scalar %+ == 0 after "bar"=~/(?<x>foo)|bar/'); 1700 is(scalar (%-), 1, 'scalar %- == 1 after "bar"=~/(?<x>foo)|bar/'); 1701 1702 $ok = -1; 1703 $ok = exists ($-{x}) ? 1 : 0 if 'foo' =~ /(?<x>foo)|bar/; 1704 is($ok, 1, '$-{x} exists after "foo"=~/(?<x>foo)|bar/'); 1705 is(scalar (%+), 1, 'scalar %+ == 1 after "foo"=~/(?<x>foo)|bar/'); 1706 is(scalar (%-), 1, 'scalar %- == 1 after "foo"=~/(?<x>foo)|bar/'); 1707 1708 $ok = -1; 1709 $ok = exists ($+{x}) ? 1 : 0 if 'foo'=~/(?<x>foo)|bar/; 1710 is($ok, 1, '$+{x} exists after "foo"=~/(?<x>foo)|bar/'); 1711 } 1712 1713 { 1714 local $_; 1715 ($_ = 'abc') =~ /(abc)/g; 1716 $_ = '123'; 1717 is("$1", 'abc', "/g leads to unsafe match vars: $1"); 1718 1719 fresh_perl_is(<<'EOP', ">abc<\n", {}, 'mention $&'); 1720$&; 1721my $x; 1722($x='abc')=~/(abc)/g; 1723$x='123'; 1724print ">$1<\n"; 1725EOP 1726 1727 fresh_perl_is(<<'EOP', ">abc<\n", {}, 'no mention of $&'); 1728my $x; 1729($x='abc')=~/(abc)/g; 1730$x='123'; 1731print ">$1<\n"; 1732EOP 1733 } 1734 1735 { 1736 # Message-ID: <20070818091501.7eff4831@r2d2> 1737 my $str = ""; 1738 for (0 .. 5) { 1739 my @x; 1740 $str .= "@x"; # this should ALWAYS be the empty string 1741 'a' =~ /(a|)/; 1742 push @x, 1; 1743 } 1744 is(length $str, 0, "Trie scope error, string should be empty"); 1745 $str = ""; 1746 my @foo = ('a') x 5; 1747 for (@foo) { 1748 my @bar; 1749 $str .= "@bar"; 1750 s/a|/push @bar, 1/e; 1751 } 1752 is(length $str, 0, "Trie scope error, string should be empty"); 1753 } 1754 1755 { 1756# more TRIE/AHOCORASICK problems with mixed utf8 / latin-1 and case folding 1757 for my $chr (160 .. 255) { 1758 my $chr_byte = chr($chr); 1759 my $chr_utf8 = chr($chr); utf8::upgrade($chr_utf8); 1760 my $rx = qr{$chr_byte|X}i; 1761 ok($chr_utf8 =~ $rx, "utf8/latin, codepoint $chr"); 1762 } 1763 } 1764 1765 { 1766 our $a = 3; "" =~ /(??{ $a })/; 1767 our $b = $a; 1768 is($b, $a, "Copy of scalar used for postponed subexpression"); 1769 } 1770 1771 { 1772 our @ctl_n = (); 1773 our @plus = (); 1774 our $nested_tags; 1775 $nested_tags = qr{ 1776 < 1777 (\w+) 1778 (?{ 1779 push @ctl_n,$^N; 1780 push @plus,$+; 1781 }) 1782 > 1783 (??{$nested_tags})* 1784 </\s* \w+ \s*> 1785 }x; 1786 1787 my $match = '<bla><blubb></blubb></bla>' =~ m/^$nested_tags$/; 1788 ok $match, 'nested construct matches'; 1789 is("@ctl_n", "bla blubb", '$^N inside of (?{}) works as expected'); 1790 is("@plus", "bla blubb", '$+ inside of (?{}) works as expected'); 1791 } 1792 1793 SKIP: { 1794 # XXX: This set of tests is essentially broken, POSIX character classes 1795 # should not have differing definitions under Unicode. 1796 # There are property names for that. 1797 skip "Tests assume ASCII", 4 unless $::IS_ASCII; 1798 1799 my @notIsPunct = grep {/[[:punct:]]/ and not /\p{IsPunct}/} 1800 map {chr} 0x20 .. 0x7f; 1801 is(join ('', @notIsPunct), '$+<=>^`|~', 1802 '[:punct:] disagrees with IsPunct on Symbols'); 1803 1804 my @isPrint = grep {not /[[:print:]]/ and /\p{IsPrint}/} 1805 map {chr} 0 .. 0x1f, 0x7f .. 0x9f; 1806 is(join ('', @isPrint), "", 1807 'IsPrint agrees with [:print:] on control characters'); 1808 1809 my @isPunct = grep {/[[:punct:]]/ != /\p{IsPunct}/} 1810 map {chr} 0x80 .. 0xff; 1811 is(join ('', @isPunct), "\xa1\xa7\xab\xb6\xb7\xbb\xbf", # ¡ « · » ¿ 1812 'IsPunct disagrees with [:punct:] outside ASCII'); 1813 1814 my @isPunctLatin1 = eval q { 1815 no warnings 'deprecated'; 1816 use encoding 'latin1'; 1817 grep {/[[:punct:]]/ != /\p{IsPunct}/} map {chr} 0x80 .. 0xff; 1818 }; 1819 skip "Eval failed ($@)", 1 if $@; 1820 skip "PERL_LEGACY_UNICODE_CHARCLASS_MAPPINGS set to 0", 1 1821 if !$ENV{PERL_TEST_LEGACY_POSIX_CC}; 1822 is(join ('', @isPunctLatin1), '', 1823 'IsPunct agrees with [:punct:] with explicit Latin1'); 1824 } 1825 1826 { 1827 # Tests for [#perl 71942] 1828 our $count_a; 1829 our $count_b; 1830 1831 my $c = 0; 1832 for my $re ( 1833# [ 1834# should match?, 1835# input string, 1836# re 1, 1837# re 2, 1838# expected values of count_a and count_b, 1839# ] 1840 [ 1841 0, 1842 "xababz", 1843 qr/a+(?{$count_a++})b?(*COMMIT)(*FAIL)/, 1844 qr/a+(?{$count_b++})b?(*COMMIT)z/, 1845 1, 1846 ], 1847 [ 1848 0, 1849 "xababz", 1850 qr/a+(?{$count_a++})b?(*COMMIT)\s*(*FAIL)/, 1851 qr/a+(?{$count_b++})b?(*COMMIT)\s*z/, 1852 1, 1853 ], 1854 [ 1855 0, 1856 "xababz", 1857 qr/a+(?{$count_a++})(?:b|)?(*COMMIT)(*FAIL)/, 1858 qr/a+(?{$count_b++})(?:b|)?(*COMMIT)z/, 1859 1, 1860 ], 1861 [ 1862 0, 1863 "xababz", 1864 qr/a+(?{$count_a++})b{0,6}(*COMMIT)(*FAIL)/, 1865 qr/a+(?{$count_b++})b{0,6}(*COMMIT)z/, 1866 1, 1867 ], 1868 [ 1869 0, 1870 "xabcabcz", 1871 qr/a+(?{$count_a++})(bc){0,6}(*COMMIT)(*FAIL)/, 1872 qr/a+(?{$count_b++})(bc){0,6}(*COMMIT)z/, 1873 1, 1874 ], 1875 [ 1876 0, 1877 "xabcabcz", 1878 qr/a+(?{$count_a++})(bc*){0,6}(*COMMIT)(*FAIL)/, 1879 qr/a+(?{$count_b++})(bc*){0,6}(*COMMIT)z/, 1880 1, 1881 ], 1882 1883 1884 [ 1885 0, 1886 "aaaabtz", 1887 qr/a+(?{$count_a++})b?(*PRUNE)(*FAIL)/, 1888 qr/a+(?{$count_b++})b?(*PRUNE)z/, 1889 4, 1890 ], 1891 [ 1892 0, 1893 "aaaabtz", 1894 qr/a+(?{$count_a++})b?(*PRUNE)\s*(*FAIL)/, 1895 qr/a+(?{$count_b++})b?(*PRUNE)\s*z/, 1896 4, 1897 ], 1898 [ 1899 0, 1900 "aaaabtz", 1901 qr/a+(?{$count_a++})(?:b|)(*PRUNE)(*FAIL)/, 1902 qr/a+(?{$count_b++})(?:b|)(*PRUNE)z/, 1903 4, 1904 ], 1905 [ 1906 0, 1907 "aaaabtz", 1908 qr/a+(?{$count_a++})b{0,6}(*PRUNE)(*FAIL)/, 1909 qr/a+(?{$count_b++})b{0,6}(*PRUNE)z/, 1910 4, 1911 ], 1912 [ 1913 0, 1914 "aaaabctz", 1915 qr/a+(?{$count_a++})(bc){0,6}(*PRUNE)(*FAIL)/, 1916 qr/a+(?{$count_b++})(bc){0,6}(*PRUNE)z/, 1917 4, 1918 ], 1919 [ 1920 0, 1921 "aaaabctz", 1922 qr/a+(?{$count_a++})(bc*){0,6}(*PRUNE)(*FAIL)/, 1923 qr/a+(?{$count_b++})(bc*){0,6}(*PRUNE)z/, 1924 4, 1925 ], 1926 1927 [ 1928 0, 1929 "aaabaaab", 1930 qr/a+(?{$count_a++;})b?(*SKIP)(*FAIL)/, 1931 qr/a+(?{$count_b++;})b?(*SKIP)z/, 1932 2, 1933 ], 1934 [ 1935 0, 1936 "aaabaaab", 1937 qr/a+(?{$count_a++;})b?(*SKIP)\s*(*FAIL)/, 1938 qr/a+(?{$count_b++;})b?(*SKIP)\s*z/, 1939 2, 1940 ], 1941 [ 1942 0, 1943 "aaabaaab", 1944 qr/a+(?{$count_a++;})(?:b|)(*SKIP)(*FAIL)/, 1945 qr/a+(?{$count_b++;})(?:b|)(*SKIP)z/, 1946 2, 1947 ], 1948 [ 1949 0, 1950 "aaabaaab", 1951 qr/a+(?{$count_a++;})b{0,6}(*SKIP)(*FAIL)/, 1952 qr/a+(?{$count_b++;})b{0,6}(*SKIP)z/, 1953 2, 1954 ], 1955 [ 1956 0, 1957 "aaabcaaabc", 1958 qr/a+(?{$count_a++;})(bc){0,6}(*SKIP)(*FAIL)/, 1959 qr/a+(?{$count_b++;})(bc){0,6}(*SKIP)z/, 1960 2, 1961 ], 1962 [ 1963 0, 1964 "aaabcaaabc", 1965 qr/a+(?{$count_a++;})(bc*){0,6}(*SKIP)(*FAIL)/, 1966 qr/a+(?{$count_b++;})(bc*){0,6}(*SKIP)z/, 1967 2, 1968 ], 1969 1970 1971 [ 1972 0, 1973 "aaddbdaabyzc", 1974 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) (*FAIL) \s* c \1 /x, 1975 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) z \s* c \1 /x, 1976 4, 1977 ], 1978 [ 1979 0, 1980 "aaddbdaabyzc", 1981 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* (*FAIL) \s* c \1 /x, 1982 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b? (*SKIP:T1) \s* z \s* c \1 /x, 1983 4, 1984 ], 1985 [ 1986 0, 1987 "aaddbdaabyzc", 1988 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) (*FAIL) \s* c \1 /x, 1989 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (?:b|) (*SKIP:T1) z \s* c \1 /x, 1990 4, 1991 ], 1992 [ 1993 0, 1994 "aaddbdaabyzc", 1995 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x, 1996 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? b{0,6} (*SKIP:T1) z \s* c \1 /x, 1997 4, 1998 ], 1999 [ 2000 0, 2001 "aaddbcdaabcyzc", 2002 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x, 2003 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc){0,6} (*SKIP:T1) z \s* c \1 /x, 2004 4, 2005 ], 2006 [ 2007 0, 2008 "aaddbcdaabcyzc", 2009 qr/a (?{$count_a++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) (*FAIL) \s* c \1 /x, 2010 qr/a (?{$count_b++;}) (*MARK:T1) (a*) .*? (bc*){0,6} (*SKIP:T1) z \s* c \1 /x, 2011 4, 2012 ], 2013 2014 2015 [ 2016 0, 2017 "aaaaddbdaabyzc", 2018 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x, 2019 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) z \s* c \1 /x, 2020 2, 2021 ], 2022 [ 2023 0, 2024 "aaaaddbdaabyzc", 2025 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* (*FAIL) \s* c \1 /x, 2026 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b? (*MARK:T1) (*SKIP:T1) \s* z \s* c \1 /x, 2027 2, 2028 ], 2029 [ 2030 0, 2031 "aaaaddbdaabyzc", 2032 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x, 2033 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (?:b|) (*MARK:T1) (*SKIP:T1) z \s* c \1 /x, 2034 2, 2035 ], 2036 [ 2037 0, 2038 "aaaaddbdaabyzc", 2039 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x, 2040 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? b{0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x, 2041 2, 2042 ], 2043 [ 2044 0, 2045 "aaaaddbcdaabcyzc", 2046 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x, 2047 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x, 2048 2, 2049 ], 2050 [ 2051 0, 2052 "aaaaddbcdaabcyzc", 2053 qr/a (?{$count_a++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) (*FAIL) \s* c \1 /x, 2054 qr/a (?{$count_b++;}) (a?) (*MARK:T1) (a*) .*? (bc*){0,6} (*MARK:T1) (*SKIP:T1) z \s* c \1 /x, 2055 2, 2056 ], 2057 2058 2059 [ 2060 0, 2061 "AbcdCBefgBhiBqz", 2062 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) (*FAIL)/x, 2063 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) z/x, 2064 1, 2065 ], 2066 [ 2067 0, 2068 "AbcdCBefgBhiBqz", 2069 qr/(A (.*) (?{ $count_a++ }) C? (*THEN) | A D) \s* (*FAIL)/x, 2070 qr/(A (.*) (?{ $count_b++ }) C? (*THEN) | A D) \s* z/x, 2071 1, 2072 ], 2073 [ 2074 0, 2075 "AbcdCBefgBhiBqz", 2076 qr/(A (.*) (?{ $count_a++ }) (?:C|) (*THEN) | A D) (*FAIL)/x, 2077 qr/(A (.*) (?{ $count_b++ }) (?:C|) (*THEN) | A D) z/x, 2078 1, 2079 ], 2080 [ 2081 0, 2082 "AbcdCBefgBhiBqz", 2083 qr/(A (.*) (?{ $count_a++ }) C{0,6} (*THEN) | A D) (*FAIL)/x, 2084 qr/(A (.*) (?{ $count_b++ }) C{0,6} (*THEN) | A D) z/x, 2085 1, 2086 ], 2087 [ 2088 0, 2089 "AbcdCEBefgBhiBqz", 2090 qr/(A (.*) (?{ $count_a++ }) (CE){0,6} (*THEN) | A D) (*FAIL)/x, 2091 qr/(A (.*) (?{ $count_b++ }) (CE){0,6} (*THEN) | A D) z/x, 2092 1, 2093 ], 2094 [ 2095 0, 2096 "AbcdCBefgBhiBqz", 2097 qr/(A (.*) (?{ $count_a++ }) (CE*){0,6} (*THEN) | A D) (*FAIL)/x, 2098 qr/(A (.*) (?{ $count_b++ }) (CE*){0,6} (*THEN) | A D) z/x, 2099 1, 2100 ], 2101 ) { 2102 $c++; 2103 $count_a = 0; 2104 $count_b = 0; 2105 2106 my $match_a = ($re->[1] =~ $re->[2]) || 0; 2107 my $match_b = ($re->[1] =~ $re->[3]) || 0; 2108 2109 is($match_a, $re->[0], "match a " . ($re->[0] ? "succeeded" : "failed") . " ($c)"); 2110 is($match_b, $re->[0], "match b " . ($re->[0] ? "succeeded" : "failed") . " ($c)"); 2111 is($count_a, $re->[4], "count a ($c)"); 2112 is($count_b, $re->[4], "count b ($c)"); 2113 } 2114 } 2115 2116 { # Bleadperl v5.13.8-292-gf56b639 breaks NEZUMI/Unicode-LineBreak-1.011 2117 # \xdf in lookbehind failed to compile as is multi-char fold 2118 my $message = "Lookbehind with \\xdf matchable compiles"; 2119 my $r = eval 'qr{ 2120 (?u: (?<=^url:) | 2121 (?<=[/]) (?=[^/]) | 2122 (?<=[^-.]) (?=[-~.,_?\#%=&]) | 2123 (?<=[=&]) (?=.) 2124 )}iox'; 2125 is($@, '', $message); 2126 object_ok($r, 'Regexp', $message); 2127 } 2128 2129 # RT #82610 2130 ok 'foo/file.fob' =~ m,^(?=[^\.])[^/]*/(?=[^\.])[^/]*\.fo[^/]$,; 2131 2132 { # This was failing unless an explicit /d was added 2133 my $p = qr/[\xE0_]/i; 2134 utf8::upgrade($p); 2135 like("\xC0", $p, "Verify \"\\xC0\" =~ /[\\xE0_]/i; pattern in utf8"); 2136 } 2137 2138 ok "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/, 2139 "Check TRIE does not overwrite EXACT following NOTHING at start - RT #111842"; 2140 2141 { 2142 my $single = ":"; 2143 my $upper = "\x{390}"; # Fold is 3 chars. 2144 my $multi = CORE::fc($upper); 2145 2146 my $failed = 0; 2147 2148 # Try forcing a node to be split, with a multi-char fold at the 2149 # boundary 2150 for my $repeat (1 .. 300) { 2151 my $string = $single x $repeat; 2152 my $lhs = $string . $upper; 2153 if ($lhs !~ m/$string$multi/i) { 2154 $failed = $repeat; 2155 last; 2156 } 2157 } 2158 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed"); 2159 2160 $failed = 0; 2161 for my $repeat (1 .. 300) { 2162 my $string = $single x $repeat; 2163 my $lhs = $string . "\N{LATIN SMALL LIGATURE FFI}"; 2164 if ($lhs !~ m/${string}ff\N{LATIN SMALL LETTER I}/i) { 2165 $failed = $repeat; 2166 last; 2167 } 2168 } 2169 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed"); 2170 2171 $failed = 0; 2172 for my $repeat (1 .. 300) { 2173 my $string = $single x $repeat; 2174 my $lhs = $string . "\N{LATIN SMALL LIGATURE FFL}"; 2175 if ($lhs !~ m/${string}ff\N{U+6c}/i) { 2176 $failed = $repeat; 2177 last; 2178 } 2179 } 2180 ok(! $failed, "Matched multi-char fold across EXACTFish node boundaries; if failed, was at count $failed"); 2181 } 2182 2183 { 2184 fresh_perl_is('print eval "\"\x{101}\" =~ /[[:lower:]]/", "\n"; print eval "\"\x{100}\" =~ /[[:lower:]]/i", "\n";', 2185 "1\n1", # Both re's should match 2186 "", 2187 "get [:lower:] swash in first eval; test under /i in second"); 2188 } 2189 2190 # 2191 # Keep the following tests last -- they may crash perl 2192 # 2193 print "# Tests that follow may crash perl\n"; 2194 { 2195 eval '/\k/'; 2196 ok $@ =~ /\QSequence \k... not terminated in regex;\E/, 2197 'Lone \k not allowed'; 2198 } 2199 2200 { 2201 my $message = "Substitution with lookahead (possible segv)"; 2202 $_ = "ns1ns1ns1"; 2203 s/ns(?=\d)/ns_/g; 2204 is($_, "ns_1ns_1ns_1", $message); 2205 $_ = "ns1"; 2206 s/ns(?=\d)/ns_/; 2207 is($_, "ns_1", $message); 2208 $_ = "123"; 2209 s/(?=\d+)|(?<=\d)/!Bang!/g; 2210 is($_, "!Bang!1!Bang!2!Bang!3!Bang!", $message); 2211 } 2212 2213 { 2214 # Earlier versions of Perl said this was fatal. 2215 my $message = "U+0FFFF shouldn't crash the regex engine"; 2216 no warnings 'utf8'; 2217 my $a = eval "chr(65535)"; 2218 use warnings; 2219 my $warning_message; 2220 local $SIG{__WARN__} = sub { $warning_message = $_[0] }; 2221 eval $a =~ /[a-z]/; 2222 ok(1, $message); # If it didn't crash, it worked. 2223 } 2224 2225 TODO: { # Was looping 2226 todo_skip('Triggers thread clone SEGV. See #86550') 2227 if $::running_as_thread && $::running_as_thread; 2228 watchdog(10); # Use a bigger value for busy systems 2229 like("\x{00DF}", qr/[\x{1E9E}_]*/i, "\"\\x{00DF}\" =~ /[\\x{1E9E}_]*/i was looping"); 2230 } 2231 2232 { # Bug #90536, caused failed assertion 2233 unlike("s\N{U+DF}", qr/^\x{00DF}/i, "\"s\\N{U+DF}\", qr/^\\x{00DF}/i"); 2234 } 2235 2236 # User-defined Unicode properties to match above-Unicode code points 2237 sub Is_32_Bit_Super { return "110000\tFFFFFFFF\n" } 2238 sub Is_Portable_Super { return '!utf8::Any' } # Matches beyond 32 bits 2239 2240 { # Assertion was failing on on 64-bit platforms; just didn't work on 32. 2241 no warnings qw(non_unicode portable); 2242 use Config; 2243 2244 # We use 'ok' instead of 'like' because the warnings are lexically 2245 # scoped, and want to turn them off, so have to do the match in this 2246 # scope 2247 if ($Config{uvsize} < 8) { 2248 ok(chr(0xFFFF_FFFE) =~ /\p{Is_32_Bit_Super}/, 2249 "chr(0xFFFF_FFFE) can match a Unicode property"); 2250 ok(chr(0xFFFF_FFFF) =~ /\p{Is_32_Bit_Super}/, 2251 "chr(0xFFFF_FFFF) can match a Unicode property"); 2252 my $p = qr/^[\x{FFFF_FFFF}]$/; 2253 ok(chr(0xFFFF_FFFF) =~ $p, 2254 "chr(0xFFFF_FFFF) can match itself in a [class]"); 2255 ok(chr(0xFFFF_FFFF) =~ $p, # Tests any caching 2256 "chr(0xFFFF_FFFF) can match itself in a [class] subsequently"); 2257 } 2258 else { 2259 no warnings 'overflow'; 2260 ok(chr(0xFFFF_FFFF_FFFF_FFFE) =~ qr/\p{Is_Portable_Super}/, 2261 "chr(0xFFFF_FFFF_FFFF_FFFE) can match a Unicode property"); 2262 ok(chr(0xFFFF_FFFF_FFFF_FFFF) =~ qr/^\p{Is_Portable_Super}$/, 2263 "chr(0xFFFF_FFFF_FFFF_FFFF) can match a Unicode property"); 2264 2265 my $p = qr/^[\x{FFFF_FFFF_FFFF_FFFF}]$/; 2266 ok(chr(0xFFFF_FFFF_FFFF_FFFF) =~ $p, 2267 "chr(0xFFFF_FFFF_FFFF_FFFF) can match itself in a [class]"); 2268 ok(chr(0xFFFF_FFFF_FFFF_FFFF) =~ $p, # Tests any caching 2269 "chr(0xFFFF_FFFF_FFFF_FFFF) can match itself in a [class] subsequently"); 2270 2271 # This test is because something was declared as 32 bits, but 2272 # should have been cast to 64; only a problem where 2273 # sizeof(STRLEN) != sizeof(UV) 2274 ok(chr(0xFFFF_FFFF_FFFF_FFFE) !~ qr/\p{Is_32_Bit_Super}/, "chr(0xFFFF_FFFF_FFFF_FFFE) shouldn't match a range ending in 0xFFFF_FFFF"); 2275 } 2276 } 2277 2278 { # [perl #112530], the code below caused a panic 2279 sub InFoo { "a\tb\n9\ta\n" } 2280 like("\n", qr/\p{InFoo}/, 2281 "Overlapping ranges in user-defined properties"); 2282 } 2283 2284 { # Regexp:Grammars was broken: 2285 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2013-06/msg01290.html 2286 fresh_perl_like('use warnings; "abc" =~ qr{(?&foo){0}abc(?<foo>)}', 2287 'Quantifier unexpected on zero-length expression', 2288 "", 2289 'No segfault on qr{(?&foo){0}abc(?<foo>)}'); 2290 } 2291 2292 # !!! NOTE that tests that aren't at all likely to crash perl should go 2293 # a ways above, above these last ones. 2294 2295 done_testing(); 2296} # End of sub run_tests 2297 22981; 2299