This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix bug with (??{$overload}) regexp caching
[perl5.git] / t / re / pos.t
CommitLineData
de0df3c0
MH
1#!./perl
2
3# Make sure pos / resetting pos on failed match works
4
5use strict;
6use warnings;
7
8BEGIN {
9 chdir 't' if -d 't';
10 @INC = '../lib';
11 require './test.pl';
12}
13
14plan tests => 8;
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}