mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
8c9a797894
commit
f88a88402c
1 changed files with 32 additions and 6 deletions
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var good_re = []string{
|
var goodRe = []string{
|
||||||
``,
|
``,
|
||||||
`.`,
|
`.`,
|
||||||
`^.$`,
|
`^.$`,
|
||||||
|
|
@ -36,7 +36,7 @@ type stringError struct {
|
||||||
err string
|
err string
|
||||||
}
|
}
|
||||||
|
|
||||||
var bad_re = []stringError{
|
var badRe = []stringError{
|
||||||
{`*`, "missing argument to repetition operator: `*`"},
|
{`*`, "missing argument to repetition operator: `*`"},
|
||||||
{`+`, "missing argument to repetition operator: `+`"},
|
{`+`, "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) {
|
func TestGoodCompile(t *testing.T) {
|
||||||
for i := 0; i < len(good_re); i++ {
|
for i := 0; i < len(goodRe); i++ {
|
||||||
compileTest(t, good_re[i], "")
|
compileTest(t, goodRe[i], "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadCompile(t *testing.T) {
|
func TestBadCompile(t *testing.T) {
|
||||||
for i := 0; i < len(bad_re); i++ {
|
for i := 0; i < len(badRe); i++ {
|
||||||
compileTest(t, bad_re[i].re, bad_re[i].err)
|
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.
|
// Check that one-pass cutoff does trigger.
|
||||||
func TestOnePassCutoff(t *testing.T) {
|
func TestOnePassCutoff(t *testing.T) {
|
||||||
re, err := syntax.Parse(`^x{1,1000}y{1,1000}$`, syntax.Perl)
|
re, err := syntax.Parse(`^x{1,1000}y{1,1000}$`, syntax.Perl)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue