-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_test.go
83 lines (74 loc) · 1.89 KB
/
string_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAnyString(t *testing.T) {
assert.Equal(t, "", AnyString())
assert.Equal(t, "", AnyString("", "", ""))
assert.Equal(t, "a", AnyString("a", "b"))
assert.Equal(t, "b", AnyString("b", "a"))
assert.Equal(t, "a", AnyString("a", "b", "c"))
}
func TestSub(t *testing.T) {
table := []struct {
Tag string
S1 []string
S2 []string
Diff []string
}{
{"t1", nil, nil, []string{}},
{"t2", []string{}, nil, []string{}},
{"t3", nil, []string{}, []string{}},
{"t4", []string{"a", "b"}, []string{}, []string{"a", "b"}},
{"t5", []string{"a", "b"}, []string{"a"}, []string{"b"}},
{"t6", []string{"a", "b"}, []string{"a", "c"}, []string{"b"}},
{"t7", []string{"a", "b"}, []string{"a", "b"}, []string{}},
}
for _, v := range table {
t.Run(v.Tag, func(t *testing.T) {
assert.Equal(t, v.Diff, Sub(v.S1, v.S2))
})
}
}
func TestIntersect(t *testing.T) {
table := []struct {
Tag string
S1 []string
S2 []string
Intersect []string
}{
{"t1", nil, nil, []string{}},
{"t2", []string{}, nil, []string{}},
{"t3", nil, []string{}, []string{}},
{"t4", []string{"a", "b"}, []string{}, []string{}},
{"t5", []string{"a", "b"}, []string{"a"}, []string{"a"}},
{"t6", []string{"a", "b"}, []string{"a", "c"}, []string{"a"}},
{"t7", []string{"a", "b"}, []string{"a", "b"}, []string{"a", "b"}},
}
for _, v := range table {
t.Run(v.Tag, func(t *testing.T) {
assert.Equal(t, v.Intersect, Intersect(v.S1, v.S2))
})
}
}
func TestLowerFirst(t *testing.T) {
table := []struct {
Tag string
Val string
Result string
}{
{"t1", "", ""},
{"t2", "a", "a"},
{"t3", "A", "a"},
{"t4", "ab", "ab"},
{"t5", "Ab", "ab"},
{"t6", "AB", "aB"},
{"t7", "aB", "aB"},
}
for _, v := range table {
t.Run(v.Tag, func(t *testing.T) {
assert.Equal(t, v.Result, LowerFirst(v.Val))
})
}
}