Files
wrapper/op_string/slice_test.go

46 lines
1.1 KiB
Go

// 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)
})
}