refactor: dbm

This commit is contained in:
meilin.huang
2024-12-08 13:04:23 +08:00
parent ebc89e056f
commit e56788af3e
152 changed files with 4273 additions and 3715 deletions

View File

@@ -1,9 +1,10 @@
package stringx
import (
"github.com/stretchr/testify/require"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func TestTruncateStr(t *testing.T) {
@@ -12,20 +13,12 @@ func TestTruncateStr(t *testing.T) {
length int
want string
}{
{"123一二三", 0, ""},
{"123一二三", 1, "1"},
{"123一二三", 3, "123"},
{"123一二三", 4, "123"},
{"123一二三", 5, "123"},
{"123一二三", 6, "123一"},
{"123一二三", 7, "123一"},
{"123一二三", 11, "123一二"},
{"123一二三", 12, "123一二三"},
{"123一二三", 13, "123一二三"},
{"123一二三", 4, "123...三"},
{"123一二三", 5, "123...二三"},
}
for _, tc := range testCases {
t.Run(strconv.Itoa(tc.length), func(t *testing.T) {
got := TruncateStr(tc.data, tc.length)
got := Truncate(tc.data, tc.length, 3, "...")
require.Equal(t, tc.want, got)
})
}