Files
mayfly-go/server/pkg/utils/stringx/stringx_test.go

26 lines
459 B
Go
Raw Normal View History

package stringx
import (
"strconv"
"testing"
2024-12-08 13:04:23 +08:00
"github.com/stretchr/testify/require"
)
func TestTruncateStr(t *testing.T) {
testCases := []struct {
data string
length int
want string
}{
2024-12-08 13:04:23 +08:00
{"123一二三", 4, "123...三"},
{"123一二三", 5, "123...二三"},
}
for _, tc := range testCases {
t.Run(strconv.Itoa(tc.length), func(t *testing.T) {
2024-12-08 13:04:23 +08:00
got := Truncate(tc.data, tc.length, 3, "...")
require.Equal(t, tc.want, got)
})
}
}