优化any转string

This commit is contained in:
Yun
2025-09-02 15:43:26 +08:00
parent ab8524e5ef
commit 15e1ed41f4
5 changed files with 297 additions and 70 deletions
+8 -4
View File
@@ -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)
}