IRC parsing, tokenization, and state handling in C#
at ircrobotsv2 220 lines 5.1 kB view raw
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 21# the desc string holds a description of the test, if it exists 22 23# the atoms dict has the keys: 24# * tags: tags dict 25# tags with no value are an empty string 26# * source: source string, without single leading colon 27# * verb: verb string 28# * params: params split up as a list 29# if the params key does not exist, assume it is empty 30# if any other keys do no exist, assume they are null 31# a key that is null does not exist or is not specified with the 32# given input string 33 34# matches is a list of messages that match 35 36# simple tests 37- desc: Simple test with verb and params. 38 atoms: 39 verb: "foo" 40 params: 41 - "bar" 42 - "baz" 43 - "asdf" 44 matches: 45 - "foo bar baz asdf" 46 - "foo bar baz :asdf" 47 48# with no regular params 49- desc: Simple test with source and no params. 50 atoms: 51 source: "src" 52 verb: "AWAY" 53 matches: 54 - ":src AWAY" 55 56- desc: Simple test with source and empty trailing param. 57 atoms: 58 source: "src" 59 verb: "AWAY" 60 params: 61 - "" 62 matches: 63 - ":src AWAY :" 64 65# with source 66- desc: Simple test with source. 67 atoms: 68 source: "coolguy" 69 verb: "foo" 70 params: 71 - "bar" 72 - "baz" 73 - "asdf" 74 matches: 75 - ":coolguy foo bar baz asdf" 76 - ":coolguy foo bar baz :asdf" 77 78# with trailing param 79- desc: Simple test with trailing param. 80 atoms: 81 verb: "foo" 82 params: 83 - "bar" 84 - "baz" 85 - "asdf quux" 86 matches: 87 - "foo bar baz :asdf quux" 88 89- desc: Simple test with empty trailing param. 90 atoms: 91 verb: "foo" 92 params: 93 - "bar" 94 - "baz" 95 - "" 96 matches: 97 - "foo bar baz :" 98 99- desc: Simple test with trailing param containing colon. 100 atoms: 101 verb: "foo" 102 params: 103 - "bar" 104 - "baz" 105 - ":asdf" 106 matches: 107 - "foo bar baz ::asdf" 108 109# with source and trailing param 110- desc: Test with source and trailing param. 111 atoms: 112 source: "coolguy" 113 verb: "foo" 114 params: 115 - "bar" 116 - "baz" 117 - "asdf quux" 118 matches: 119 - ":coolguy foo bar baz :asdf quux" 120 121- desc: Test with trailing containing beginning+end whitespace. 122 atoms: 123 source: "coolguy" 124 verb: "foo" 125 params: 126 - "bar" 127 - "baz" 128 - " asdf quux " 129 matches: 130 - ":coolguy foo bar baz : asdf quux " 131 132- desc: Test with trailing containing what looks like another trailing param. 133 atoms: 134 source: "coolguy" 135 verb: "PRIVMSG" 136 params: 137 - "bar" 138 - "lol :) " 139 matches: 140 - ":coolguy PRIVMSG bar :lol :) " 141 142- desc: Simple test with source and empty trailing. 143 atoms: 144 source: "coolguy" 145 verb: "foo" 146 params: 147 - "bar" 148 - "baz" 149 - "" 150 matches: 151 - ":coolguy foo bar baz :" 152 153- desc: Trailing contains only spaces. 154 atoms: 155 source: "coolguy" 156 verb: "foo" 157 params: 158 - "bar" 159 - "baz" 160 - " " 161 matches: 162 - ":coolguy foo bar baz : " 163 164- desc: Param containing tab (tab is not considered SPACE for message splitting). 165 atoms: 166 source: "coolguy" 167 verb: "foo" 168 params: 169 - "b\tar" 170 - "baz" 171 matches: 172 - ":coolguy foo b\tar baz" 173 - ":coolguy foo b\tar :baz" 174 175# with tags 176- desc: Tag with no value and space-filled trailing. 177 atoms: 178 tags: 179 "asd": "" 180 source: "coolguy" 181 verb: "foo" 182 params: 183 - "bar" 184 - "baz" 185 - " " 186 matches: 187 - "@asd :coolguy foo bar baz : " 188 189- desc: Tags with escaped values. 190 atoms: 191 verb: "foo" 192 tags: 193 "a": "b\\and\nk" 194 "d": "gh;764" 195 matches: 196 - "@a=b\\\\and\\nk;d=gh\\:764 foo" 197 - "@d=gh\\:764;a=b\\\\and\\nk foo" 198 199- desc: Tags with escaped values and params. 200 atoms: 201 verb: "foo" 202 tags: 203 "a": "b\\and\nk" 204 "d": "gh;764" 205 params: 206 - "par1" 207 - "par2" 208 matches: 209 - "@a=b\\\\and\\nk;d=gh\\:764 foo par1 par2" 210 - "@a=b\\\\and\\nk;d=gh\\:764 foo par1 :par2" 211 - "@d=gh\\:764;a=b\\\\and\\nk foo par1 par2" 212 - "@d=gh\\:764;a=b\\\\and\\nk foo par1 :par2" 213 214- desc: Tag with long, strange values (including LF and newline). 215 atoms: 216 tags: 217 foo: "\\\\;\\s \r\n" 218 verb: "COMMAND" 219 matches: 220 - "@foo=\\\\\\\\\\:\\\\s\\s\\r\\n COMMAND"