values_flex_test.go 2.0 KB

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