diff options
author | Yves Orton <demerphq@gmail.com> | 2007-01-12 03:31:12 +0100 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-01-15 16:26:17 +0000 |
commit | cde0cee5716418bb58782f073048ee9685ed2368 (patch) | |
tree | c2a691ebb8348e48a5171a60b617299632146e12 /t | |
parent | 780a5241a93925d81e932db73df46ee749b203b9 (diff) | |
download | perl-cde0cee5716418bb58782f073048ee9685ed2368.tar.gz |
Add support for /k modfier for matching along with ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH}
Message-ID: <9b18b3110701111731x29b1c63i57b1698f769b3bbc@mail.gmail.com>
(with tweaks)
p4raw-id: //depot/perl@29831
Diffstat (limited to 't')
-rwxr-xr-x | t/op/regexp.t | 10 | ||||
-rw-r--r-- | t/op/regexp_kmod.t | 39 |
2 files changed, 48 insertions, 1 deletions
diff --git a/t/op/regexp.t b/t/op/regexp.t index cce19fc03d..a7cd5fc7b9 100755 --- a/t/op/regexp.t +++ b/t/op/regexp.t @@ -125,7 +125,15 @@ EOFCODE } else { if (!$match || $got ne $expect) { - print "not ok $. ($study) $input => `$got', match=$match\n$code\n"; + eval { require Data::Dumper }; + if ($@) { + print "not ok $. ($study) $input => `$got', match=$match\n$code\n"; + } + else { # better diagnostics + my $s = Data::Dumper->new([$subject],['subject'])->Useqq(1)->Dump; + my $g = Data::Dumper->new([$got],['got'])->Useqq(1)->Dump; + print "not ok $. ($study) $input => `$got', match=$match\n$s\n$g\n$code\n"; + } next TEST; } } diff --git a/t/op/regexp_kmod.t b/t/op/regexp_kmod.t new file mode 100644 index 0000000000..84efd83546 --- /dev/null +++ b/t/op/regexp_kmod.t @@ -0,0 +1,39 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; +} + +use strict; +use warnings; + +our @tests = ( + # /k Pattern PRE MATCH POST + [ 'k', "456", "123-", "456", "-789"], + [ '', "(456)", "123-", "456", "-789"], + [ '', "456", undef, undef, undef ], +); + +plan tests => 4 * @tests + 2; +my $W = ""; + +$SIG{__WARN__} = sub { $W.=join("",@_); }; +sub _u($$) { "$_[0] is ".(defined $_[1] ? "'$_[1]'" : "undef") } + +$_ = '123-456-789'; +foreach my $test (@tests) { + my ($k, $pat,$l,$m,$r) = @$test; + my $test_name = "/$pat/$k"; + my $ok = ok($k ? /$pat/k : /$pat/, $test_name); + SKIP: { + skip "/$pat/$k failed to match", 3 + unless $ok; + is(${^PREMATCH}, $l,_u "$test_name: ^PREMATCH",$l); + is(${^MATCH}, $m,_u "$test_name: ^MATCH",$m ); + is(${^POSTMATCH}, $r,_u "$test_name: ^POSTMATCH",$r ); + } +} +is($W,"","No warnings should be produced"); +ok(!defined ${^MATCH}, "No /k in scope so ^MATCH is undef"); |