You've already forked json-iterator
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:
@ -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\"}]}",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,8 @@ func init() {
|
||||
marshalCases = append(marshalCases,
|
||||
json.RawMessage("{}"),
|
||||
)
|
||||
unmarshalCases = append(unmarshalCases, unmarshalCase{
|
||||
ptr: (*json.RawMessage)(nil),
|
||||
input: `[1,2,3]`,
|
||||
})
|
||||
}
|
||||
|
@ -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")},
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user