-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.go
71 lines (56 loc) · 1.54 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
package lo
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChunkString(t *testing.T) {
is := assert.New(t)
result1 := ChunkString("12345", 2)
is.Equal([]string{"12", "34", "5"}, result1)
result2 := ChunkString("123456", 2)
is.Equal([]string{"12", "34", "56"}, result2)
result3 := ChunkString("123456", 6)
is.Equal([]string{"123456"}, result3)
result4 := ChunkString("123456", 10)
is.Equal([]string{"123456"}, result4)
result5 := ChunkString("", 2)
is.Equal([]string{""}, result5)
result6 := ChunkString("明1好休2林森", 2)
is.Equal([]string{"明1", "好休", "2林", "森"}, result6)
is.Panics(func() {
ChunkString("12345", 0)
})
}
func TestSubstring(t *testing.T) {
is := assert.New(t)
str1 := Substring("hello", 0, 0)
str2 := Substring("hello", 10, 2)
str3 := Substring("hello", -10, 2)
str4 := Substring("hello", 0, 10)
str5 := Substring("hello", 0, 2)
str6 := Substring("hello", 2, 2)
str7 := Substring("hello", 2, 5)
str8 := Substring("hello", 2, 3)
str9 := Substring("hello", 2, 4)
str10 := Substring("hello", -2, 4)
str11 := Substring("hello", -4, 1)
str12 := Substring("hello", -4, math.MaxUint)
is.Equal("", str1)
is.Equal("", str2)
is.Equal("he", str3)
is.Equal("hello", str4)
is.Equal("he", str5)
is.Equal("ll", str6)
is.Equal("llo", str7)
is.Equal("llo", str8)
is.Equal("llo", str9)
is.Equal("lo", str10)
is.Equal("e", str11)
is.Equal("ello", str12)
}
func TestRuneLength(t *testing.T) {
is := assert.New(t)
is.Equal(5, RuneLength("hellô"))
is.Equal(6, len("hellô"))
}