-
Notifications
You must be signed in to change notification settings - Fork 191
/
fiter_test.go
48 lines (40 loc) · 1.19 KB
/
fiter_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
package strutil_test
import (
"testing"
"github.com/gookit/goutil/strutil"
"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", strutil.Trim(sample, cutSet))
}
is.Eq("abc", strutil.Trim("abc,.", ".,"))
is.Eq("abc", strutil.Trim(", abc ,", ",", " "))
// TrimLeft
is.Eq("abc ", strutil.Ltrim(" abc "))
is.Eq("abc ", strutil.LTrim(" abc "))
is.Eq("abc ,", strutil.TrimLeft(", abc ,", " ,"))
is.Eq("abc ,", strutil.TrimLeft(", abc ,", ", "))
is.Eq("abc ,", strutil.TrimLeft(", abc ,", ",", " "))
is.Eq(" abc ,", strutil.TrimLeft(", abc ,", ","))
// TrimRight
is.Eq(" abc", strutil.Rtrim(" abc "))
is.Eq(" abc", strutil.RTrim(" abc "))
is.Eq(", abc", strutil.TrimRight(", abc ,", ", "))
is.Eq(", abc ", strutil.TrimRight(", abc ,", ","))
is.Eq(", abc", strutil.TrimRight(", abc ,", ",", " "))
}
func TestFilterEmail(t *testing.T) {
is := assert.New(t)
is.Eq("[email protected]", strutil.FilterEmail(" [email protected] "))
is.Eq("inhere.xyz", strutil.FilterEmail(" inhere.xyz "))
}