iface_test.go 812 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package test
  2. import "io"
  3. func init() {
  4. var pCloser1 = func(str string) *io.Closer {
  5. closer := io.Closer(strCloser1(str))
  6. return &closer
  7. }
  8. var pCloser2 = func(str string) *io.Closer {
  9. strCloser := strCloser2(str)
  10. closer := io.Closer(&strCloser)
  11. return &closer
  12. }
  13. marshalCases = append(marshalCases,
  14. pCloser1("hello"),
  15. pCloser2("hello"),
  16. )
  17. unmarshalCases = append(unmarshalCases, unmarshalCase{
  18. ptr: (*[]io.Closer)(nil),
  19. input: "[null]",
  20. }, unmarshalCase{
  21. obj: func() interface{} {
  22. strCloser := strCloser2("")
  23. return &struct {
  24. Field io.Closer
  25. }{
  26. &strCloser,
  27. }
  28. },
  29. input: `{"Field": "hello"}`,
  30. })
  31. }
  32. type strCloser1 string
  33. func (closer strCloser1) Close() error {
  34. return nil
  35. }
  36. type strCloser2 string
  37. func (closer *strCloser2) Close() error {
  38. return nil
  39. }