Files
convx/to_string_test.go
T

42 lines
939 B
Go
Raw Normal View History

2024-10-28 20:02:37 +08:00
package convx_test
import (
"testing"
"code.yun.ink/pkg/convx"
)
func TestToString(t *testing.T) {
2024-10-28 20:33:26 +08:00
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
2024-10-28 20:02:37 +08:00
}
2024-10-28 20:33:26 +08:00
for _, test := range tests {
str, err := convx.ToString(test.input)
if err != nil {
t.Errorf("convx.ToString(%v) failed with %v", test.input, err)
}
if str != test.expect {
t.Errorf("convx.ToString(%v) = %v, want %v", test.input, str, test.expect)
}
2024-10-28 20:02:37 +08:00
}
}