1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add JoinFunc

This commit is contained in:
dudaodong
2024-10-24 14:56:13 +08:00
parent 921f218ef7
commit 2015d36b08
5 changed files with 126 additions and 0 deletions

View File

@@ -1816,3 +1816,43 @@ func TestFrequency(t *testing.T) {
assert.Equal(expected, result)
})
}
func TestJoinFunc(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestJoinFunc")
t.Run("basic case", func(t *testing.T) {
result := JoinFunc([]int{1, 2, 3}, ", ", func(i int) int {
return i * 2
})
expected := "2, 4, 6"
assert.Equal(expected, result)
})
t.Run("empty slice", func(t *testing.T) {
result := JoinFunc([]int{}, ", ", func(i int) int {
return i * 2
})
assert.Equal("", result)
})
t.Run("single element slice", func(t *testing.T) {
result := JoinFunc([]int{1}, ", ", func(i int) int {
return i * 2
})
assert.Equal("2", result)
})
t.Run("string slice", func(t *testing.T) {
result := JoinFunc([]string{"a", "b", "c"}, ", ", func(s string) string {
return strings.ToUpper(s)
})
expected := "A, B, C"
assert.Equal(expected, result)
})
}