From: Tamir Duberstein Date: Sun, 31 Jul 2016 16:55:06 +0000 (-0400) Subject: regexp: add some tests that were fixed in #12980 X-Git-Tag: go1.8beta1~1838 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f88a88402cbf93b37f701a8ca0c70b7d2558a057;p=gostls13.git regexp: add some tests that were fixed in #12980 Also includes a minor golint cleanup in the tests. Change-Id: I8c0fc81479e635e7cca18d5c48c28b654afa59d8 Reviewed-on: https://go-review.googlesource.com/25380 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/regexp/all_test.go b/src/regexp/all_test.go index 88391ff47d..c989f0798d 100644 --- a/src/regexp/all_test.go +++ b/src/regexp/all_test.go @@ -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)