1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-12 22:47:42 +02:00

consolidate more tests

This commit is contained in:
Tao Wen
2018-02-14 08:58:59 +08:00
parent 658ff9ef15
commit a8708bca85
6 changed files with 54 additions and 108 deletions

View File

@ -1,8 +1,14 @@
package test
import "math/big"
import (
"math/big"
"encoding/json"
)
func init() {
var pRawMessage = func(val json.RawMessage) *json.RawMessage {
return &val
}
nilMap := map[string]string(nil)
marshalCases = append(marshalCases,
map[string]interface{}{"abc": 1},
@ -20,6 +26,7 @@ func init() {
},
nilMap,
&nilMap,
map[string]*json.RawMessage{"hello":pRawMessage(json.RawMessage("[]"))},
)
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*map[string]string)(nil),
@ -27,6 +34,9 @@ func init() {
}, unmarshalCase{
ptr: (*map[string]string)(nil),
input: `null`,
}, unmarshalCase{
ptr: (*map[string]*json.RawMessage)(nil),
input: "{\"test\":[{\"key\":\"value\"}]}",
})
}

View File

@ -4,6 +4,9 @@ func init() {
var pEFace = func(val interface{}) *interface{} {
return &val
}
var pInt = func(val int) *int {
return &val
}
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (**interface{})(nil),
input: `"hello"`,
@ -16,5 +19,7 @@ func init() {
})
marshalCases = append(marshalCases,
pEFace("hello"),
(*int)(nil),
pInt(100),
)
}
}

View File

@ -6,4 +6,8 @@ func init() {
marshalCases = append(marshalCases,
json.RawMessage("{}"),
)
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*json.RawMessage)(nil),
input: `[1,2,3]`,
})
}

View File

@ -7,6 +7,9 @@ import (
)
func init() {
var pString = func(val string) *string {
return &val
}
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*struct {
Field interface{}
@ -34,6 +37,18 @@ func init() {
Field1 string
})(nil),
input: `{"\u0046ield1":"hello"}`,
}, unmarshalCase{
ptr: (*struct {
Field1 *string
Field2 *string
})(nil),
input: `{"field1": null, "field2": "world"}`,
}, unmarshalCase{
ptr: (*struct {
Field1 string
Field2 json.RawMessage
})(nil),
input: `{"field1": "hello", "field2":[1,2,3]}`,
})
marshalCases = append(marshalCases,
struct {
@ -116,6 +131,10 @@ func init() {
MaxAge: 20,
},
structOrder{},
struct {
Field1 *string
Field2 *string
}{Field2: pString("world")},
)
}