util_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package xsql
  2. import (
  3. "fmt"
  4. "reflect"
  5. "testing"
  6. )
  7. func TestLowercaseKeyMap(t *testing.T) {
  8. var tests = []struct {
  9. src map[string]interface{}
  10. expOrg map[string]interface{}
  11. dest map[string]interface{}
  12. }{
  13. {
  14. src: map[string]interface{}{
  15. "Key1": "value1",
  16. "key2": "value2",
  17. },
  18. expOrg: map[string]interface{} {
  19. "Key1": nil,
  20. "key2": nil,
  21. },
  22. dest: map[string]interface{}{
  23. "key1": "value1",
  24. "key2": "value2",
  25. },
  26. },
  27. {
  28. src: map[string]interface{}{
  29. "Key1": "value1",
  30. "Complex": map[string]interface{}{
  31. "Sub1": "sub_value1",
  32. },
  33. },
  34. expOrg: map[string]interface{} {
  35. "Key1": nil,
  36. "Complex": map[string]interface{} {
  37. "Sub1": nil,
  38. },
  39. },
  40. dest: map[string]interface{}{
  41. "key1": "value1",
  42. "complex": map[string]interface{}{
  43. "sub1": "sub_value1",
  44. },
  45. },
  46. },
  47. {
  48. src: map[string]interface{}{
  49. "Key1": "value1",
  50. "Complex": map[string]interface{}{
  51. "Sub1": "sub_value1",
  52. "Sub1_2": map[string]interface{}{
  53. "Sub2": "sub2",
  54. },
  55. },
  56. },
  57. expOrg: map[string]interface{} {
  58. "Key1": nil,
  59. "Complex": map[string]interface{}{
  60. "Sub1": nil,
  61. "Sub1_2": map[string]interface{}{
  62. "Sub2": nil,
  63. },
  64. },
  65. },
  66. dest: map[string]interface{}{
  67. "key1": "value1",
  68. "complex": map[string]interface{}{
  69. "sub1": "sub_value1",
  70. "sub1_2": map[string]interface{}{
  71. "sub2": "sub2",
  72. },
  73. },
  74. },
  75. },
  76. }
  77. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  78. for i, tt := range tests {
  79. //fmt.Printf("Parsing SQL %q.\n", tt.s)
  80. origKeys := make(map[string]interface{})
  81. result := LowercaseKeyMap(tt.src, origKeys)
  82. if !reflect.DeepEqual(tt.dest, result) {
  83. t.Errorf("%d. \nstmt mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.dest, result)
  84. }
  85. if !reflect.DeepEqual(tt.expOrg, origKeys) {
  86. t.Errorf("%d. \nstmt mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.dest, result)
  87. }
  88. }
  89. }