map_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package test
  2. import (
  3. "encoding/json"
  4. "math/big"
  5. )
  6. func init() {
  7. var pRawMessage = func(val json.RawMessage) *json.RawMessage {
  8. return &val
  9. }
  10. nilMap := map[string]string(nil)
  11. marshalCases = append(marshalCases,
  12. map[string]interface{}{"abc": 1},
  13. map[string]MyInterface{"hello": MyString("world")},
  14. map[*big.Float]string{big.NewFloat(1.2): "2"},
  15. map[string]interface{}{
  16. "3": 3,
  17. "1": 1,
  18. "2": 2,
  19. },
  20. map[uint64]interface{}{
  21. uint64(1): "a",
  22. uint64(2): "a",
  23. uint64(4): "a",
  24. },
  25. nilMap,
  26. &nilMap,
  27. map[string]*json.RawMessage{"hello": pRawMessage(json.RawMessage("[]"))},
  28. )
  29. unmarshalCases = append(unmarshalCases, unmarshalCase{
  30. ptr: (*map[string]string)(nil),
  31. input: `{"k\"ey": "val"}`,
  32. }, unmarshalCase{
  33. ptr: (*map[string]string)(nil),
  34. input: `null`,
  35. }, unmarshalCase{
  36. ptr: (*map[string]*json.RawMessage)(nil),
  37. input: "{\"test\":[{\"key\":\"value\"}]}",
  38. })
  39. }
  40. type MyInterface interface {
  41. Hello() string
  42. }
  43. type MyString string
  44. func (ms MyString) Hello() string {
  45. return string(ms)
  46. }