No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

92 líneas
3.0 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. []string{"testCase", "test_case"},
  32. []string{"TestCase", "test_case"},
  33. []string{"Test Case", "test_case"},
  34. []string{" Test Case", "test_case"},
  35. []string{"Test Case ", "test_case"},
  36. []string{" Test Case ", "test_case"},
  37. []string{"test", "test"},
  38. []string{"test_case", "test_case"},
  39. []string{"Test", "test"},
  40. []string{"", ""},
  41. []string{"ManyManyWords", "many_many_words"},
  42. []string{"manyManyWords", "many_many_words"},
  43. []string{"AnyKind of_string", "any_kind_of_string"},
  44. []string{"numbers2and55with000", "numbers_2_and_55_with_000"},
  45. []string{"JSONData", "json_data"},
  46. []string{"userID", "user_id"},
  47. []string{"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. []string{"testCase", "test@case"},
  61. []string{"TestCase", "test@case"},
  62. []string{"Test Case", "test@case"},
  63. []string{" Test Case", "test@case"},
  64. []string{"Test Case ", "test@case"},
  65. []string{" Test Case ", "test@case"},
  66. []string{"test", "test"},
  67. []string{"test_case", "test@case"},
  68. []string{"Test", "test"},
  69. []string{"", ""},
  70. []string{"ManyManyWords", "many@many@words"},
  71. []string{"manyManyWords", "many@many@words"},
  72. []string{"AnyKind of_string", "any@kind@of@string"},
  73. []string{"numbers2and55with000", "numbers@2@and@55@with@000"},
  74. []string{"JSONData", "json@data"},
  75. []string{"userID", "user@id"},
  76. []string{"AAAbbb", "aa@abbb"},
  77. []string{"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. }