diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-12-22 01:15:33 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-12-22 01:15:33 +0000 |
commit | 362133b5eb9024407b03e8095307f9d5d36154c2 (patch) | |
tree | 06f36bbef6fae78278f799194ad0df8ba2dabaa1 /libgo/go/regexp | |
parent | 331a34f7832c3b58fd8488f49121a6af52433123 (diff) | |
download | gcc-362133b5eb9024407b03e8095307f9d5d36154c2.tar.gz |
libgo: Update to revision 15193:6fdc1974457c of master library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194692 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/regexp')
-rw-r--r-- | libgo/go/regexp/all_test.go | 47 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse.go | 8 |
2 files changed, 26 insertions, 29 deletions
diff --git a/libgo/go/regexp/all_test.go b/libgo/go/regexp/all_test.go index b7e4f044a57..a6a659c4031 100644 --- a/libgo/go/regexp/all_test.go +++ b/libgo/go/regexp/all_test.go @@ -31,53 +31,52 @@ var good_re = []string{ `\!\\`, } -/* type stringError struct { re string - err error + err string } var bad_re = []stringError{ - {`*`, ErrBareClosure}, - {`+`, ErrBareClosure}, - {`?`, ErrBareClosure}, - {`(abc`, ErrUnmatchedLpar}, - {`abc)`, ErrUnmatchedRpar}, - {`x[a-z`, ErrUnmatchedLbkt}, - {`abc]`, ErrUnmatchedRbkt}, - {`[z-a]`, ErrBadRange}, - {`abc\`, ErrExtraneousBackslash}, - {`a**`, ErrBadClosure}, - {`a*+`, ErrBadClosure}, - {`a??`, ErrBadClosure}, - {`\x`, ErrBadBackslash}, -} -*/ - -func compileTest(t *testing.T, expr string, error error) *Regexp { + {`*`, "missing argument to repetition operator: `*`"}, + {`+`, "missing argument to repetition operator: `+`"}, + {`?`, "missing argument to repetition operator: `?`"}, + {`(abc`, "missing closing ): `(abc`"}, + {`abc)`, "unexpected ): `abc)`"}, + {`x[a-z`, "missing closing ]: `[a-z`"}, + {`[z-a]`, "invalid character class range: `z-a`"}, + {`abc\`, "trailing backslash at end of expression"}, + {`a**`, "invalid nested repetition operator: `**`"}, + {`a*+`, "invalid nested repetition operator: `*+`"}, + {`\x`, "invalid escape sequence: `\\x`"}, +} + +func compileTest(t *testing.T, expr string, error string) *Regexp { re, err := Compile(expr) - if err != error { + if error == "" && err != nil { 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 } func TestGoodCompile(t *testing.T) { for i := 0; i < len(good_re); i++ { - compileTest(t, good_re[i], nil) + compileTest(t, good_re[i], "") } } -/* func TestBadCompile(t *testing.T) { for i := 0; i < len(bad_re); i++ { compileTest(t, bad_re[i].re, bad_re[i].err) } } -*/ func matchTest(t *testing.T, test *FindTest) { - re := compileTest(t, test.pat, nil) + re := compileTest(t, test.pat, "") if re == nil { return } diff --git a/libgo/go/regexp/syntax/parse.go b/libgo/go/regexp/syntax/parse.go index 0bf5799b001..335f7395d93 100644 --- a/libgo/go/regexp/syntax/parse.go +++ b/libgo/go/regexp/syntax/parse.go @@ -42,11 +42,9 @@ const ( ErrMissingParen ErrorCode = "missing closing )" ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator" ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression" + ErrUnexpectedParen ErrorCode = "unexpected )" ) -// TODO: Export for Go 1.1. -const errUnexpectedParen ErrorCode = "unexpected )" - func (e ErrorCode) String() string { return string(e) } @@ -1167,13 +1165,13 @@ func (p *parser) parseRightParen() error { n := len(p.stack) if n < 2 { - return &Error{errUnexpectedParen, p.wholeRegexp} + return &Error{ErrUnexpectedParen, p.wholeRegexp} } re1 := p.stack[n-1] re2 := p.stack[n-2] p.stack = p.stack[:n-2] if re2.Op != opLeftParen { - return &Error{errUnexpectedParen, p.wholeRegexp} + return &Error{ErrUnexpectedParen, p.wholeRegexp} } // Restore flags at time of paren. p.flags = re2.Flags |