-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings_test.go
64 lines (57 loc) · 1.19 KB
/
strings_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
package strings_test
import (
"testing"
"github.com/x-punch/go-strings"
)
func TestRandomString(t *testing.T) {
if len(strings.GetRandomString(0)) != 0 {
t.Fail()
}
if len(strings.GetRandomString(10)) != 10 {
t.Fail()
}
}
func TestRandomNumber(t *testing.T) {
if len(strings.GetRandomNumber(0)) != 0 {
t.Fail()
}
if len(strings.GetRandomNumber(5)) != 5 {
t.Fail()
}
}
func TestSubString(t *testing.T) {
if "12345" != strings.SubString("123456789", 0, 5) {
t.Fail()
}
if "123456789" != strings.SubString("123456789", 0, 20) {
t.Fail()
}
if "456" != strings.SubString("123456789", 3, 3) {
t.Fail()
}
}
func TestContainString(t *testing.T) {
if !strings.ContainString("", ",", "") {
t.Fail()
}
if !strings.ContainString("123,456,abc,ddd", ",", "456") {
t.Fail()
}
if strings.ContainString("12.34.56,aa.admin.guest", ".", "aa") {
t.Fail()
}
if strings.ContainString("12.34.56,aa.admin.guest", ".", "") {
t.Fail()
}
}
func TestContains(t *testing.T) {
if !strings.ContainsInArray([]string{"12", "aa", "bb"}, "aa") {
t.Fail()
}
if strings.ContainsInArray([]string{"12", "aa", "334"}, "34") {
t.Fail()
}
if strings.ContainsInArray([]string{}, "34") {
t.Fail()
}
}