1#!./perl 2 3# Make sure pos / resetting pos on failed match works 4 5BEGIN { 6 chdir 't' if -d 't'; 7 @INC = '../lib'; 8 require './test.pl'; 9} 10 11plan tests => 8; 12 13use strict; 14use warnings; 15 16## Early bailout of pp_match because matchlen > stringlen 17 18# With a var 19{ 20 my $str = "bird"; 21 22 $str =~ /i/g; 23 24 is(pos($str), 2, 'pos correct'); 25 26 $str =~ /toolongtomatch/g; 27 28 is(pos($str), undef, 'pos undef after failed match'); 29} 30 31# With $_ 32{ 33 $_ = "bird"; 34 35 m/i/g; 36 37 is(pos, 2, 'pos correct'); 38 39 m/toolongtomatch/g; 40 41 is(pos, undef, 'pos undef after failed match'); 42} 43 44## Early bail out of pp_match because ?? already matched 45 46# With a var 47{ 48 my $str = "bird"; 49 50 for (1..2) { 51 if ($str =~ m?bird?g) { 52 is(pos($str), 4, 'pos correct'); 53 } else { 54 is(pos($str), undef, 'pos undef after failed match'); 55 } 56 } 57} 58 59# With $_ 60{ 61 for (1..2) { 62 if (m?\d?g) { 63 is(pos, 1, 'pos correct'); 64 } else { 65 is(pos, undef, 'pos undef after failed match'); 66 } 67 } 68} 69