aboutsummaryrefslogtreecommitdiff
path: root/src/testing/match_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/match_test.go')
-rw-r--r--src/testing/match_test.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/testing/match_test.go b/src/testing/match_test.go
index 8c09dc660fb..9ceadbb31d9 100644
--- a/src/testing/match_test.go
+++ b/src/testing/match_test.go
@@ -5,8 +5,10 @@
package testing
import (
+ "fmt"
"reflect"
"regexp"
+ "strings"
"unicode"
)
@@ -25,10 +27,11 @@ func TestIsSpace(t *T) {
}
func TestSplitRegexp(t *T) {
- res := func(s ...string) []string { return s }
+ res := func(s ...string) filterMatch { return simpleMatch(s) }
+ alt := func(m ...filterMatch) filterMatch { return alternationMatch(m) }
testCases := []struct {
pattern string
- result []string
+ result filterMatch
}{
// Correct patterns
// If a regexp pattern is correct, all split regexps need to be correct
@@ -49,6 +52,8 @@ func TestSplitRegexp(t *T) {
{`([)/][(])`, res(`([)/][(])`)},
{"[(]/[)]", res("[(]", "[)]")},
+ {"A/B|C/D", alt(res("A", "B"), res("C", "D"))},
+
// Faulty patterns
// Errors in original should produce at least one faulty regexp in results.
{")/", res(")/")},
@@ -71,10 +76,8 @@ func TestSplitRegexp(t *T) {
// needs to have an error as well.
if _, err := regexp.Compile(tc.pattern); err != nil {
ok := true
- for _, re := range a {
- if _, err := regexp.Compile(re); err != nil {
- ok = false
- }
+ if err := a.verify("", regexp.MatchString); err != nil {
+ ok = false
}
if ok {
t.Errorf("%s: expected error in any of %q", tc.pattern, a)
@@ -113,6 +116,10 @@ func TestMatcher(t *T) {
{"TestFoo/", "TestBar", "x", false, false},
{"TestFoo/bar/baz", "TestBar", "x/bar/baz", false, false},
+ {"A/B|C/D", "TestA", "B", true, false},
+ {"A/B|C/D", "TestC", "D", true, false},
+ {"A/B|C/D", "TestA", "C", false, false},
+
// subtests only
{"", "TestFoo", "x", true, false},
{"/", "TestFoo", "x", true, false},
@@ -184,3 +191,13 @@ func TestNaming(t *T) {
}
}
}
+
+// GoString returns a string that is more readable than the default, which makes
+// it easier to read test errors.
+func (m alternationMatch) GoString() string {
+ s := make([]string, len(m))
+ for i, m := range m {
+ s[i] = fmt.Sprintf("%#v", m)
+ }
+ return fmt.Sprintf("(%s)", strings.Join(s, " | "))
+}