-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools_test.go
63 lines (56 loc) · 1.8 KB
/
tools_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package opt
import "testing"
// TestSts tests convert slice to string.
func TestSts(t *testing.T) {
type test struct {
value interface{}
result string
sep string
}
var tests = []test{
{[]int{1, 2, 3}, "1,2,3", ","},
{[]int{1, 2, 3}, "1:2:3", ":"},
{[]int{1, 2, 3}, "1 2 3", " "},
{[]string{"1", "2", "3"}, "1,2,3", ","},
{[]string{"a,b,c", "d,e,f", "g,h,i"}, "a,b,c@d,e,f@g,h,i", "@"},
{[]string{"a b c", "d e f", "g h i"}, "a b c@d e f@g h i", "@"},
}
for i, s := range tests {
if r := sts(s.value, s.sep); r != s.result {
t.Errorf("test %d is failed, expected %v but %v", i, s.result, r)
}
}
}
// TestSplit tests splits the string at the specified rune-marker ignoring
// the position of the marker inside of the group: `...`, '...', "..."
// and (...), {...}, [...].
func TestSplit(t *testing.T) {
type test struct {
n int
value string
result []string
}
var tests = []test{
{-1, "a,b,c", []string{"a", "b", "c"}},
{-1, "a,,c", []string{"a", "", "c"}},
{-1, "a,,", []string{"a", "", ""}},
{-1, "a,(b,c),d", []string{"a", "(b,c)", "d"}},
{-1, "a,\"b,c\",d", []string{"a", "\"b,c\"", "d"}},
{-1, "a,'b,c',d", []string{"a", "'b,c'", "d"}},
{-1, "a,`b,c`,d", []string{"a", "`b,c`", "d"}},
{-1, "a,b,c,d", []string{"a", "b", "c", "d"}},
{0, "a,b,c,d", []string{}},
{1, "a,b,c,d", []string{"a,b,c,d"}},
{2, "a,b,c,d", []string{"a", "b,c,d"}},
{3, "a,b,c,d", []string{"a", "b", "c,d"}},
{4, "a,b,c,d", []string{"a", "b", "c", "d"}},
{5, "a,b,c,d", []string{"a", "b", "c", "d"}},
{3, "a_b_c,, ,", []string{"a_b_c", "", " ,"}},
{-1, "a_b_c,, ,", []string{"a_b_c", "", " ", ""}},
}
for i, s := range tests {
if r := splitN(s.value, ",", s.n); sts(r, ":") != sts(s.result, ":") {
t.Errorf("test %d is failed, expected %v but %v", i, s.result, r)
}
}
}