mammoth2-test.go.tmpl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // +build !notfastpath
  2. // Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
  3. // Use of this source code is governed by a MIT license found in the LICENSE file.
  4. // Code generated from mammoth2-test.go.tmpl - DO NOT EDIT.
  5. package codec
  6. // Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go....
  7. //
  8. // Add:
  9. // - test file for creating a mammoth generated file as _mammoth_generated.go
  10. // - generate a second mammoth files in a different file: mammoth2_generated_test.go
  11. // - mammoth-test.go.tmpl will do this
  12. // - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags)
  13. // - as part of TestMammoth, run it also
  14. // - this will cover all the codecgen, gen-helper, etc in one full run
  15. // - check in mammoth* files into github also
  16. // - then
  17. //
  18. // Now, add some types:
  19. // - some that implement BinaryMarshal, TextMarshal, JSONMarshal, and one that implements none of it
  20. // - create a wrapper type that includes TestMammoth2, with it in slices, and maps, and the custom types
  21. // - this wrapper object is what we work encode/decode (so that the codecgen methods are called)
  22. // import "encoding/binary"
  23. import "fmt"
  24. type TestMammoth2 struct {
  25. {{range .Values }}{{if .Primitive }}{{/*
  26. */}}{{ .MethodNamePfx "F" true }} {{ .Primitive }}
  27. {{ .MethodNamePfx "Fptr" true }} *{{ .Primitive }}
  28. {{end}}{{end}}
  29. {{range .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/*
  30. */}}{{ .MethodNamePfx "F" false }} []{{ .Elem }}
  31. {{ .MethodNamePfx "Fptr" false }} *[]{{ .Elem }}
  32. {{end}}{{end}}{{end}}
  33. {{range .Values }}{{if not .Primitive }}{{if .MapKey }}{{/*
  34. */}}{{ .MethodNamePfx "F" false }} map[{{ .MapKey }}]{{ .Elem }}
  35. {{ .MethodNamePfx "Fptr" false }} *map[{{ .MapKey }}]{{ .Elem }}
  36. {{end}}{{end}}{{end}}
  37. }
  38. // -----------
  39. type testMammoth2Binary uint64
  40. func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) {
  41. data = make([]byte, 8)
  42. bigen.PutUint64(data, uint64(x))
  43. return
  44. }
  45. func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
  46. *x = testMammoth2Binary(bigen.Uint64(data))
  47. return
  48. }
  49. type testMammoth2Text uint64
  50. func (x testMammoth2Text) MarshalText() (data []byte, err error) {
  51. data = []byte(fmt.Sprintf("%b", uint64(x)))
  52. return
  53. }
  54. func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) {
  55. _, err = fmt.Sscanf(string(data), "%b", (*uint64)(x))
  56. return
  57. }
  58. type testMammoth2Json uint64
  59. func (x testMammoth2Json) MarshalJSON() (data []byte, err error) {
  60. data = []byte(fmt.Sprintf("%v", uint64(x)))
  61. return
  62. }
  63. func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) {
  64. _, err = fmt.Sscanf(string(data), "%v", (*uint64)(x))
  65. return
  66. }
  67. type testMammoth2Basic [4]uint64
  68. type TestMammoth2Wrapper struct {
  69. V TestMammoth2
  70. T testMammoth2Text
  71. B testMammoth2Binary
  72. J testMammoth2Json
  73. C testMammoth2Basic
  74. M map[testMammoth2Basic]TestMammoth2
  75. L []TestMammoth2
  76. A [4]int64
  77. }