ignorecase_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package stringutils2
  15. import (
  16. "testing"
  17. )
  18. func TestHasSufffixIgnoreCase(t *testing.T) {
  19. cases := []struct {
  20. Hystack string
  21. Needle string
  22. Want bool
  23. }{
  24. {
  25. Hystack: "Hyperscacle:ASC",
  26. Needle: ":ASC",
  27. Want: true,
  28. },
  29. {
  30. Hystack: "Hyperscacle:ASC",
  31. Needle: ":asc",
  32. Want: true,
  33. },
  34. {
  35. Hystack: "Hyperscacle:ASC",
  36. Needle: "ASCD",
  37. Want: false,
  38. },
  39. }
  40. for _, c := range cases {
  41. got := HasSuffixIgnoreCase(c.Hystack, c.Needle)
  42. if got != c.Want {
  43. t.Errorf("HasSuffixIgnoreCase %s %s want %v got %v", c.Hystack, c.Needle, c.Want, got)
  44. }
  45. }
  46. }
  47. func TestHasPrefixIgnoreCase(t *testing.T) {
  48. cases := []struct {
  49. Hystack string
  50. Needle string
  51. Want bool
  52. }{
  53. {
  54. Hystack: "Hyperscacle:ASC",
  55. Needle: "Hyper",
  56. Want: true,
  57. },
  58. {
  59. Hystack: "Hyperscacle:ASC",
  60. Needle: "HYPER",
  61. Want: true,
  62. },
  63. {
  64. Hystack: "Hyperscacle:ASC",
  65. Needle: "ASCD",
  66. Want: false,
  67. },
  68. }
  69. for _, c := range cases {
  70. got := HasPrefixIgnoreCase(c.Hystack, c.Needle)
  71. if got != c.Want {
  72. t.Errorf("HasPrefixIgnoreCase %s %s want %v got %v", c.Hystack, c.Needle, c.Want, got)
  73. }
  74. }
  75. }