1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 // Verify that our IsSpace agrees with unicode.IsSpace.
14 func TestIsSpace(t
*T
) {
16 for r
:= rune(0); r
<= unicode
.MaxRune
; r
++ {
17 if isSpace(r
) != unicode
.IsSpace(r
) {
18 t
.Errorf("IsSpace(%U)=%t incorrect", r
, isSpace(r
))
27 func TestSplitRegexp(t
*T
) {
28 res
:= func(s
...string) []string { return s
}
29 testCases
:= []struct {
34 // If a regexp pattern is correct, all split regexps need to be correct
38 {"//", res("", "", "")},
40 {"A/B", res("A", "B")},
41 {"A/B/", res("A", "B", "")},
42 {"/A/B/", res("", "A", "B", "")},
43 {"[A]/(B)", res("[A]", "(B)")},
44 {"[/]/[/]", res("[/]", "[/]")},
45 {"[/]/[:/]", res("[/]", "[:/]")},
48 {"]/[/]", res("]", "[/]")},
49 {`([)/][(])`, res(`([)/][(])`)},
50 {"[(]/[)]", res("[(]", "[)]")},
53 // Errors in original should produce at least one faulty regexp in results.
55 {")/(/)", res(")/(", ")")},
56 {"a[/)b", res("a[/)b")},
59 {"[/]/[/", res("[/]", "[/")},
60 {`\p{/}`, res(`\p{`, "}")},
61 {`\p/`, res(`\p`, "")},
62 {`[[:/:]]`, res(`[[:/:]]`)},
64 for _
, tc
:= range testCases
{
65 a
:= splitRegexp(tc
.pattern
)
66 if !reflect
.DeepEqual(a
, tc
.result
) {
67 t
.Errorf("splitRegexp(%q) = %#v; want %#v", tc
.pattern
, a
, tc
.result
)
70 // If there is any error in the pattern, one of the returned subpatterns
71 // needs to have an error as well.
72 if _
, err
:= regexp
.Compile(tc
.pattern
); err
!= nil {
74 for _
, re
:= range a
{
75 if _
, err
:= regexp
.Compile(re
); err
!= nil {
80 t
.Errorf("%s: expected error in any of %q", tc
.pattern
, a
)
86 func TestMatcher(t
*T
) {
87 testCases
:= []struct {
93 // Behavior without subtests.
94 {"", "", "TestFoo", true, false},
95 {"TestFoo", "", "TestFoo", true, false},
96 {"TestFoo/", "", "TestFoo", true, true},
97 {"TestFoo/bar/baz", "", "TestFoo", true, true},
98 {"TestFoo", "", "TestBar", false, false},
99 {"TestFoo/", "", "TestBar", false, false},
100 {"TestFoo/bar/baz", "", "TestBar/bar/baz", false, false},
103 {"", "TestFoo", "x", true, false},
104 {"TestFoo", "TestFoo", "x", true, false},
105 {"TestFoo/", "TestFoo", "x", true, false},
106 {"TestFoo/bar/baz", "TestFoo", "bar", true, true},
107 // Subtest with a '/' in its name still allows for copy and pasted names
109 {"TestFoo/bar/baz", "TestFoo", "bar/baz", true, false},
110 {"TestFoo/bar/baz", "TestFoo/bar", "baz", true, false},
111 {"TestFoo/bar/baz", "TestFoo", "x", false, false},
112 {"TestFoo", "TestBar", "x", false, false},
113 {"TestFoo/", "TestBar", "x", false, false},
114 {"TestFoo/bar/baz", "TestBar", "x/bar/baz", false, false},
117 {"", "TestFoo", "x", true, false},
118 {"/", "TestFoo", "x", true, false},
119 {"./", "TestFoo", "x", true, false},
120 {"./.", "TestFoo", "x", true, false},
121 {"/bar/baz", "TestFoo", "bar", true, true},
122 {"/bar/baz", "TestFoo", "bar/baz", true, false},
123 {"//baz", "TestFoo", "bar/baz", true, false},
124 {"//", "TestFoo", "bar/baz", true, false},
125 {"/bar/baz", "TestFoo/bar", "baz", true, false},
126 {"//foo", "TestFoo", "bar/baz", false, false},
127 {"/bar/baz", "TestFoo", "x", false, false},
128 {"/bar/baz", "TestBar", "x/bar/baz", false, false},
131 for _
, tc
:= range testCases
{
132 m
:= newMatcher(regexp
.MatchString
, tc
.pattern
, "-test.run")
134 parent
:= &common
{name
: tc
.parent
}
138 if n
, ok
, partial
:= m
.fullName(parent
, tc
.sub
); ok
!= tc
.ok || partial
!= tc
.partial
{
139 t
.Errorf("for pattern %q, fullName(parent=%q, sub=%q) = %q, ok %v partial %v; want ok %v partial %v",
140 tc
.pattern
, tc
.parent
, tc
.sub
, n
, ok
, partial
, tc
.ok
, tc
.partial
)
145 func TestNaming(t
*T
) {
146 m
:= newMatcher(regexp
.MatchString
, "", "")
148 parent
:= &common
{name
: "x", level
: 1} // top-level test.
150 // Rig the matcher with some preloaded values.
151 m
.subNames
["x/b"] = 1000
153 testCases
:= []struct {
164 {"a#01", "x/a#01"}, // user has subtest with this name.
165 {"a", "x/a"}, // doesn't conflict with this name.
166 {"a", "x/a#01#01"}, // conflict, add disambiguating string.
167 {"a", "x/a#02"}, // This string is claimed now, so resume
168 {"a", "x/a#03"}, // with counting.
169 {"a#02", "x/a#02#01"},
171 {"b", "x/b#1000"}, // rigged, see above
175 {"A:1 B:2", "x/A:1_B:2"},
176 {"s\t\r\u00a0", "x/s___"},
178 {"\U0010ffff", `x/\U0010ffff`},
181 for i
, tc
:= range testCases
{
182 if got
, _
, _
:= m
.fullName(parent
, tc
.name
); got
!= tc
.want
{
183 t
.Errorf("%d:%s: got %q; want %q", i
, tc
.name
, got
, tc
.want
)