summaryrefslogtreecommitdiff
path: root/libgo/go/regexp/all_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2016-02-03 21:58:02 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-02-03 21:58:02 +0000
commitf98dd1a338867a408f7c72d73fbad7fe7fc93e3a (patch)
tree2f8da9862a9c1fe0df138917f997b03439c02773 /libgo/go/regexp/all_test.go
parentb081ed4efc144da0c45a6484aebfd10e0eb9fda3 (diff)
libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200 From-SVN: r233110
Diffstat (limited to 'libgo/go/regexp/all_test.go')
-rw-r--r--libgo/go/regexp/all_test.go63
1 files changed, 62 insertions, 1 deletions
diff --git a/libgo/go/regexp/all_test.go b/libgo/go/regexp/all_test.go
index d78ae6a4cde..88391ff47de 100644
--- a/libgo/go/regexp/all_test.go
+++ b/libgo/go/regexp/all_test.go
@@ -113,6 +113,25 @@ func TestMatchFunction(t *testing.T) {
}
}
+func copyMatchTest(t *testing.T, test *FindTest) {
+ re := compileTest(t, test.pat, "")
+ if re == nil {
+ return
+ }
+ m1 := re.MatchString(test.text)
+ m2 := re.Copy().MatchString(test.text)
+ if m1 != m2 {
+ t.Errorf("Copied Regexp match failure on %s: original gave %t; copy gave %t; should be %t",
+ test, m1, m2, len(test.matches) > 0)
+ }
+}
+
+func TestCopyMatch(t *testing.T) {
+ for _, test := range findTests {
+ copyMatchTest(t, &test)
+ }
+}
+
type ReplaceTest struct {
pattern, replacement, input, output string
}
@@ -201,6 +220,12 @@ var replaceTests = []ReplaceTest{
// Substitution when subexpression isn't found
{"(x)?", "$1", "123", "123"},
{"abc", "$1", "123", "123"},
+
+ // Substitutions involving a (x){0}
+ {"(a)(b){0}(c)", ".$1|$3.", "xacxacx", "x.a|c.x.a|c.x"},
+ {"(a)(((b))){0}c", ".$1.", "xacxacx", "x.a.x.a.x"},
+ {"((a(b){0}){3}){5}(h)", "y caramb$2", "say aaaaaaaaaaaaaaaah", "say ay caramba"},
+ {"((a(b){0}){3}){5}h", "y caramb$2", "say aaaaaaaaaaaaaaaah", "say ay caramba"},
}
var replaceLiteralTests = []ReplaceTest{
@@ -334,6 +359,19 @@ var metaTests = []MetaTest{
{`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[\{\]\}\\\|,<\.>/\?~`, `!@#`, false},
}
+var literalPrefixTests = []MetaTest{
+ // See golang.org/issue/11175.
+ // output is unused.
+ {`^0^0$`, ``, `0`, false},
+ {`^0^`, ``, ``, false},
+ {`^0$`, ``, `0`, true},
+ {`$0^`, ``, ``, false},
+ {`$0$`, ``, ``, false},
+ {`^^0$$`, ``, ``, false},
+ {`^$^$`, ``, ``, false},
+ {`$$0^^`, ``, ``, false},
+}
+
func TestQuoteMeta(t *testing.T) {
for _, tc := range metaTests {
// Verify that QuoteMeta returns the expected string.
@@ -365,7 +403,7 @@ func TestQuoteMeta(t *testing.T) {
}
func TestLiteralPrefix(t *testing.T) {
- for _, tc := range metaTests {
+ for _, tc := range append(metaTests, literalPrefixTests...) {
// Literal method needs to scan the pattern.
re := MustCompile(tc.pattern)
str, complete := re.LiteralPrefix()
@@ -665,3 +703,26 @@ func BenchmarkOnePassLongNotPrefix(b *testing.B) {
re.Match(x)
}
}
+
+func BenchmarkMatchParallelShared(b *testing.B) {
+ x := []byte("this is a long line that contains foo bar baz")
+ re := MustCompile("foo (ba+r)? baz")
+ b.ResetTimer()
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ re.Match(x)
+ }
+ })
+}
+
+func BenchmarkMatchParallelCopied(b *testing.B) {
+ x := []byte("this is a long line that contains foo bar baz")
+ re := MustCompile("foo (ba+r)? baz")
+ b.ResetTimer()
+ b.RunParallel(func(pb *testing.PB) {
+ re := re.Copy()
+ for pb.Next() {
+ re.Match(x)
+ }
+ })
+}