values_flex_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 and benchmarks.
  6. type testInt64 int64
  7. type TestStrucFlex struct {
  8. _struct struct{} `codec:",omitempty"` //set omitempty for every field
  9. testStrucCommon
  10. Ci64 testInt64 // added here, so we can execute the extension paths
  11. Mis map[int]string
  12. Mbu64 map[bool]struct{}
  13. Miwu64s map[int]wrapUint64Slice
  14. Mfwss map[float64]wrapStringSlice
  15. Mf32wss map[float32]wrapStringSlice
  16. Mui2wss map[uint64]wrapStringSlice
  17. Msu2wss map[stringUint64T]wrapStringSlice
  18. //M map[interface{}]interface{} `json:"-",bson:"-"`
  19. Mtsptr map[string]*TestStrucFlex
  20. Mts map[string]TestStrucFlex
  21. Its []*TestStrucFlex
  22. Nteststruc *TestStrucFlex
  23. }
  24. func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) {
  25. ts = &TestStrucFlex{
  26. Ci64: -22,
  27. Miwu64s: map[int]wrapUint64Slice{
  28. 5: []wrapUint64{1, 2, 3, 4, 5},
  29. 3: []wrapUint64{1, 2, 3},
  30. },
  31. Mf32wss: map[float32]wrapStringSlice{
  32. 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  33. 3.0: []wrapString{"1.0", "2.0", "3.0"},
  34. },
  35. Mui2wss: map[uint64]wrapStringSlice{
  36. 5: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  37. 3: []wrapString{"1.0", "2.0", "3.0"},
  38. },
  39. Mfwss: map[float64]wrapStringSlice{
  40. 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"},
  41. 3.0: []wrapString{"1.0", "2.0", "3.0"},
  42. },
  43. Mis: map[int]string{
  44. 1: "one",
  45. 22: "twenty two",
  46. -44: "minus forty four",
  47. },
  48. Mbu64: map[bool]struct{}{false: {}, true: {}},
  49. }
  50. populateTestStrucCommon(&ts.testStrucCommon, n, bench, useInterface, useStringKeyOnly)
  51. if depth > 0 {
  52. depth--
  53. if ts.Mtsptr == nil {
  54. ts.Mtsptr = make(map[string]*TestStrucFlex)
  55. }
  56. if ts.Mts == nil {
  57. ts.Mts = make(map[string]TestStrucFlex)
  58. }
  59. ts.Mtsptr["0"] = newTestStrucFlex(depth, n, bench, useInterface, useStringKeyOnly)
  60. ts.Mts["0"] = *(ts.Mtsptr["0"])
  61. ts.Its = append(ts.Its, ts.Mtsptr["0"])
  62. }
  63. return
  64. }