feat: 字符串 -> 基础数据类型转换, 使用泛型实现
This commit is contained in:
32
op_string/base_test.go
Normal file
32
op_string/base_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Package op_string ...
|
||||
//
|
||||
// Description : op_string ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2025-10-13 11:28
|
||||
package op_string
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestToBaseValue(t *testing.T) {
|
||||
Convey("测试ToBaseValue - uint64 转换成功", t, func() {
|
||||
res := ToBaseValue[uint64]("12345")
|
||||
So(res.Err, ShouldBeNil)
|
||||
So(res.Value, ShouldEqual, uint64(12345))
|
||||
So(reflect.TypeOf(res.Value).Kind(), ShouldEqual, reflect.Uint64)
|
||||
So(reflect.TypeOf(res.Value).Kind(), ShouldNotEqual, reflect.Uint32)
|
||||
})
|
||||
Convey("测试ToBaseValue - uint64 转换失败", t, func() {
|
||||
res := ToBaseValue[uint64]("s12345")
|
||||
So(res.Err, ShouldNotBeNil)
|
||||
So(res.Value, ShouldEqual, 0)
|
||||
So(reflect.TypeOf(res.Value).Kind(), ShouldEqual, reflect.Uint64)
|
||||
So(reflect.TypeOf(res.Value).Kind(), ShouldNotEqual, reflect.Uint32)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user