You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strings_test.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (c) 2017 Euan Kemp
  2. // Copyright (c) 2017 Daniel Oaks
  3. // released under the MIT license
  4. package irc
  5. import (
  6. "fmt"
  7. "testing"
  8. )
  9. func TestCasefoldChannel(t *testing.T) {
  10. type channelTest struct {
  11. channel string
  12. folded string
  13. err bool
  14. }
  15. testCases := []channelTest{
  16. {
  17. channel: "#foo",
  18. folded: "#foo",
  19. },
  20. {
  21. channel: "#rfc1459[noncompliant]",
  22. folded: "#rfc1459[noncompliant]",
  23. },
  24. {
  25. channel: "#{[]}",
  26. folded: "#{[]}",
  27. },
  28. {
  29. channel: "#FOO",
  30. folded: "#foo",
  31. },
  32. {
  33. channel: "#bang!",
  34. folded: "#bang!",
  35. },
  36. {
  37. channel: "#",
  38. folded: "#",
  39. },
  40. }
  41. for _, errCase := range []string{
  42. "", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
  43. } {
  44. testCases = append(testCases, channelTest{channel: errCase, err: true})
  45. }
  46. for i, tt := range testCases {
  47. t.Run(fmt.Sprintf("case %d: %s", i, tt.channel), func(t *testing.T) {
  48. res, err := CasefoldChannel(tt.channel)
  49. if tt.err && err == nil {
  50. t.Errorf("expected error when casefolding [%s], but did not receive one", tt.channel)
  51. return
  52. }
  53. if !tt.err && err != nil {
  54. t.Errorf("unexpected error while casefolding [%s]: %s", tt.channel, err.Error())
  55. return
  56. }
  57. if tt.folded != res {
  58. t.Errorf("expected [%v] to be [%v]", res, tt.folded)
  59. }
  60. })
  61. }
  62. }
  63. func TestCasefoldName(t *testing.T) {
  64. type nameTest struct {
  65. name string
  66. folded string
  67. err bool
  68. }
  69. testCases := []nameTest{
  70. {
  71. name: "foo",
  72. folded: "foo",
  73. },
  74. {
  75. name: "FOO",
  76. folded: "foo",
  77. },
  78. }
  79. for _, errCase := range []string{
  80. "", "#", "foo,bar", "star*man*junior", "lo7t?",
  81. "f.l", "excited!nick", "foo@bar", ":trail",
  82. "~o", "&o", "@o", "%h", "+v", "-m",
  83. } {
  84. testCases = append(testCases, nameTest{name: errCase, err: true})
  85. }
  86. for i, tt := range testCases {
  87. t.Run(fmt.Sprintf("case %d: %s", i, tt.name), func(t *testing.T) {
  88. res, err := CasefoldName(tt.name)
  89. if tt.err && err == nil {
  90. t.Errorf("expected error when casefolding [%s], but did not receive one", tt.name)
  91. return
  92. }
  93. if !tt.err && err != nil {
  94. t.Errorf("unexpected error while casefolding [%s]: %s", tt.name, err.Error())
  95. return
  96. }
  97. if tt.folded != res {
  98. t.Errorf("expected [%v] to be [%v]", res, tt.folded)
  99. }
  100. })
  101. }
  102. }