优化any转string
This commit is contained in:
+8
-4
@@ -6,6 +6,12 @@ import (
|
||||
"code.yun.ink/pkg/convx"
|
||||
)
|
||||
|
||||
type TestStr string
|
||||
|
||||
const (
|
||||
TestStrOne TestStr = "1"
|
||||
)
|
||||
|
||||
func TestToString(t *testing.T) {
|
||||
|
||||
var tests = []struct {
|
||||
@@ -26,13 +32,11 @@ func TestToString(t *testing.T) {
|
||||
{uint16(1), "1"}, //uint16
|
||||
{uint32(1), "1"}, //uint32
|
||||
{uint64(1), "1"}, //uint64
|
||||
{TestStrOne, "1"}, //custom type
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
str, err := convx.ToString(test.input)
|
||||
if err != nil {
|
||||
t.Errorf("convx.ToString(%v) failed with %v", test.input, err)
|
||||
}
|
||||
str := convx.ToString(test.input)
|
||||
if str != test.expect {
|
||||
t.Errorf("convx.ToString(%v) = %v, want %v", test.input, str, test.expect)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user