|
|
@ -94,10 +94,11 @@ func TestFilter(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestFirstN(t *testing.T) {
|
|
|
|
func TestFirstN(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
input string
|
|
|
|
input string
|
|
|
|
n int
|
|
|
|
n int
|
|
|
|
expect string
|
|
|
|
ellipsis string
|
|
|
|
|
|
|
|
expect string
|
|
|
|
}{
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "english string",
|
|
|
|
name: "english string",
|
|
|
@ -105,6 +106,13 @@ func TestFirstN(t *testing.T) {
|
|
|
|
n: 8,
|
|
|
|
n: 8,
|
|
|
|
expect: "anything",
|
|
|
|
expect: "anything",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "english string with ellipsis",
|
|
|
|
|
|
|
|
input: "anything that we use",
|
|
|
|
|
|
|
|
n: 8,
|
|
|
|
|
|
|
|
ellipsis: "...",
|
|
|
|
|
|
|
|
expect: "anything...",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "english string more",
|
|
|
|
name: "english string more",
|
|
|
|
input: "anything that we use",
|
|
|
|
input: "anything that we use",
|
|
|
@ -117,6 +125,13 @@ func TestFirstN(t *testing.T) {
|
|
|
|
n: 2,
|
|
|
|
n: 2,
|
|
|
|
expect: "我是",
|
|
|
|
expect: "我是",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "chinese string with ellipsis",
|
|
|
|
|
|
|
|
input: "我是中国人",
|
|
|
|
|
|
|
|
n: 2,
|
|
|
|
|
|
|
|
ellipsis: "...",
|
|
|
|
|
|
|
|
expect: "我是...",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "chinese string",
|
|
|
|
name: "chinese string",
|
|
|
|
input: "我是中国人",
|
|
|
|
input: "我是中国人",
|
|
|
@ -127,7 +142,7 @@ func TestFirstN(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
assert.Equal(t, test.expect, FirstN(test.input, test.n))
|
|
|
|
assert.Equal(t, test.expect, FirstN(test.input, test.n, test.ellipsis))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|