Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

148 строки
3.7 KiB

  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015 Ian Coleman
  5. * Copyright (c) 2018 Ma_124, <github.com/Ma124>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, Subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or Substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. package strcase
  26. import (
  27. "testing"
  28. )
  29. func TestToSnake(t *testing.T) {
  30. cases := [][]string{
  31. {"testCase", "test_case"},
  32. {"TestCase", "test_case"},
  33. {"Test Case", "test_case"},
  34. {" Test Case", "test_case"},
  35. {"Test Case ", "test_case"},
  36. {" Test Case ", "test_case"},
  37. {"test", "test"},
  38. {"test_case", "test_case"},
  39. {"Test", "test"},
  40. {"", ""},
  41. {"ManyManyWords", "many_many_words"},
  42. {"manyManyWords", "many_many_words"},
  43. {"AnyKind of_string", "any_kind_of_string"},
  44. {"numbers2and55with000", "numbers_2_and_55_with_000"},
  45. {"JSONData", "json_data"},
  46. {"userID", "user_id"},
  47. {"AAAbbb", "aa_abbb"},
  48. }
  49. for _, i := range cases {
  50. in := i[0]
  51. out := i[1]
  52. result := ToSnake(in)
  53. if result != out {
  54. t.Error("'" + in + "'('" + result + "' != '" + out + "')")
  55. }
  56. }
  57. }
  58. func TestToDelimited(t *testing.T) {
  59. cases := [][]string{
  60. {"testCase", "test@case"},
  61. {"TestCase", "test@case"},
  62. {"Test Case", "test@case"},
  63. {" Test Case", "test@case"},
  64. {"Test Case ", "test@case"},
  65. {" Test Case ", "test@case"},
  66. {"test", "test"},
  67. {"test_case", "test@case"},
  68. {"Test", "test"},
  69. {"", ""},
  70. {"ManyManyWords", "many@many@words"},
  71. {"manyManyWords", "many@many@words"},
  72. {"AnyKind of_string", "any@kind@of@string"},
  73. {"numbers2and55with000", "numbers@2@and@55@with@000"},
  74. {"JSONData", "json@data"},
  75. {"userID", "user@id"},
  76. {"AAAbbb", "aa@abbb"},
  77. {"test-case", "test@case"},
  78. }
  79. for _, i := range cases {
  80. in := i[0]
  81. out := i[1]
  82. result := ToDelimited(in, '@')
  83. if result != out {
  84. t.Error("'" + in + "' ('" + result + "' != '" + out + "')")
  85. }
  86. }
  87. }
  88. func TestToScreamingSnake(t *testing.T) {
  89. cases := [][]string{
  90. {"testCase", "TEST_CASE"},
  91. }
  92. for _, i := range cases {
  93. in := i[0]
  94. out := i[1]
  95. result := ToScreamingSnake(in)
  96. if result != out {
  97. t.Error("'" + result + "' != '" + out + "'")
  98. }
  99. }
  100. }
  101. func TestToKebab(t *testing.T) {
  102. cases := [][]string{
  103. {"testCase", "test-case"},
  104. }
  105. for _, i := range cases {
  106. in := i[0]
  107. out := i[1]
  108. result := ToKebab(in)
  109. if result != out {
  110. t.Error("'" + result + "' != '" + out + "'")
  111. }
  112. }
  113. }
  114. func TestToScreamingKebab(t *testing.T) {
  115. cases := [][]string{
  116. {"testCase", "TEST-CASE"},
  117. }
  118. for _, i := range cases {
  119. in := i[0]
  120. out := i[1]
  121. result := ToScreamingKebab(in)
  122. if result != out {
  123. t.Error("'" + result + "' != '" + out + "'")
  124. }
  125. }
  126. }
  127. func TestToScreamingDelimited(t *testing.T) {
  128. cases := [][]string{
  129. {"testCase", "TEST.CASE"},
  130. }
  131. for _, i := range cases {
  132. in := i[0]
  133. out := i[1]
  134. result := ToScreamingDelimited(in, '.', true)
  135. if result != out {
  136. t.Error("'" + result + "' != '" + out + "'")
  137. }
  138. }
  139. }