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:48:12 +08:00
parent 64c1c67885
commit 658ff9ef15
4 changed files with 169 additions and 364 deletions

View File

@ -3,6 +3,7 @@ package test
import (
"time"
"encoding/json"
"bytes"
)
func init() {
@ -16,6 +17,23 @@ func init() {
Field int `json:"field"`
})(nil),
input: `{"field": null}`,
}, unmarshalCase{
ptr: (*struct {
ID int `json:"id"`
Payload map[string]interface{} `json:"payload"`
buf *bytes.Buffer
})(nil),
input: ` {"id":1, "payload":{"account":"123","password":"456"}}`,
}, unmarshalCase{
ptr: (*struct {
Field1 string
})(nil),
input: `{"Field\"1":"hello"}`,
}, unmarshalCase{
ptr: (*struct {
Field1 string
})(nil),
input: `{"\u0046ield1":"hello"}`,
})
marshalCases = append(marshalCases,
struct {
@ -77,6 +95,27 @@ func init() {
struct {
Field MyInterface `json:"field"`
}{MyString("hello")},
struct {
Field1 string `json:"field-1,omitempty"`
Field2 func() `json:"-"`
}{},
structRecursive{},
struct {
*CacheItem
// Omit bad keys
OmitMaxAge omit `json:"cacheAge,omitempty"`
// Add nice keys
MaxAge int `json:"max_age"`
}{
CacheItem: &CacheItem{
Key: "value",
MaxAge: 100,
},
MaxAge: 20,
},
structOrder{},
)
}
@ -84,4 +123,38 @@ type StructVarious struct {
Field0 string
Field1 []string
Field2 map[string]interface{}
}
type structRecursive struct {
Field1 string
Me *structRecursive
}
type omit *struct{}
type CacheItem struct {
Key string `json:"key"`
MaxAge int `json:"cacheAge"`
}
type orderA struct {
Field2 string
}
type orderC struct {
Field5 string
}
type orderB struct {
Field4 string
orderC
Field6 string
}
type structOrder struct {
Field1 string
orderA
Field3 string
orderB
Field7 string
}