|
|
@ -2777,6 +2777,36 @@ func TestUnmarshalJsonReaderComplex(t *testing.T) {
|
|
|
|
assert.Equal(t, "txt", req.Txt)
|
|
|
|
assert.Equal(t, "txt", req.Txt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderArrayBool(t *testing.T) {
|
|
|
|
|
|
|
|
payload := `{"id": false}`
|
|
|
|
|
|
|
|
var res struct {
|
|
|
|
|
|
|
|
ID []string `json:"id"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderArrayInt(t *testing.T) {
|
|
|
|
|
|
|
|
payload := `{"id": 123}`
|
|
|
|
|
|
|
|
var res struct {
|
|
|
|
|
|
|
|
ID []string `json:"id"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderArrayString(t *testing.T) {
|
|
|
|
|
|
|
|
payload := `{"id": "123"}`
|
|
|
|
|
|
|
|
var res struct {
|
|
|
|
|
|
|
|
ID []string `json:"id"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkDefaultValue(b *testing.B) {
|
|
|
|
func BenchmarkDefaultValue(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
var a struct {
|
|
|
|
var a struct {
|
|
|
@ -2789,14 +2819,3 @@ func BenchmarkDefaultValue(b *testing.B) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestUnmarshalJsonReaderArray(t *testing.T) {
|
|
|
|
|
|
|
|
payload := "{\"id\": 123}"
|
|
|
|
|
|
|
|
var res struct {
|
|
|
|
|
|
|
|
ID []string `json:"id"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := strings.NewReader(payload)
|
|
|
|
|
|
|
|
err := UnmarshalJsonReader(reader, &res)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(res.ID))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|