about summary refs log tree commit diff
path: root/IRCSharp.Tests/Tokenization/Data/msg-split.yaml
blob: fa3f4aa9f7f7fb0c841276c38ba2c9c8aaf5a86a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# IRC parser tests
# splitting messages into usable atoms

# Written in 2015 by Daniel Oaks <daniel@danieloaks.net>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.

# some of the tests here originate from grawity's test vectors, which is WTFPL v2 licensed
#   https://github.com/grawity/code/tree/master/lib/tests
# some of the tests here originate from Mozilla's test vectors, which is public domain
#   https://dxr.mozilla.org/comm-central/source/chat/protocols/irc/test/test_ircMessage.js
# some of the tests here originate from SaberUK's test vectors, which he's indicated I am free to include here
#   https://github.com/SaberUK/ircparser/tree/master/test

# we follow RFC1459 with regards to multiple ascii spaces splitting atoms:
#   The prefix, command, and all parameters are
#   separated by one (or more) ASCII space character(s) (0x20).
# because doing it as RFC2812 says (strictly as a single ascii space) isn't sane

tests:
  # input is the string coming directly from the server to parse

  # the atoms dict has the keys:
  #   * tags: tags dict
  #       tags with no value are an empty string
  #   * source: source string, without single leading colon
  #   * verb: verb string
  #   * params: params split up as a list
  # if the params key does not exist, assume it is empty
  # if any other keys do no exist, assume they are null
  # a key that is null does not exist or is not specified with the
  #   given input string

  # simple
  - input: "foo bar baz asdf"
    atoms:
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "asdf"

  # with source
  - input: ":coolguy foo bar baz asdf"
    atoms:
      source: "coolguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "asdf"

  # with trailing param
  - input: "foo bar baz :asdf quux"
    atoms:
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "asdf quux"

  - input: "foo bar baz :"
    atoms:
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - ""

  - input: "foo bar baz ::asdf"
    atoms:
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - ":asdf"

  # with source and trailing param
  - input: ":coolguy foo bar baz :asdf quux"
    atoms:
      source: "coolguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "asdf quux"

  - input: ":coolguy foo bar baz :  asdf quux "
    atoms:
      source: "coolguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "  asdf quux "

  - input: ":coolguy PRIVMSG bar :lol :) "
    atoms:
      source: "coolguy"
      verb: "PRIVMSG"
      params:
        - "bar"
        - "lol :) "

  - input: ":coolguy foo bar baz :"
    atoms:
      source: "coolguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - ""

  - input: ":coolguy foo bar baz :  "
    atoms:
      source: "coolguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"
        - "  "

  # with tags
  - input: "@a=b;c=32;k;rt=ql7 foo"
    atoms:
      verb: "foo"
      tags:
        "a": "b"
        "c": "32"
        "k": ""
        "rt": "ql7"

  # with escaped tags
  - input: "@a=b\\\\and\\nk;c=72\\s45;d=gh\\:764 foo"
    atoms:
      verb: "foo"
      tags:
        "a": "b\\and\nk"
        "c": "72 45"
        "d": "gh;764"

  # with tags and source
  - input: "@c;h=;a=b :quux ab cd"
    atoms:
      tags:
        "c": ""
        "h": ""
        "a": "b"
      source: "quux"
      verb: "ab"
      params:
        - "cd"

  # different forms of last param
  - input: ":src JOIN #chan"
    atoms:
      source: "src"
      verb: "JOIN"
      params:
        - "#chan"

  - input: ":src JOIN :#chan"
    atoms:
      source: "src"
      verb: "JOIN"
      params:
        - "#chan"

  # with and without last param
  - input: ":src AWAY"
    atoms:
      source: "src"
      verb: "AWAY"

  - input: ":src AWAY "
    atoms:
      source: "src"
      verb: "AWAY"

  # tab is not considered <SPACE>
  - input: ":cool\tguy foo bar baz"
    atoms:
      source: "cool\tguy"
      verb: "foo"
      params:
        - "bar"
        - "baz"

  # with weird control codes in the source
  - input: ":coolguy!ag@net\x035w\x03ork.admin PRIVMSG foo :bar baz"
    atoms:
      source: "coolguy!ag@net\x035w\x03ork.admin"
      verb: "PRIVMSG"
      params:
        - "foo"
        - "bar baz"

  - input: ":coolguy!~ag@n\x02et\x0305w\x0fork.admin PRIVMSG foo :bar baz"
    atoms:
      source: "coolguy!~ag@n\x02et\x0305w\x0fork.admin"
      verb: "PRIVMSG"
      params:
        - "foo"
        - "bar baz"

  - input: "@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4= :irc.example.com COMMAND param1 param2 :param3 param3"
    atoms:
      tags:
        tag1: "value1"
        tag2: ""
        vendor1/tag3: "value2"
        vendor2/tag4: ""
      source: "irc.example.com"
      verb: "COMMAND"
      params:
        - "param1"
        - "param2"
        - "param3 param3"

  - input: ":irc.example.com COMMAND param1 param2 :param3 param3"
    atoms:
      source: "irc.example.com"
      verb: "COMMAND"
      params:
        - "param1"
        - "param2"
        - "param3 param3"

  - input: "@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 COMMAND param1 param2 :param3 param3"
    atoms:
      tags:
        tag1: "value1"
        tag2: ""
        vendor1/tag3: "value2"
        vendor2/tag4: ""
      verb: "COMMAND"
      params:
        - "param1"
        - "param2"
        - "param3 param3"

  - input: "COMMAND"
    atoms:
      verb: "COMMAND"

  # yaml encoding + slashes is fun
  - input: "@foo=\\\\\\\\\\:\\\\s\\s\\r\\n COMMAND"
    atoms:
      tags:
        foo: "\\\\;\\s \r\n"
      verb: "COMMAND"

  # broken messages from unreal
  - input: ":gravel.mozilla.org 432  #momo :Erroneous Nickname: Illegal characters"
    atoms:
      source: "gravel.mozilla.org"
      verb: "432"
      params:
        - "#momo"
        - "Erroneous Nickname: Illegal characters"

  - input: ":gravel.mozilla.org MODE #tckk +n "
    atoms:
      source: "gravel.mozilla.org"
      verb: "MODE"
      params:
        - "#tckk"
        - "+n"

  - input: ":services.esper.net MODE #foo-bar +o foobar  "
    atoms:
      source: "services.esper.net"
      verb: "MODE"
      params:
        - "#foo-bar"
        - "+o"
        - "foobar"

  # tag values should be parsed char-at-a-time to prevent wayward replacements.
  - input: "@tag1=value\\\\ntest COMMAND"
    atoms:
      tags:
        tag1: "value\\ntest"
      verb: "COMMAND"

  # If a tag value has a slash followed by a character which doesn't need
  # to be escaped, the slash should be dropped.
  - input: "@tag1=value\\1 COMMAND"
    atoms:
      tags:
        tag1: "value1"
      verb: "COMMAND"

  # A slash at the end of a tag value should be dropped
  - input: "@tag1=value1\\ COMMAND"
    atoms:
      tags:
        tag1: "value1"
      verb: "COMMAND"

  # Duplicate tags: Parsers SHOULD disregard all but the final occurence 
  - input: "@tag1=1;tag2=3;tag3=4;tag1=5 COMMAND"
    atoms:
      tags:
        tag1: "5"
        tag2: "3"
        tag3: "4"
      verb: "COMMAND"

  # vendored tags can have the same name as a non-vendored tag
  - input: "@tag1=1;tag2=3;tag3=4;tag1=5;vendor/tag2=8 COMMAND"
    atoms:
      tags:
        tag1: "5"
        tag2: "3"
        tag3: "4"
        vendor/tag2: "8"
      verb: "COMMAND"

  # Some parsers handle /MODE in a special way, make sure they do it right
  - input: ":SomeOp MODE #channel :+i"
    atoms:
      source: "SomeOp"
      verb: "MODE"
      params:
      - "#channel"
      - "+i"

  - input: ":SomeOp MODE #channel +oo SomeUser :AnotherUser"
    atoms:
      source: "SomeOp"
      verb: "MODE"
      params:
      - "#channel"
      - "+oo"
      - "SomeUser"
      - "AnotherUser"