IRC parsing, tokenization, and state handling in C#
1# IRC parser tests
2# joining atoms into sendable messages
3
4# Written in 2015 by Daniel Oaks <daniel@danieloaks.net>
5#
6# To the extent possible under law, the author(s) have dedicated all copyright
7# and related and neighboring rights to this software to the public domain
8# worldwide. This software is distributed without any warranty.
9#
10# You should have received a copy of the CC0 Public Domain Dedication along
11# with this software. If not, see
12# <http://creativecommons.org/publicdomain/zero/1.0/>.
13
14# some of the tests here originate from grawity's test vectors, which is WTFPL v2 licensed
15# https://github.com/grawity/code/tree/master/lib/tests
16# some of the tests here originate from Mozilla's test vectors, which is public domain
17# https://dxr.mozilla.org/comm-central/source/chat/protocols/irc/test/test_ircMessage.js
18# some of the tests here originate from SaberUK's test vectors, which he's indicated I am free to include here
19# https://github.com/SaberUK/ircparser/tree/master/test
20
21tests:
22 # the desc string holds a description of the test, if it exists
23
24 # the atoms dict has the keys:
25 # * tags: tags dict
26 # tags with no value are an empty string
27 # * source: source string, without single leading colon
28 # * verb: verb string
29 # * params: params split up as a list
30 # if the params key does not exist, assume it is empty
31 # if any other keys do no exist, assume they are null
32 # a key that is null does not exist or is not specified with the
33 # given input string
34
35 # matches is a list of messages that match
36
37 # simple tests
38 - desc: Simple test with verb and params.
39 atoms:
40 verb: "foo"
41 params:
42 - "bar"
43 - "baz"
44 - "asdf"
45 matches:
46 - "foo bar baz asdf"
47 - "foo bar baz :asdf"
48
49 # with no regular params
50 - desc: Simple test with source and no params.
51 atoms:
52 source: "src"
53 verb: "AWAY"
54 matches:
55 - ":src AWAY"
56
57 - desc: Simple test with source and empty trailing param.
58 atoms:
59 source: "src"
60 verb: "AWAY"
61 params:
62 - ""
63 matches:
64 - ":src AWAY :"
65
66 # with source
67 - desc: Simple test with source.
68 atoms:
69 source: "coolguy"
70 verb: "foo"
71 params:
72 - "bar"
73 - "baz"
74 - "asdf"
75 matches:
76 - ":coolguy foo bar baz asdf"
77 - ":coolguy foo bar baz :asdf"
78
79 # with trailing param
80 - desc: Simple test with trailing param.
81 atoms:
82 verb: "foo"
83 params:
84 - "bar"
85 - "baz"
86 - "asdf quux"
87 matches:
88 - "foo bar baz :asdf quux"
89
90 - desc: Simple test with empty trailing param.
91 atoms:
92 verb: "foo"
93 params:
94 - "bar"
95 - "baz"
96 - ""
97 matches:
98 - "foo bar baz :"
99
100 - desc: Simple test with trailing param containing colon.
101 atoms:
102 verb: "foo"
103 params:
104 - "bar"
105 - "baz"
106 - ":asdf"
107 matches:
108 - "foo bar baz ::asdf"
109
110 # with source and trailing param
111 - desc: Test with source and trailing param.
112 atoms:
113 source: "coolguy"
114 verb: "foo"
115 params:
116 - "bar"
117 - "baz"
118 - "asdf quux"
119 matches:
120 - ":coolguy foo bar baz :asdf quux"
121
122 - desc: Test with trailing containing beginning+end whitespace.
123 atoms:
124 source: "coolguy"
125 verb: "foo"
126 params:
127 - "bar"
128 - "baz"
129 - " asdf quux "
130 matches:
131 - ":coolguy foo bar baz : asdf quux "
132
133 - desc: Test with trailing containing what looks like another trailing param.
134 atoms:
135 source: "coolguy"
136 verb: "PRIVMSG"
137 params:
138 - "bar"
139 - "lol :) "
140 matches:
141 - ":coolguy PRIVMSG bar :lol :) "
142
143 - desc: Simple test with source and empty trailing.
144 atoms:
145 source: "coolguy"
146 verb: "foo"
147 params:
148 - "bar"
149 - "baz"
150 - ""
151 matches:
152 - ":coolguy foo bar baz :"
153
154 - desc: Trailing contains only spaces.
155 atoms:
156 source: "coolguy"
157 verb: "foo"
158 params:
159 - "bar"
160 - "baz"
161 - " "
162 matches:
163 - ":coolguy foo bar baz : "
164
165 - desc: Param containing tab (tab is not considered SPACE for message splitting).
166 atoms:
167 source: "coolguy"
168 verb: "foo"
169 params:
170 - "b\tar"
171 - "baz"
172 matches:
173 - ":coolguy foo b\tar baz"
174 - ":coolguy foo b\tar :baz"
175
176 # with tags
177 - desc: Tag with no value and space-filled trailing.
178 atoms:
179 tags:
180 "asd": ""
181 source: "coolguy"
182 verb: "foo"
183 params:
184 - "bar"
185 - "baz"
186 - " "
187 matches:
188 - "@asd :coolguy foo bar baz : "
189
190 - desc: Tags with escaped values.
191 atoms:
192 verb: "foo"
193 tags:
194 "a": "b\\and\nk"
195 "d": "gh;764"
196 matches:
197 - "@a=b\\\\and\\nk;d=gh\\:764 foo"
198 - "@d=gh\\:764;a=b\\\\and\\nk foo"
199
200 - desc: Tags with escaped values and params.
201 atoms:
202 verb: "foo"
203 tags:
204 "a": "b\\and\nk"
205 "d": "gh;764"
206 params:
207 - "par1"
208 - "par2"
209 matches:
210 - "@a=b\\\\and\\nk;d=gh\\:764 foo par1 par2"
211 - "@a=b\\\\and\\nk;d=gh\\:764 foo par1 :par2"
212 - "@d=gh\\:764;a=b\\\\and\\nk foo par1 par2"
213 - "@d=gh\\:764;a=b\\\\and\\nk foo par1 :par2"
214
215 - desc: Tag with long, strange values (including LF and newline).
216 atoms:
217 tags:
218 foo: "\\\\;\\s \r\n"
219 verb: "COMMAND"
220 matches:
221 - "@foo=\\\\\\\\\\:\\\\s\\s\\r\\n COMMAND"