feat: 基础数据类型字符串转数组

This commit is contained in:
2025-10-13 14:42:54 +08:00
parent efab8cb6d2
commit 033e013510
3 changed files with 102 additions and 8 deletions

45
op_string/slice_test.go Normal file
View File

@ -0,0 +1,45 @@
// Package op_string ...
//
// Description : op_string ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-10-13 14:36
package op_string
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestToBaseTypeSlice(t *testing.T) {
Convey("序列化数据转数组成功", t, func() {
testData := `[1,2,3,4,5]`
res := ToBaseTypeSlice[uint](testData)
So(res.Value, ShouldNotBeNil)
So(res.Err, ShouldBeNil)
So(len(res.Value), ShouldEqual, 5)
})
Convey("序列化数据转数组失败", t, func() {
testData := `[1,2,3,4,-5]`
res := ToBaseTypeSlice[uint](testData)
So(res.Value, ShouldNotBeNil)
So(len(res.Value), ShouldEqual, 0)
So(res.Err, ShouldNotBeNil)
})
Convey("字符串转数组成功", t, func() {
testData := `1,2,3,4,5`
res := ToBaseTypeSlice[uint](testData, ",")
So(res.Value, ShouldNotBeNil)
So(res.Err, ShouldBeNil)
So(len(res.Value), ShouldEqual, 5)
})
Convey("字符串转数组失败", t, func() {
testData := `1,2,3,4,-5`
res := ToBaseTypeSlice[uint](testData)
So(res.Value, ShouldNotBeNil)
So(len(res.Value), ShouldEqual, 0)
So(res.Err, ShouldNotBeNil)
})
}