Add tests for a backreference following a literal, which is a different codepath
authorYves Orton <demerphq@gmail.com>
Tue, 25 Jun 2013 22:59:09 +0000 (00:59 +0200)
committerYves Orton <demerphq@gmail.com>
Tue, 25 Jun 2013 23:01:22 +0000 (01:01 +0200)
/\87/ is parsed through a different code path than /foo\87/ so we
test that they both work properly when there are sufficient capture
buffers defined. We test the fail cases in the re/re_tests corpus,
but the success cases are easier managed in re/pat.t.

t/re/pat.t

index 99d719d..8793f94 100644 (file)
@@ -20,7 +20,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 570;  # Update this when adding/deleting tests.
+plan tests => 670;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -1366,17 +1366,19 @@ EOP
     {
         # if we have 87 capture buffers defined then \87 should refer to the 87th.
         # test that this is true for 1..100
-        my $str= "aa";
         for my $i (1..100) {
-            my $pat= "a";
-            $pat= "($pat)" for 1 .. $i;
-            $pat.="\\$i";
-            eval {
-                ok($str=~/$pat/,"\\$i works with $i buffers");
-                1;
-            } or do {
-                ok(0,"\\$i works with $i buffers");
-            };
+            my $capture= "a";
+            $capture= "($capture)" for 1 .. $i;
+            for my $mid ("","b") {
+                my $str= "a${mid}a";
+                my $backref= "\\$i";
+                eval {
+                    ok($str=~/$capture$mid$backref/,"\\$i works with $i buffers '$str'=~/...$mid$backref/");
+                    1;
+                } or do {
+                    is("$@","","\\$i works with $i buffers works with $i buffers '$str'=~/...$mid$backref/");
+                };
+            }
         }
     }