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 1.9KB

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