Commit 3c6c8831 authored by Russ Cox's avatar Russ Cox

regexp: re-enable TestBadCompile

The code that was commented out was for the old regexp package.
In the new one the errors and the space of valid regexps are different.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6873063
parent f4fc163d
...@@ -30,53 +30,52 @@ var good_re = []string{ ...@@ -30,53 +30,52 @@ var good_re = []string{
`\!\\`, `\!\\`,
} }
/*
type stringError struct { type stringError struct {
re string re string
err error err string
} }
var bad_re = []stringError{ var bad_re = []stringError{
{`*`, ErrBareClosure}, {`*`, "missing argument to repetition operator: `*`"},
{`+`, ErrBareClosure}, {`+`, "missing argument to repetition operator: `+`"},
{`?`, ErrBareClosure}, {`?`, "missing argument to repetition operator: `?`"},
{`(abc`, ErrUnmatchedLpar}, {`(abc`, "missing closing ): `(abc`"},
{`abc)`, ErrUnmatchedRpar}, {`abc)`, "unexpected ): `abc)`"},
{`x[a-z`, ErrUnmatchedLbkt}, {`x[a-z`, "missing closing ]: `[a-z`"},
{`abc]`, ErrUnmatchedRbkt}, {`[z-a]`, "invalid character class range: `z-a`"},
{`[z-a]`, ErrBadRange}, {`abc\`, "trailing backslash at end of expression"},
{`abc\`, ErrExtraneousBackslash}, {`a**`, "invalid nested repetition operator: `**`"},
{`a**`, ErrBadClosure}, {`a*+`, "invalid nested repetition operator: `*+`"},
{`a*+`, ErrBadClosure}, {`\x`, "invalid escape sequence: `\\x`"},
{`a??`, ErrBadClosure}, }
{`\x`, ErrBadBackslash},
} func compileTest(t *testing.T, expr string, error string) *Regexp {
*/
func compileTest(t *testing.T, expr string, error error) *Regexp {
re, err := Compile(expr) re, err := Compile(expr)
if err != error { if error == "" && err != nil {
t.Error("compiling `", expr, "`; unexpected error: ", err.Error()) t.Error("compiling `", expr, "`; unexpected error: ", err.Error())
} }
if error != "" && err == nil {
t.Error("compiling `", expr, "`; missing error")
} else if error != "" && !strings.Contains(err.Error(), error) {
t.Error("compiling `", expr, "`; wrong error: ", err.Error(), "; want ", error)
}
return re return re
} }
func TestGoodCompile(t *testing.T) { func TestGoodCompile(t *testing.T) {
for i := 0; i < len(good_re); i++ { for i := 0; i < len(good_re); i++ {
compileTest(t, good_re[i], nil) compileTest(t, good_re[i], "")
} }
} }
/*
func TestBadCompile(t *testing.T) { func TestBadCompile(t *testing.T) {
for i := 0; i < len(bad_re); i++ { for i := 0; i < len(bad_re); i++ {
compileTest(t, bad_re[i].re, bad_re[i].err) compileTest(t, bad_re[i].re, bad_re[i].err)
} }
} }
*/
func matchTest(t *testing.T, test *FindTest) { func matchTest(t *testing.T, test *FindTest) {
re := compileTest(t, test.pat, nil) re := compileTest(t, test.pat, "")
if re == nil { if re == nil {
return return
} }
......
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