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