Debian Codegraph @

value_tests/map_test.go

raw ◀ ▶
1 Debian patch touch this file
1 package test
2
3 import (
4 "encoding/json"
5 "math/big"
6 )
7
•8
9 func init() {
10 var pRawMessage = func(val json.RawMessage) *json.RawMessage {
11 return &val
12 }
13 nilMap := map[string]string(nil)
14 marshalCases = append(marshalCases,
15 map[string]interface{}{"abc": 1},
16 map[string]MyInterface{"hello": MyString("world")},
17 map[*big.Float]string{big.NewFloat(1.2): "2"},
18 map[string]interface{}{
19 "3": 3,
20 "1": 1,
21 "2": 2,
22 },
23 map[uint64]interface{}{
24 uint64(1): "a",
25 uint64(2): "a",
26 uint64(4): "a",
27 },
28 nilMap,
29 &nilMap,
30 map[string]*json.RawMessage{"hello": pRawMessage(json.RawMessage("[]"))},
31 map[customKey]string{customKey(1): "bar"},
32 )
33 unmarshalCases = append(unmarshalCases, unmarshalCase{
34 ptr: (*map[string]string)(nil),
35 input: `{"k\"ey": "val"}`,
36 }, unmarshalCase{
37 ptr: (*map[string]string)(nil),
38 input: `null`,
39 }, unmarshalCase{
40 ptr: (*map[string]*json.RawMessage)(nil),
41 input: "{\"test\":[{\"key\":\"value\"}]}",
42 }, unmarshalCase{
•43 ptr: (*map[customKey]string)(nil),
44 input: `{"foo": "bar"}`,
45 })
46 }
47
48 type MyInterface interface {
49 Hello() string
50 }
51
52 type MyString string
53
54 func (ms MyString) Hello() string {
55 return string(ms)
56 }
57
58 type customKey int32
59
•60
61 func (c customKey) MarshalText() ([]byte, error) {
62 return []byte("foo"), nil
63 }
64
65 func (c *customKey) UnmarshalText(value []byte) error {
66 *c = 1
67 return nil
68 }