You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015 Ian Coleman
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, Subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or Substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. package strcase
  25. import (
  26. "testing"
  27. )
  28. func TestToSnake(t *testing.T) {
  29. cases := [][]string{
  30. []string{"testCase", "test_case"},
  31. []string{"TestCase", "test_case"},
  32. []string{"Test Case", "test_case"},
  33. []string{" Test Case", "test_case"},
  34. []string{"Test Case ", "test_case"},
  35. []string{" Test Case ", "test_case"},
  36. []string{"test", "test"},
  37. []string{"test_case", "test_case"},
  38. []string{"Test", "test"},
  39. []string{"", ""},
  40. []string{"ManyManyWords", "many_many_words"},
  41. []string{"manyManyWords", "many_many_words"},
  42. []string{"AnyKind of_string", "any_kind_of_string"},
  43. []string{"numbers2and55with000", "numbers_2_and_55_with_000"},
  44. []string{"JSONData", "json_data"},
  45. []string{"userID", "user_id"},
  46. []string{"AAAbbb", "aa_abbb"},
  47. }
  48. for _, i := range cases {
  49. in := i[0]
  50. out := i[1]
  51. result := ToSnake(in)
  52. if result != out {
  53. t.Error("'" + result + "' != '" + out + "'")
  54. }
  55. }
  56. }