Commit | Line | Data |
---|---|---|
de0df3c0 MH |
1 | #!./perl |
2 | ||
3 | # Make sure pos / resetting pos on failed match works | |
4 | ||
de0df3c0 MH |
5 | BEGIN { |
6 | chdir 't' if -d 't'; | |
de0df3c0 | 7 | require './test.pl'; |
624c42e2 | 8 | set_up_inc('../lib'); |
de0df3c0 MH |
9 | } |
10 | ||
11 | plan tests => 8; | |
12 | ||
0b1b7115 JH |
13 | use strict; |
14 | use warnings; | |
15 | ||
de0df3c0 MH |
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 | } |