1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00

52 lines
1.0 KiB
Go
Raw Normal View History

2018-02-13 23:49:40 +08:00
package test
2018-02-14 08:58:59 +08:00
import (
"encoding/json"
2018-02-24 22:04:41 +08:00
"math/big"
2018-02-14 08:58:59 +08:00
)
2018-02-14 08:28:17 +08:00
2018-02-13 23:49:40 +08:00
func init() {
2018-02-14 08:58:59 +08:00
var pRawMessage = func(val json.RawMessage) *json.RawMessage {
return &val
}
2018-02-14 08:39:18 +08:00
nilMap := map[string]string(nil)
2018-02-13 23:49:40 +08:00
marshalCases = append(marshalCases,
map[string]interface{}{"abc": 1},
map[string]MyInterface{"hello": MyString("world")},
2018-02-14 08:28:17 +08:00
map[*big.Float]string{big.NewFloat(1.2): "2"},
map[string]interface{}{
"3": 3,
"1": 1,
"2": 2,
},
map[uint64]interface{}{
uint64(1): "a",
uint64(2): "a",
uint64(4): "a",
},
2018-02-14 08:39:18 +08:00
nilMap,
&nilMap,
2018-02-24 22:04:41 +08:00
map[string]*json.RawMessage{"hello": pRawMessage(json.RawMessage("[]"))},
2018-02-13 23:49:40 +08:00
)
2018-02-14 08:28:17 +08:00
unmarshalCases = append(unmarshalCases, unmarshalCase{
2018-02-24 22:04:41 +08:00
ptr: (*map[string]string)(nil),
2018-02-14 08:28:17 +08:00
input: `{"k\"ey": "val"}`,
2018-02-14 08:39:18 +08:00
}, unmarshalCase{
2018-02-24 22:04:41 +08:00
ptr: (*map[string]string)(nil),
2018-02-14 08:39:18 +08:00
input: `null`,
2018-02-14 08:58:59 +08:00
}, unmarshalCase{
2018-02-24 22:04:41 +08:00
ptr: (*map[string]*json.RawMessage)(nil),
2018-02-14 08:58:59 +08:00
input: "{\"test\":[{\"key\":\"value\"}]}",
2018-02-14 08:28:17 +08:00
})
2018-02-13 23:49:40 +08:00
}
type MyInterface interface {
Hello() string
}
type MyString string
func (ms MyString) Hello() string {
return string(ms)
}