Files
convx/to_string_test.go
T
2025-09-02 15:43:26 +08:00

46 lines
931 B
Go

package convx_test
import (
"testing"
"code.yun.ink/pkg/convx"
)
type TestStr string
const (
TestStrOne TestStr = "1"
)
func TestToString(t *testing.T) {
var tests = []struct {
input interface{}
expect string
}{
{"1", "1"}, //string
{1, "1"}, //int
{int8(1), "1"}, //int8
{int16(1), "1"}, //int16
{-1, "-1"}, //int32
{int64(1), "1"}, //int64
{float32(1.1), "1.1"}, //float32
{float64(1.1), "1.1"}, //float64
{true, "true"}, //bool
{uint(1), "1"}, //uint
{uint8(1), "1"}, //uint8
{uint16(1), "1"}, //uint16
{uint32(1), "1"}, //uint32
{uint64(1), "1"}, //uint64
{TestStrOne, "1"}, //custom type
}
for _, test := range tests {
str := convx.ToString(test.input)
if str != test.expect {
t.Errorf("convx.ToString(%v) = %v, want %v", test.input, str, test.expect)
}
}
}