-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringable_test.go
43 lines (35 loc) · 1.28 KB
/
stringable_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
package go_stringable
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestStringable_StrPad(t *testing.T) {
assert.Equal(t, "0001", StrPadLeft("1", rune('0'), 4))
assert.Equal(t, "1000", StrPadRight("1", rune('0'), 4))
assert.Equal(t, "0001", StrPadLeft("1", '0', 4))
assert.Equal(t, "1000", StrPadRight("1", '0', 4))
}
func TestStringable_Md5(t *testing.T) {
assert.Equal(t, "ebcd082fe9479bc278628297985ca2ba", Md5("Hyperf"))
assert.Equal(t, "ebcd082fe9479bc278628297985ca2ba", Md5ByteArray([]byte("Hyperf")))
}
func TestStringable_Random(t *testing.T) {
res, _ := Random(6)
assert.NotEmpty(t, res)
res, _ = RandomNumber(6)
assert.NotEmpty(t, res)
}
func TestStringable_Repeat(t *testing.T) {
assert.Equal(t, "****", Repeat("*", 4))
assert.Equal(t, "****", Repeat("**", 2))
}
func TestStringable_Mask(t *testing.T) {
assert.Equal(t, "***erf", Mask("Hyperf", 0, 3, "*"))
assert.Equal(t, "H***rf", Mask("Hyperf", 1, 3, "*"))
assert.Equal(t, "***erf", MaskByStar("Hyperf", 0, 3))
assert.Equal(t, "Hyp***", MaskLastByStar("Hyperf", 3))
assert.Equal(t, "Hy***f", Mask("Hyperf", -1, 3, "*"))
assert.Equal(t, "***erf", Mask("Hyperf", -3, 0, "*"))
assert.Equal(t, "******erf", Mask("Hyperf", -3, 6, "*"))
assert.Equal(t, "你好**", Mask("你好世界", 2, 2, "*"))
}