File: picoirc.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (418 lines) | stat: -rw-r--r-- 14,519 bytes parent folder | download | duplicates (3)
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
source [file join \
        [file dirname [file dirname [file join [pwd] [info script]]]] \
        devtools testutilities.tcl]

testsNeedTcl     8.6
testsNeedTcltest 2.0

package require TclOO

support {
    use virtchannel_core/events.tcl tcl::chan::events
    use virtchannel_base/variable.tcl tcl::chan::variable
}

testing {
    useLocal picoirc.tcl picoirc
}

proc contextReset {{data {}}} {
    array set ::picoirc::irc $::picoirc::defaults
    set ::picoirc::irc(callback) callback
    set ::picoirc::irc(nick) anonymous
    set ::picoirc::irc(data) "$data\n"
    set ::picoirc::irc(socket) [tcl::chan::variable ::picoirc::irc(data)]
    chan configure $::picoirc::irc(socket) -buffering line
    foreach _ [split $data \n] {
        ::picoirc::Read ::picoirc::irc
    }
    return
}

proc send {channel msg} {
    ::picoirc::post ::picoirc::irc $channel $msg
    return
}

proc contextResult {} {
    close $::picoirc::irc(socket)
    return [lindex [split $::picoirc::irc(data) \n] end-1]
}

proc contextItemResult {key} {
    close $::picoirc::irc(socket)
    return $::picoirc::irc($key)
}

proc callback {_ args} {
    global data
    set data $args
    if {$args == "version"} {
        return "PicoIRC:1.0:Tcl 8.6 tls 1.7.22"
    }
    return
}

proc callbackResult {} {
    global data
    return $data
}

test picoirc-1.0 {irc:// schema} -body {
    ::picoirc::Splituri irc://chat.freenode.net
} -result [list chat.freenode.net 6667 {} 0]

test picoirc-1.1 {irc:// schema with port} -body {
    ::picoirc::Splituri irc://irc.choopa.net:6654
} -result [list irc.choopa.net 6654 {} 0]

test picoirc-1.2 {irc:// schema with channel} -body {
    ::picoirc::Splituri irc://chat.freenode.net/#tcl
} -result [list chat.freenode.net 6667 #tcl 0]

test picoirc-1.3 {irc:// schema with channel and port} -body {
    ::picoirc::Splituri irc://chat.freenode.net:5347/#go-nuts
} -result [list chat.freenode.net 5347 #go-nuts 0]

test picoirc-1.4 {ircs:// schema} -body {
    ::picoirc::Splituri ircs://185.98.4.3
} -result [list 185.98.4.3 6697 {} 1]

test picoirc-1.5 {ircs:// schema with port} -body {
    ::picoirc::Splituri ircs://chat.freenode.net:69654
} -result [list chat.freenode.net 69654 {} 1]

test picoirc-1.6 {ircs:// schema with channel} -body {
    ::picoirc::Splituri ircs://chat.freenode.net/#tcl
} -result [list chat.freenode.net 6697 #tcl 1]

test picoirc-1.7 {ircs:// schema with channel and port} -body {
    ::picoirc::Splituri ircs://chat.freenode.net:76556/#go-nuts
} -result [list chat.freenode.net 76556 #go-nuts 1]

test picoirc-1.8 {address} -body {
    ::picoirc::Splituri irc.freenode.net
} -result [list irc.freenode.net 6667 {} 0]

test picoirc-1.9 {address with port} -body {
    ::picoirc::Splituri 243.75.9.4:8697
} -result [list 243.75.9.4 8697 {} 0]

test picoirc-1.10 {address with channel} -body {
    ::picoirc::Splituri #tcl@chat.freenode.net
} -result [list chat.freenode.net 6667 #tcl 0]

test picoirc-1.11 {address with channel and port} -body {
    ::picoirc::Splituri #go-nuts@chat.freenode.net:765
} -result [list chat.freenode.net 765 #go-nuts 0]

test picoirc-1.12 {irc:// schema with multiple channels} -body {
    ::picoirc::Splituri irc://chat.freenode.net/#tcl,#go-nuts,#twtxt
} -result [list chat.freenode.net 6667 {{#tcl} #go-nuts #twtxt} 0]

test picoirc-1.13 {irc:// schema with channel and special params} -body {
    ::picoirc::Splituri irc://chat.freenode.net/#tcl,needkey,needpass
} -result [list chat.freenode.net 6667 #tcl 0]

test picoirc-1.14 {address with multiple channels} -body {
    ::picoirc::Splituri #tcl,#go-nuts,#twtxt@chat.freenode.net
} -result [list chat.freenode.net 6667 {{#tcl} #go-nuts #twtxt} 0]

test picoirc-1.15 {address with channel and special params} -body {
    ::picoirc::Splituri #tcl,needkey,needpass@chat.freenode.net
} -result [list chat.freenode.net 6667 #tcl 0]

test picoirc-2.0 {channel message} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG #tcl :hello #tcl"
    callbackResult
} -result [list chat #tcl tcler {hello #tcl} {}]

test picoirc-2.1 {channel message with action} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG #tcl :\001ACTION fixing scripts\001"
    callbackResult
} -result [list chat #tcl tcler {fixing scripts} ACTION]

test picoirc-2.2 {channel message with version} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG #tcl :\001VERSION\001"
    contextResult
} -result "NOTICE tcler :\001VERSION PicoIRC:1.0:Tcl 8.6 tls 1.7.22\001"

test picoirc-2.3 {private message} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG anonymous :hey there"
    callbackResult
} -result [list chat anonymous tcler {hey there} {}]

test picoirc-2.4 {private message with action} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG anonymous :\001ACTION feels good\001"
    callbackResult
} -result [list chat anonymous tcler {feels good} ACTION]

test picoirc-2.5 {private message with version} -body {
    contextReset ":tcler!~anon@127.0.0.1 PRIVMSG anonymous :\001VERSION\001"
    contextResult
} -result "NOTICE tcler :\001VERSION PicoIRC:1.0:Tcl 8.6 tls 1.7.22\001"

test picoirc-2.6 {user list} -body {
    contextReset [join [list \
        ":card.freenode.net 353 tcler @ #tcl :tcler +aku +curiousgay +kbk +rkeene +sebres" \
        ":card.freenode.net 366 tcler #tcl :End of /NAMES list." \
    ] "\n"]
    callbackResult
} -result [list userlist #tcl {tcler +aku +curiousgay +kbk +rkeene +sebres}]

test picoirc-2.7 {whois} -body {
    contextReset [join [list \
        ":kornbluth.freenode.net 311 tcler anonymous ~anon 192.168.1.1 * :PicoIRC 1.0 user" \
        ":kornbluth.freenode.net 319 tcler anonymous :+#go-nuts #haskell #tcl " \
        ":kornbluth.freenode.net 312 tcler anonymous beckett.freenode.net :DE" \
        ":kornbluth.freenode.net 671 tcler anonymous :is using a secure connection" \
        ":kornbluth.freenode.net 330 tcler anonymous anonymous :is logged in as" \
        ":kornbluth.freenode.net 318 tcler anonymous :End of /WHOIS list." \
    ] "\n"]
    callbackResult
} -result [list userinfo anonymous \
                [list name ~anon \
                      host 192.168.1.1 \
                      userinfo {PicoIRC 1.0 user} \
                      channels {+#go-nuts #haskell #tcl }]]

test picoirc-2.8 {join channel} -body {
    contextReset ":tcler!~anon@127.0.0.1 JOIN #tcl"
    callbackResult
} -result [list traffic entered #tcl tcler]

test picoirc-2.9 {change nick} -body {
    contextReset ":tcler!~anon@127.0.0.1 NICK :gopher"
    callbackResult
} -result [list traffic nickchange {} tcler gopher]

test picoirc-2.10 {quit channel} -body {
    contextReset ":tcler!~anon@127.0.0.1 PART #tcl"
    callbackResult
} -result [list traffic left #tcl tcler]

test picoirc-2.11 {quit server} -body {
    contextReset ":tcler!~anon@127.0.0.1 QUIT"
    callbackResult
} -result [list traffic left {} tcler]

test picoirc-2.12 {mode self} -body {
    contextReset ":anonymous MODE anonymous :+RZi"
    callbackResult
} -result [list mode {} anonymous +RZi]

test picoirc-2.13 {mode channel} -body {
    contextReset ":egan.freenode.net MODE #tcl-hacks :+ns"
    callbackResult
} -result [list mode {} #tcl-hacks +ns]

test picoirc-2.14 {mode channel with parameter} -body {
    contextReset ":ChanServ!ChanServ@services. MODE #tcl-hacks :+v newbie"
    callbackResult
} -result [list mode ChanServ #tcl-hacks "+v newbie"]

test picoirc-2.15 {mode channel with parameter without colon} -body {
    contextReset ":ChanServ!ChanServ@services. MODE #tcl-hacks +v newbie"
    callbackResult
} -result [list mode ChanServ #tcl-hacks "+v newbie"]

test picoirc-2.16 {mode channel with trailing space and without colon} -body {
    contextReset ":ChanServ!ChanServ@services. MODE #tcl-hacks -s "
    callbackResult
} -result [list mode ChanServ #tcl-hacks "-s "]

test picoirc-2.17 {channel notice} -body {
    contextReset ":ChanServ!ChanServ@services. NOTICE #tcl :Tcl is the productive programming language."
    callbackResult
} -result [list chat #tcl ChanServ {Tcl is the productive programming language.} NOTICE]

test picoirc-2.18 {private notice} -body {
    contextReset ":NickServ!NickServ@services. NOTICE anonymous :This nickname is registered."
    callbackResult
} -result [list chat {} NickServ {This nickname is registered.} NOTICE]

test picoirc-2.19 {global notice} -body {
    contextReset ":beckett.freenode.net NOTICE * :*** Checking Ident"
    callbackResult
} -result [list chat {} {} {*** Checking Ident} NOTICE]

test picoirc-3.0 {/me} -body {
    contextReset
    send #tcl "/me testing picoirc"
    list [contextResult] [callbackResult]
} -result [list "PRIVMSG #tcl :\001ACTION testing picoirc\001" \
          [list chat #tcl anonymous "testing picoirc" ACTION]]

test picoirc-3.1 {/nick} -body {
    contextReset
    send #tcl "/nick anon"
    contextResult
} -result "NICK anon"

test picoirc-3.2 {/quit} -body {
    contextReset
    send #tcl "/quit"
    contextResult
} -result "QUIT"

test picoirc-3.3 {/part} -body {
    contextReset
    send #tcl "/part"
    contextResult
} -result "PART #tcl"

test picoirc-3.4 {/names} -body {
    contextReset
    send #tcl "/names"
    contextResult
} -result "NAMES #tcl"

test picoirc-3.5 {/whois inside channel} -body {
    contextReset
    send #tcl "/whois aku"
    contextResult
} -result "WHOIS aku"

test picoirc-3.6 {/whois} -body {
    contextReset
    send {} "/whois aku"
    contextResult
} -result "WHOIS aku"

test picoirc-3.7 {/kick} -body {
    contextReset
    send #tcl "/kick bastard too much spamming"
    contextResult
} -result "KICK #tcl bastard :too much spamming"

test picoirc-3.8 {/kick no reason} -body {
    contextReset
    send #tcl "/kick bastard"
    contextResult
} -result "KICK #tcl bastard :"

test picoirc-3.9 {/mode} -body {
    contextReset
    send #tcl "/mode #tcl-hacks +s"
    contextResult
} -result "MODE #tcl-hacks +s"

test picoirc-3.10 {/topic} -body {
    contextReset
    send #tcl "/topic Tcl is the best scripting language in the world!"
    contextResult
} -result "TOPIC #tcl :Tcl is the best scripting language in the world!"

test picoirc-3.11 {/quote} -body {
    contextReset
    send #tcl "/quote JOIN #go-nuts"
    contextResult
} -result "JOIN #go-nuts"

test picoirc-3.12 {/part} -body {
    contextReset
    send #tcl "/join #haskell"
    contextResult
} -result "JOIN #haskell"

test picoirc-3.13 {/version} -body {
    contextReset
    send #tcl "/version #haskell"
    contextResult
} -result "PRIVMSG #haskell :\001VERSION\001"

test picoirc-3.14 {/msg} -body {
    contextReset
    send #tcl "/msg NickServ help me please"
    list [contextResult] [callbackResult]
} -result [list "PRIVMSG NickServ :help me please" \
          [list chat NickServ anonymous "help me please" {}]]

test picoirc-3.15 {/notice} -body {
    contextReset
    send #tcl "/notice #haskell declarative programming is amazing"
    list [contextResult] [callbackResult]
} -result [list "NOTICE #haskell :declarative programming is amazing" \
          [list chat #haskell anonymous "declarative programming is amazing" "NOTICE"]]

test picoirc-3.16 {unknown command} -body {
    contextReset
    send #tcl "/compile chromium"
    callbackResult
} -result [list system #tcl {unknown command /compile}]

test picoirc-4.0 {channel message ipv6} -body {
     contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG #tcl :hello #tcl"
     callbackResult
} -result [list chat #tcl tcler {hello #tcl} {}]

test picoirc-4.1 {channel message with action ipv6} -body {
     contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG #tcl :\001ACTION fixing scripts\001"
     callbackResult
} -result [list chat #tcl tcler {fixing scripts} ACTION]

test picoirc-4.2 {channel message with version ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG #tcl :\001VERSION\001"
    contextResult
} -result "NOTICE tcler :\001VERSION PicoIRC:1.0:Tcl 8.6 tls 1.7.22\001"

test picoirc-4.3 {private message ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG anonymous :hey there"
    callbackResult
} -result [list chat anonymous tcler {hey there} {}]

test picoirc-4.4 {private message with action ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG anonymous :\001ACTION feels good\001"
    callbackResult
} -result [list chat anonymous tcler {feels good} ACTION]

test picoirc-4.5 {private message with version ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PRIVMSG anonymous :\001VERSION\001"
    contextResult
} -result "NOTICE tcler :\001VERSION PicoIRC:1.0:Tcl 8.6 tls 1.7.22\001"

# picoirc-4.6 : not ipv6 specific

test picoirc-4.7 {whois ipv6} -body {
     contextReset [join [list \
         ":zinc.libera.chat 311 tcler anonymous ~anon client.example.com * :PicoIRC 1.0 user" \
         ":zinc.libera.chat 319 tcler anonymous :#tcl #tcltest" \
         ":zinc.libera.chat 312 tcler anonymous zinc.libera.chat :Espoo, FI" \
         ":zinc.libera.chat 338 tcler anonymous fd0a:7439:215b:fd8f:0:1:2:3 :actually using host" \
         ":zinc.libera.chat 317 tcler anonymous 149 1624142406 :seconds idle, signon time" \
         ":zinc.libera.chat 330 tcler anonymous anonymous :is logged in as" \
         ":zinc.libera.chat 318 tcler anonymous :End of /WHOIS list." \
     ] "\n"]
     callbackResult
} -result [list userinfo anonymous \
              [list name ~anon \
                    host client.example.com \
                    userinfo {PicoIRC 1.0 user} \
                    channels {#tcl #tcltest}]]

test picoirc-4.8 {join channel ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 JOIN #tcl"
    callbackResult
} -result {traffic entered #tcl tcler}

test picoirc-4.9 {change nick ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 NICK :gopher"
    callbackResult
} -result {traffic nickchange {} tcler gopher}

test picoirc-4.10 {quit channel ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 PART #tcl"
    callbackResult
} -result {traffic left #tcl tcler}

test picoirc-4.11 {quit server ipv6} -body {
    contextReset ":tcler!~anon@fd0a:7439:215b:fd8f:0:1:2:3 QUIT"
    callbackResult
} -result {traffic left {} tcler}

test picoirc-5.0 {capabilities list} -body {
    contextReset ":zinc.libera.chat CAP tcler LS :multi-prefix tls sasl"
    contextItemResult caps
} -result {multi-prefix tls sasl}

testsuiteCleanup