Commit f88a8840 authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Brad Fitzpatrick

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/25380Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8c9a7978
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment