util_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. dest map[string]interface{}
  11. }{
  12. {
  13. src: map[string]interface{}{
  14. "Key1": "value1",
  15. "key2": "value2",
  16. },
  17. dest: map[string]interface{}{
  18. "key1": "value1",
  19. "key2": "value2",
  20. },
  21. },
  22. {
  23. src: map[string]interface{}{
  24. "Key1": "value1",
  25. "Complex": map[string]interface{}{
  26. "Sub1": "sub_value1",
  27. },
  28. },
  29. dest: map[string]interface{}{
  30. "key1": "value1",
  31. "complex": map[string]interface{}{
  32. "sub1": "sub_value1",
  33. },
  34. },
  35. },
  36. {
  37. src: map[string]interface{}{
  38. "Key1": "value1",
  39. "Complex": map[string]interface{}{
  40. "Sub1": "sub_value1",
  41. "Sub1_2": map[string]interface{}{
  42. "Sub2": "sub2",
  43. },
  44. },
  45. },
  46. dest: map[string]interface{}{
  47. "key1": "value1",
  48. "complex": map[string]interface{}{
  49. "sub1": "sub_value1",
  50. "sub1_2": map[string]interface{}{
  51. "sub2": "sub2",
  52. },
  53. },
  54. },
  55. },
  56. }
  57. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  58. for i, tt := range tests {
  59. //fmt.Printf("Parsing SQL %q.\n", tt.s)
  60. result := LowercaseKeyMap(tt.src)
  61. if !reflect.DeepEqual(tt.dest, result) {
  62. t.Errorf("%d. \nstmt mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.dest, result)
  63. }
  64. }
  65. }