struct_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package test
  2. import (
  3. "time"
  4. "encoding/json"
  5. )
  6. func init() {
  7. unmarshalCases = append(unmarshalCases, unmarshalCase{
  8. ptr: (*struct {
  9. Field interface{}
  10. })(nil),
  11. input: `{"Field": "hello"}`,
  12. })
  13. marshalCases = append(marshalCases,
  14. struct {
  15. Field map[string]interface{}
  16. }{
  17. map[string]interface{}{"hello": "world"},
  18. },
  19. struct {
  20. Field map[string]interface{}
  21. Field2 string
  22. }{
  23. map[string]interface{}{"hello": "world"}, "",
  24. },
  25. struct {
  26. Field interface{}
  27. }{
  28. 1024,
  29. },
  30. struct {
  31. Field MyInterface
  32. }{
  33. MyString("hello"),
  34. },
  35. struct {
  36. F *float64
  37. }{},
  38. // TODO: fix this
  39. //struct {
  40. // *time.Time
  41. //}{},
  42. struct {
  43. *time.Time
  44. }{&time.Time{}},
  45. struct {
  46. *StructVarious
  47. }{&StructVarious{}},
  48. struct {
  49. *StructVarious
  50. }{},
  51. struct {
  52. Field1 int
  53. Field2 [1]*float64
  54. }{},
  55. struct {
  56. Field interface{} `json:"field,omitempty"`
  57. }{},
  58. struct {
  59. Field MyInterface `json:"field,omitempty"`
  60. }{},
  61. struct {
  62. Field MyInterface `json:"field,omitempty"`
  63. }{MyString("hello")},
  64. struct {
  65. Field json.Marshaler `json:"field"`
  66. }{},
  67. struct {
  68. Field MyInterface `json:"field"`
  69. }{},
  70. struct {
  71. Field MyInterface `json:"field"`
  72. }{MyString("hello")},
  73. )
  74. }
  75. type StructVarious struct {
  76. Field0 string
  77. Field1 []string
  78. Field2 map[string]interface{}
  79. }