]> Cypherpunks repositories - gostls13.git/commitdiff
regexp: add some tests that were fixed in #12980
authorTamir Duberstein <tamird@gmail.com>
Sun, 31 Jul 2016 16:55:06 +0000 (12:55 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 16 Aug 2016 18:36:43 +0000 (18:36 +0000)
Also includes a minor golint cleanup in the tests.

Change-Id: I8c0fc81479e635e7cca18d5c48c28b654afa59d8
Reviewed-on: https://go-review.googlesource.com/25380
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/regexp/all_test.go

index 88391ff47decd531c4266dc756689f8265246de9..c989f0798d7511d283c7bda8f0101423872a4edd 100644 (file)
@@ -11,7 +11,7 @@ import (
        "testing"
 )
 
-var good_re = []string{
+var goodRe = []string{
        ``,
        `.`,
        `^.$`,
@@ -36,7 +36,7 @@ type stringError struct {
        err string
 }
 
-var bad_re = []stringError{
+var badRe = []stringError{
        {`*`, "missing argument to repetition operator: `*`"},
        {`+`, "missing argument to repetition operator: `+`"},
        {`?`, "missing argument to repetition operator: `?`"},
@@ -64,14 +64,14 @@ func compileTest(t *testing.T, expr string, error string) *Regexp {
 }
 
 func TestGoodCompile(t *testing.T) {
-       for i := 0; i < len(good_re); i++ {
-               compileTest(t, good_re[i], "")
+       for i := 0; i < len(goodRe); i++ {
+               compileTest(t, goodRe[i], "")
        }
 }
 
 func TestBadCompile(t *testing.T) {
-       for i := 0; i < len(bad_re); i++ {
-               compileTest(t, bad_re[i].re, bad_re[i].err)
+       for i := 0; i < len(badRe); i++ {
+               compileTest(t, badRe[i].re, badRe[i].err)
        }
 }
 
@@ -512,6 +512,32 @@ func TestSplit(t *testing.T) {
        }
 }
 
+// The following sequence of Match calls used to panic. See issue #12980.
+func TestParseAndCompile(t *testing.T) {
+       expr := "a$"
+       s := "a\nb"
+
+       for i, tc := range []struct {
+               reFlags  syntax.Flags
+               expMatch bool
+       }{
+               {syntax.Perl | syntax.OneLine, false},
+               {syntax.Perl &^ syntax.OneLine, true},
+       } {
+               parsed, err := syntax.Parse(expr, tc.reFlags)
+               if err != nil {
+                       t.Fatalf("%d: parse: %v", i, err)
+               }
+               re, err := Compile(parsed.String())
+               if err != nil {
+                       t.Fatalf("%d: compile: %v", i, err)
+               }
+               if match := re.MatchString(s); match != tc.expMatch {
+                       t.Errorf("%d: %q.MatchString(%q)=%t; expected=%t", i, re, s, match, tc.expMatch)
+               }
+       }
+}
+
 // Check that one-pass cutoff does trigger.
 func TestOnePassCutoff(t *testing.T) {
        re, err := syntax.Parse(`^x{1,1000}y{1,1000}$`, syntax.Perl)