選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

73 行
2.1 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. {"ID", "Id"},
  41. }
  42. for _, i := range cases {
  43. in := i[0]
  44. out := i[1]
  45. result := ToCamel(in)
  46. if result != out {
  47. t.Error("'" + result + "' != '" + out + "'")
  48. }
  49. }
  50. }
  51. func TestToLowerCamel(t *testing.T) {
  52. cases := [][]string{
  53. {"foo-bar", "fooBar"},
  54. {"TestCase", "testCase"},
  55. {"", ""},
  56. {"AnyKind of_string", "anyKindOfString"},
  57. {"AnyKind.of-string", "anyKindOfString"},
  58. {"ID", "id"},
  59. }
  60. for _, i := range cases {
  61. in := i[0]
  62. out := i[1]
  63. result := ToLowerCamel(in)
  64. if result != out {
  65. t.Error("'" + result + "' != '" + out + "'")
  66. }
  67. }
  68. }