Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

71 řádky
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 TestToCamel(t *testing.T) {
  29. cases := [][]string{
  30. {"test_case", "TestCase"},
  31. {"test.case", "TestCase"},
  32. {"test", "Test"},
  33. {"TestCase", "TestCase"},
  34. {" test case ", "TestCase"},
  35. {"", ""},
  36. {"many_many_words", "ManyManyWords"},
  37. {"AnyKind of_string", "AnyKindOfString"},
  38. {"odd-fix", "OddFix"},
  39. {"numbers2And55with000", "Numbers2And55With000"},
  40. }
  41. for _, i := range cases {
  42. in := i[0]
  43. out := i[1]
  44. result := ToCamel(in)
  45. if result != out {
  46. t.Error("'" + result + "' != '" + out + "'")
  47. }
  48. }
  49. }
  50. func TestToLowerCamel(t *testing.T) {
  51. cases := [][]string{
  52. {"foo-bar", "fooBar"},
  53. {"TestCase", "testCase"},
  54. {"", ""},
  55. {"AnyKind of_string", "anyKindOfString"},
  56. {"AnyKind.of-string", "anyKindOfString"},
  57. }
  58. for _, i := range cases {
  59. in := i[0]
  60. out := i[1]
  61. result := ToLowerCamel(in)
  62. if result != out {
  63. t.Error("'" + result + "' != '" + out + "'")
  64. }
  65. }
  66. }