-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfilters_test.go
78 lines (63 loc) · 1.72 KB
/
filters_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
package filter
import (
"fmt"
"testing"
"github.com/gookit/goutil/testutil/assert"
)
func TestTrim(t *testing.T) {
is := assert.New(t)
// Trim
tests := map[string]string{
"abc ": "",
" abc": "",
" abc ": "",
"abc,,": ",",
"abc,.": ",.",
}
for sample, cutSet := range tests {
is.Eq("abc", Trim(sample, cutSet))
}
is.Eq("abc", Trim("abc,.", ".,"))
// is.Eq("", Trim(nil))
// TrimLeft
is.Eq("abc ", TrimLeft(" abc "))
is.Eq("abc ,", TrimLeft(", abc ,", " ,"))
is.Eq("abc ,", TrimLeft(", abc ,", ", "))
// TrimRight
is.Eq(" abc", TrimRight(" abc "))
is.Eq(", abc", TrimRight(", abc ,", ", "))
// TrimStrings
ss := TrimStrings([]string{" a", "b ", " c "})
is.Eq("[a b c]", fmt.Sprint(ss))
ss = TrimStrings([]string{",a", "b.", ",.c,"}, ",.")
is.Eq("[a b c]", fmt.Sprint(ss))
}
func TestEmail(t *testing.T) {
is := assert.New(t)
is.Eq("[email protected]", Email(" [email protected] "))
is.Eq("inhere.xyz", Email(" inhere.xyz "))
}
func TestStrOperate(t *testing.T) {
is := assert.New(t)
// Substr
is.Eq("DEF", Substr("abcDEF", 3, 3))
is.Eq("DEF", Substr("abcDEF", 3, 5))
is.Eq("", Substr("abcDEF", 23, 5))
}
func TestURLEnDecode(t *testing.T) {
is := assert.New(t)
is.Eq("a.com/?name%3D%E4%BD%A0%E5%A5%BD", URLEncode("a.com/?name=你好"))
is.Eq("a.com/?name=你好", URLDecode("a.com/?name%3D%E4%BD%A0%E5%A5%BD"))
is.Eq("a.com", URLEncode("a.com"))
is.Eq("a.com", URLDecode("a.com"))
}
func TestUnique(t *testing.T) {
is := assert.New(t)
is.Len(Unique([]int{1, 2}), 2)
is.Len(Unique([]int{1, 2, 2, 1}), 2)
is.Len(Unique([]int64{1, 2}), 2)
is.Len(Unique([]int64{1, 2, 2, 1}), 2)
is.Len(Unique([]string{"a", "b"}), 2)
is.Len(Unique([]string{"a", "b", "b"}), 2)
is.Eq("invalid", Unique("invalid"))
}