mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-06 15:37:01 +08:00
unit test jsonToStruct
This commit is contained in:
41
jsonUtil/to_string_test.go
Normal file
41
jsonUtil/to_string_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package jsonUtil
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestToString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value interface{}
|
||||
want string
|
||||
}{
|
||||
{"nil", nil, ""},
|
||||
{"string", "hello", "hello"},
|
||||
{"int", 42, "42"},
|
||||
{"int8", int8(42), "42"},
|
||||
{"int16", int16(42), "42"},
|
||||
{"int32", int32(42), "42"},
|
||||
{"int64", int64(42), "42"},
|
||||
{"uint", uint(42), "42"},
|
||||
{"uint8", uint8(42), "42"},
|
||||
{"uint16", uint16(42), "42"},
|
||||
{"uint32", uint32(42), "42"},
|
||||
{"uint64", uint64(42), "42"},
|
||||
{"float32", float32(3.14159), "3.14159"},
|
||||
{"float64", 3.14159, "3.14159"},
|
||||
{"bool-true", true, "true"},
|
||||
{"bool-false", false, "false"},
|
||||
{"complex64", complex64(1 + 2i), "(1+2i)"},
|
||||
{"complex128", complex128(3 + 4i), "(3+4i)"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := toString(tt.value); got != tt.want {
|
||||
t.Errorf("ToString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
if got := toStringReflect(tt.value); got != tt.want {
|
||||
t.Errorf("ToString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user