mammoth-test.go.tmpl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
  2. // Use of this source code is governed by a MIT license found in the LICENSE file.
  3. // ************************************************************
  4. // DO NOT EDIT.
  5. // THIS FILE IS AUTO-GENERATED from mammoth-test.go.tmpl
  6. // ************************************************************
  7. package codec
  8. import "testing"
  9. import "fmt"
  10. // TestMammoth has all the different paths optimized in fast-path
  11. // It has all the primitives, slices and maps.
  12. //
  13. // For each of those types, it has a pointer and a non-pointer field.
  14. func init() { _ = fmt.Printf } // so we can include fmt as needed
  15. type TestMammoth struct {
  16. {{range .Values }}{{if .Primitive }}{{/*
  17. */}}{{ .MethodNamePfx "F" true }} {{ .Primitive }}
  18. {{ .MethodNamePfx "Fptr" true }} *{{ .Primitive }}
  19. {{end}}{{end}}
  20. {{range .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/*
  21. */}}{{ .MethodNamePfx "F" false }} []{{ .Elem }}
  22. {{ .MethodNamePfx "Fptr" false }} *[]{{ .Elem }}
  23. {{end}}{{end}}{{end}}
  24. {{range .Values }}{{if not .Primitive }}{{if .MapKey }}{{/*
  25. */}}{{ .MethodNamePfx "F" false }} map[{{ .MapKey }}]{{ .Elem }}
  26. {{ .MethodNamePfx "Fptr" false }} *map[{{ .MapKey }}]{{ .Elem }}
  27. {{end}}{{end}}{{end}}
  28. }
  29. {{range .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/*
  30. */}} type {{ .MethodNamePfx "type" false }} []{{ .Elem }}
  31. func (_ {{ .MethodNamePfx "type" false }}) MapBySlice() { }
  32. {{end}}{{end}}{{end}}
  33. func doTestMammothSlices(t *testing.T, h Handle) {
  34. {{range $i, $e := .Values }}{{if not .Primitive }}{{if not .MapKey }}{{/*
  35. */}}
  36. for _, v := range [][]{{ .Elem }}{ nil, []{{ .Elem }}{}, []{{ .Elem }}{ {{ nonzerocmd .Elem }}, {{ nonzerocmd .Elem }} } } {
  37. // fmt.Printf(">>>> running mammoth slice v{{$i}}: %v\n", v)
  38. var v{{$i}}v1, v{{$i}}v2, v{{$i}}v3, v{{$i}}v4 []{{ .Elem }}
  39. v{{$i}}v1 = v
  40. bs{{$i}} := testMarshalErr(v{{$i}}v1, h, t, "enc-slice-v{{$i}}")
  41. if v != nil { v{{$i}}v2 = make([]{{ .Elem }}, len(v)) }
  42. testUnmarshalErr(v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}")
  43. testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, t, "equal-slice-v{{$i}}")
  44. bs{{$i}} = testMarshalErr(&v{{$i}}v1, h, t, "enc-slice-v{{$i}}-p")
  45. v{{$i}}v2 = nil
  46. testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}-p")
  47. testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, t, "equal-slice-v{{$i}}-p")
  48. // ...
  49. v{{$i}}v2 = nil
  50. if v != nil { v{{$i}}v2 = make([]{{ .Elem }}, len(v)) }
  51. v{{$i}}v3 = {{ .MethodNamePfx "type" false }}(v{{$i}}v1)
  52. bs{{$i}} = testMarshalErr(v{{$i}}v3, h, t, "enc-slice-v{{$i}}-custom")
  53. v{{$i}}v4 = {{ .MethodNamePfx "type" false }}(v{{$i}}v2)
  54. testUnmarshalErr(v{{$i}}v4, bs{{$i}}, h, t, "dec-slice-v{{$i}}-custom")
  55. testDeepEqualErr(v{{$i}}v3, v{{$i}}v4, t, "equal-slice-v{{$i}}-custom")
  56. v{{$i}}v2 = nil
  57. bs{{$i}} = testMarshalErr(&v{{$i}}v3, h, t, "enc-slice-v{{$i}}-custom-p")
  58. v{{$i}}v4 = {{ .MethodNamePfx "type" false }}(v{{$i}}v2)
  59. testUnmarshalErr(&v{{$i}}v4, bs{{$i}}, h, t, "dec-slice-v{{$i}}-custom-p")
  60. testDeepEqualErr(v{{$i}}v3, v{{$i}}v4, t, "equal-slice-v{{$i}}-custom-p")
  61. }
  62. {{end}}{{end}}{{end}}
  63. }
  64. func doTestMammothMaps(t *testing.T, h Handle) {
  65. {{range $i, $e := .Values }}{{if not .Primitive }}{{if .MapKey }}{{/*
  66. */}}
  67. for _, v := range []map[{{ .MapKey }}]{{ .Elem }}{ nil, map[{{ .MapKey }}]{{ .Elem }}{}, map[{{ .MapKey }}]{{ .Elem }}{ {{ nonzerocmd .MapKey }}:{{ nonzerocmd .Elem }} } } {
  68. // fmt.Printf(">>>> running mammoth map v{{$i}}: %v\n", v)
  69. var v{{$i}}v1, v{{$i}}v2 map[{{ .MapKey }}]{{ .Elem }}
  70. v{{$i}}v1 = v
  71. bs{{$i}} := testMarshalErr(v{{$i}}v1, h, t, "enc-map-v{{$i}}")
  72. if v != nil { v{{$i}}v2 = make(map[{{ .MapKey }}]{{ .Elem }}, len(v)) }
  73. testUnmarshalErr(v{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}")
  74. testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, t, "equal-map-v{{$i}}")
  75. bs{{$i}} = testMarshalErr(&v{{$i}}v1, h, t, "enc-map-v{{$i}}-p")
  76. v{{$i}}v2 = nil
  77. testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p")
  78. testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, t, "equal-map-v{{$i}}-p")
  79. }
  80. {{end}}{{end}}{{end}}
  81. }
  82. func doTestMammothMapsAndSlices(t *testing.T, h Handle) {
  83. doTestMammothSlices(t, h)
  84. doTestMammothMaps(t, h)
  85. }