-
-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathstring_test.go
More file actions
79 lines (70 loc) · 1.54 KB
/
Copy pathstring_test.go
File metadata and controls
79 lines (70 loc) · 1.54 KB
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
79
//go:build go1.23
package it
import (
"slices"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChunkString(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
size int
expected []string
}{
{
name: "size smaller than length, remainder",
input: "12345",
size: 2,
expected: []string{"12", "34", "5"},
},
{
name: "size smaller than length, exact",
input: "123456",
size: 2,
expected: []string{"12", "34", "56"},
},
{
name: "size equal to length",
input: "123456",
size: 6,
expected: []string{"123456"},
},
{
name: "size greater than length",
input: "123456",
size: 10,
expected: []string{"123456"},
},
{
name: "empty string",
input: "",
size: 2,
expected: []string{""}, // @TODO: should be [] - see https://github.com/samber/lo/issues/788
},
{
name: "multi-byte runes",
input: "明1好休2林森",
size: 2,
expected: []string{"明1", "好休", "2林", "森"},
},
}
for _, tt := range tests {
tt := tt //nolint:modernize
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
is := assert.New(t)
result := ChunkString(tt.input, tt.size)
assertSeqSupportBreak(t, result)
is.Equal(tt.expected, slices.Collect(result))
})
}
t.Run("panics on non-positive size", func(t *testing.T) {
t.Parallel()
is := assert.New(t)
is.PanicsWithValue("it.ChunkString: size must be greater than 0", func() {
ChunkString("12345", 0)
})
})
}