eface_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package test
  2. func init() {
  3. var pEFace = func(val interface{}) *interface{} {
  4. return &val
  5. }
  6. var pInt = func(val int) *int {
  7. return &val
  8. }
  9. unmarshalCases = append(unmarshalCases, unmarshalCase{
  10. ptr: (**interface{})(nil),
  11. input: `"hello"`,
  12. }, unmarshalCase{
  13. ptr: (**interface{})(nil),
  14. input: `1e1`,
  15. }, unmarshalCase{
  16. ptr: (**interface{})(nil),
  17. input: `1.0e1`,
  18. }, unmarshalCase{
  19. ptr: (*[]interface{})(nil),
  20. input: `[1.0e1]`,
  21. }, unmarshalCase{
  22. ptr: (*struct {
  23. Field interface{}
  24. })(nil),
  25. input: `{"field":"hello"}`,
  26. }, unmarshalCase{
  27. obj: func() interface{} {
  28. type TestData struct {
  29. Name string `json:"name"`
  30. }
  31. o := &TestData{}
  32. return &o
  33. },
  34. input: `{"name":"value"}`,
  35. }, unmarshalCase{
  36. obj: func() interface{} {
  37. b := true
  38. return &struct {
  39. Field interface{} `json:"field"`
  40. }{&b}
  41. },
  42. input: `{"field": null}`,
  43. }, unmarshalCase{
  44. obj: func() interface{} {
  45. var pb *bool
  46. return &struct {
  47. Field interface{} `json:"field"`
  48. }{&pb}
  49. },
  50. input: `{"field": null}`,
  51. }, unmarshalCase{
  52. obj: func() interface{} {
  53. b := true
  54. pb := &b
  55. return &struct {
  56. Field interface{} `json:"field"`
  57. }{&pb}
  58. },
  59. input: `{"field": null}`,
  60. })
  61. marshalCases = append(marshalCases,
  62. pEFace("hello"),
  63. struct {
  64. Field interface{}
  65. }{"hello"},
  66. struct {
  67. Field interface{}
  68. }{struct {
  69. field chan int
  70. }{}},
  71. struct {
  72. Field interface{}
  73. }{struct {
  74. Field *int
  75. }{pInt(100)}},
  76. )
  77. }