16fb12b70Safresh1use warnings; 26fb12b70Safresh1use strict; 36fb12b70Safresh1 4*9f11ffb7Safresh1# confirm that regexp-typed stack args are displayed correctly by longmess() 5*9f11ffb7Safresh1 66fb12b70Safresh1use Test::More tests => 42; 76fb12b70Safresh1 86fb12b70Safresh1use Carp (); 96fb12b70Safresh1 106fb12b70Safresh1sub lmm { Carp::longmess("x") } 116fb12b70Safresh1sub lm { lmm() } 126fb12b70Safresh1sub rx { qr/$_[0]/ } 136fb12b70Safresh1 14b8851fccSafresh1# Use full generality on sufficiently recent versions. On early Perl 15b8851fccSafresh1# releases, U+E9 is 0x51 on all EBCDIC code pages supported then. 16b8851fccSafresh1my $e9 = sprintf "%02x", (($] ge 5.007_003) 17b8851fccSafresh1 ? utf8::unicode_to_native(0xe9) 18b8851fccSafresh1 : ((ord("A") == 193) 19b8851fccSafresh1 ? 0x51 20b8851fccSafresh1 : 0xE9)); 21*9f11ffb7Safresh1my $xe9 = "\\x$e9"; 22*9f11ffb7Safresh1my $chr_e9 = eval "\"$xe9\""; 23b8851fccSafresh1my $nl_as_hex = sprintf "%x", ord("\n"); 24b8851fccSafresh1 256fb12b70Safresh1# On Perl 5.6 we accept some incorrect quoting of Unicode characters, 266fb12b70Safresh1# because upgradedness of regexps isn't preserved by stringification, 276fb12b70Safresh1# so it's impossible to implement the correct behaviour. 28*9f11ffb7Safresh1# FIXME: the permissive patterns don't account for EBCDIC 29b8851fccSafresh1my $xe9_rx = "$]" < 5.008 ? qr/\\x\{c3\}\\x\{a9\}|\\x\{e9\}/ : qr/\\x\{$e9\}/; 306fb12b70Safresh1my $x666_rx = "$]" < 5.008 ? qr/\\x\{d9\}\\x\{a6\}|\\x\{666\}/ : qr/\\x\{666\}/; 316fb12b70Safresh1my $x2603_rx = "$]" < 5.008 ? qr/\\x\{e2\}\\x\{98\}\\x\{83\}|\\x\{2603\}/ : qr/\\x\{2603\}/; 326fb12b70Safresh1 336fb12b70Safresh1like lm(qr/3/), qr/main::lm\(qr\(3\)u?\)/; 346fb12b70Safresh1like lm(qr/a.b/), qr/main::lm\(qr\(a\.b\)u?\)/; 356fb12b70Safresh1like lm(qr/a.b/s), qr/main::lm\(qr\(a\.b\)u?s\)/; 366fb12b70Safresh1like lm(qr/a.b$/s), qr/main::lm\(qr\(a\.b\$\)u?s\)/; 376fb12b70Safresh1like lm(qr/a.b$/sm), qr/main::lm\(qr\(a\.b\$\)u?ms\)/; 386fb12b70Safresh1like lm(qr/foo/), qr/main::lm\(qr\(foo\)u?\)/; 396fb12b70Safresh1like lm(qr/a\$b\@c\\d/), qr/main::lm\(qr\(a\\\$b\\\@c\\\\d\)u?\)/; 406fb12b70Safresh1like lm(qr/a\nb/), qr/main::lm\(qr\(a\\nb\)u?\)/; 41b8851fccSafresh1like lm(rx("a\nb")), qr/main::lm\(qr\(a\\x\{$nl_as_hex\}b\)u?\)/; 426fb12b70Safresh1like lm(qr/a\x{666}b/), qr/main::lm\(qr\(a\\x\{666\}b\)u?\)/; 436fb12b70Safresh1like lm(rx("a\x{666}b")), qr/main::lm\(qr\(a${x666_rx}b\)u?\)/; 446fb12b70Safresh1like lm(qr/\x{666}b/), qr/main::lm\(qr\(\\x\{666\}b\)u?\)/; 456fb12b70Safresh1like lm(rx("\x{666}b")), qr/main::lm\(qr\(${x666_rx}b\)u?\)/; 466fb12b70Safresh1like lm(qr/a\x{666}/), qr/main::lm\(qr\(a\\x\{666\}\)u?\)/; 476fb12b70Safresh1like lm(rx("a\x{666}")), qr/main::lm\(qr\(a${x666_rx}\)u?\)/; 48*9f11ffb7Safresh1like lm(qr/L${xe9}on/), qr/main::lm\(qr\(L\\x${e9}on\)u?\)/; 49b8851fccSafresh1like lm(rx("L${chr_e9}on")), qr/main::lm\(qr\(L${xe9_rx}on\)u?\)/; 50*9f11ffb7Safresh1like lm(qr/L${xe9}on \x{2603} !/), qr/main::lm\(qr\(L\\x${e9}on \\x\{2603\} !\)u?\)/; 51b8851fccSafresh1like lm(rx("L${chr_e9}on \x{2603} !")), qr/main::lm\(qr\(L${xe9_rx}on ${x2603_rx} !\)u?\)/; 526fb12b70Safresh1 536fb12b70Safresh1$Carp::MaxArgLen = 5; 546fb12b70Safresh1foreach my $arg ("foo bar baz", "foo bar ba", "foo bar b", "foo bar ", "foo bar", "foo ba") { 556fb12b70Safresh1 like lm(rx($arg)), qr/main::lm\(qr\(fo\)\.\.\.u?\)/; 566fb12b70Safresh1} 576fb12b70Safresh1foreach my $arg ("foo b", "foo ", "foo", "fo", "f", "") { 586fb12b70Safresh1 like lm(rx($arg)), qr/main::lm\(qr\(\Q$arg\E\)u?\)/; 596fb12b70Safresh1} 606fb12b70Safresh1like lm(qr/foo.bar$/sm), qr/main::lm\(qr\(fo\)\.\.\.u?ms\)/; 61*9f11ffb7Safresh1like lm(qr/L${xe9}on \x{2603} !/), qr/main::lm\(qr\(L\\\)\.\.\.u?\)/; 62b8851fccSafresh1like lm(rx("L${chr_e9}on \x{2603} !")), qr/main::lm\(qr\(L\\\)\.\.\.u?\)/; 63*9f11ffb7Safresh1like lm(qr/L${xe9}on\x{2603}/), qr/main::lm\(qr\(L\\\)\.\.\.u?\)/; 64b8851fccSafresh1like lm(rx("L${chr_e9}on\x{2603}")), qr/main::lm\(qr\(L\\\)\.\.\.u?\)/; 656fb12b70Safresh1like lm(qr/foo\x{2603}/), qr/main::lm\(qr\(fo\)\.\.\.u?\)/; 666fb12b70Safresh1like lm(rx("foo\x{2603}")), qr/main::lm\(qr\(fo\)\.\.\.u?\)/; 676fb12b70Safresh1 686fb12b70Safresh1$Carp::MaxArgLen = 0; 696fb12b70Safresh1foreach my $arg ("wibble:" x 20, "foo bar baz") { 706fb12b70Safresh1 like lm(rx($arg)), qr/main::lm\(qr\(\Q$arg\E\)u?\)/; 716fb12b70Safresh1} 72*9f11ffb7Safresh1like lm(qr/L${xe9}on\x{2603}/), qr/main::lm\(qr\(L\\x${e9}on\\x\{2603\}\)u?\)/; 73b8851fccSafresh1like lm(rx("L${chr_e9}on\x{2603}")), qr/main::lm\(qr\(L${xe9_rx}on${x2603_rx}\)u?\)/; 746fb12b70Safresh1 756fb12b70Safresh11; 76