values_flex_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* // +build testing */
  2. // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
  3. // Use of this source code is governed by a MIT license found in the LICENSE file.
  4. package codec
  5. // This file contains values used by tests alone.
  6. // This is where we may try out different things,
  7. // that other engines may not support or may barf upon
  8. // e.g. custom extensions for wrapped types, maps with non-string keys, etc.
  9. type wrapInt64 int64
  10. type wrapUint8 uint8
  11. type wrapBytes []uint8
  12. var testWRepeated512 wrapBytes
  13. func init() {
  14. var testARepeated512 [512]byte
  15. for i := range testARepeated512 {
  16. testARepeated512[i] = 'A'
  17. }
  18. testWRepeated512 = wrapBytes(testARepeated512[:])
  19. }
  20. type TestStrucFlex struct {
  21. _struct struct{} `codec:",omitempty"` //set omitempty for every field
  22. testStrucCommon
  23. Mis map[int]string
  24. Mbu64 map[bool]struct{}
  25. Miwu64s map[int]wrapUint64Slice
  26. Mfwss map[float64]wrapStringSlice
  27. Mf32wss map[float32]wrapStringSlice
  28. Mui2wss map[uint64]wrapStringSlice
  29. Msu2wss map[stringUint64T]wrapStringSlice
  30. Ci64 wrapInt64
  31. Swrapbytes []wrapBytes
  32. Swrapuint8 []wrapUint8
  33. //M map[interface{}]interface{} `json:"-",bson:"-"`
  34. Mtsptr map[string]*TestStrucFlex
  35. Mts map[string]TestStrucFlex
  36. Its []*TestStrucFlex
  37. Nteststruc *TestStrucFlex
  38. }
  39. func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) {
  40. ts = &TestStrucFlex{
  41. Miwu64s: map[int]wrapUint64Slice{
  42. 5: []wrapUint64{1, 2, 3, 4, 5},
  43. 3: []wrapUint64{1, 2, 3},
  44. },
  45. Mf32wss: map[float32]wrapStringSlice{
  46. 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  47. 3.0: []wrapString{"1.0", "2.0", "3.0"},
  48. },
  49. Mui2wss: map[uint64]wrapStringSlice{
  50. 5: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  51. 3: []wrapString{"1.0", "2.0", "3.0"},
  52. },
  53. Mfwss: map[float64]wrapStringSlice{
  54. 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  55. 3.0: []wrapString{"1.0", "2.0", "3.0"},
  56. },
  57. Mis: map[int]string{
  58. 1: "one",
  59. 22: "twenty two",
  60. -44: "minus forty four",
  61. },
  62. Mbu64: map[bool]struct{}{false: {}, true: {}},
  63. Ci64: -22,
  64. Swrapbytes: []wrapBytes{ // lengths of 1, 2, 4, 8, 16, 32, 64, 128, 256,
  65. testWRepeated512[:1],
  66. testWRepeated512[:2],
  67. testWRepeated512[:4],
  68. testWRepeated512[:8],
  69. testWRepeated512[:16],
  70. testWRepeated512[:32],
  71. testWRepeated512[:64],
  72. testWRepeated512[:128],
  73. testWRepeated512[:256],
  74. testWRepeated512[:512],
  75. },
  76. Swrapuint8: []wrapUint8{
  77. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
  78. },
  79. }
  80. populateTestStrucCommon(&ts.testStrucCommon, n, bench, useInterface, useStringKeyOnly)
  81. if depth > 0 {
  82. depth--
  83. if ts.Mtsptr == nil {
  84. ts.Mtsptr = make(map[string]*TestStrucFlex)
  85. }
  86. if ts.Mts == nil {
  87. ts.Mts = make(map[string]TestStrucFlex)
  88. }
  89. ts.Mtsptr["0"] = newTestStrucFlex(depth, n, bench, useInterface, useStringKeyOnly)
  90. ts.Mts["0"] = *(ts.Mtsptr["0"])
  91. ts.Its = append(ts.Its, ts.Mtsptr["0"])
  92. }
  93. return
  94. }