package convx_test import ( "testing" "code.yun.ink/pkg/convx" ) 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 } 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) } } }