Add some tests for the regex optimizer
authorKarl Williamson <public@khwilliamson.com>
Mon, 23 Sep 2013 04:46:10 +0000 (22:46 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 24 Sep 2013 17:36:20 +0000 (11:36 -0600)
We don't have the infrastructure to test the regex optimizer, and I'm
not sure how to do it properly, without tying the tests to particular
optimizations.  What I did, however, was to go through the recently
changed optimizer code and write tests to exercise every branch, as far
as I could tell.

t/re/pat_advanced.t
t/re/re_tests

index 0c3d2d7..6d9ca2f 100644 (file)
@@ -2253,6 +2253,31 @@ EOP
 
     }
 
+    {
+        unlike("\xB5", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        like("\xB6", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        unlike("\xB7", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        like("\xB5", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+        unlike("\xB6", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+        like("\xB7", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+
+        unlike("_\xB5", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        like("_\xB6", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        unlike("_\xB7", qr/^_?\p{IsMyRuntimeProperty}\z/, "yadayada");
+        like("_\xB5", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+        unlike("_\xB6", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+        like("_\xB7", qr/^_?\P{IsMyRuntimeProperty}\z/, "yadayada");
+    }
+
+    # These are defined later, so won't be known at regex compile time above
+    sub IsMyRuntimeProperty {
+        return "B6\n";
+    }
+
+    sub IsntMyRuntimeProperty {
+        return "!B6\n";
+    }
+
     #
     # Keep the following tests last -- they may crash perl
     #
index 7420510..3c031ff 100644 (file)
@@ -1736,8 +1736,18 @@ ab[c\\\](??{"x"})]{3}d   ab\\](d y       -       -
 # [ perl #114272]
 \Vn    \xFFn/  y       $&      \xFFn
 
+# These mostly exercize various paths in the optimizer
 /(?l:a?\w)/    b       y       $&      b
+/(?l:a?\D)/    b       y       $&      b
+^_?[^\S_0-9]\w*\z      \t      y       $&      \t
 m?^xy\?$?      xy?     y       $&      xy?
+a?\X   a\x{100}        y       $&      a\x{100}
+a?\R   a\n     y       $&      a\n
+^a?\N$ a\n     y       $&      a
+\N?a   \na     y       $&      a
+/\s?\s/l       \t      y       $&      \t
+/\s?\d/l       3       y       $&      3
+/\s?\S/l       A       y       $&      A
 
 # check we have the right utf8ness as we switch back and forth between
 # patterns