AtlatestRepositorysigil-irc

sigil-irc / tree / testtest-batch.sgl

1;;; Tests for BATCH command and batch context tracking.
2
3(import (sigil test)
4 (sigil string)
5 (sigil irc message)
6 (sigil irc batch))
7
8(test-group "BATCH wire helpers"
9
10 (test "batch-start-line minimal"
11 (assert-equal "BATCH +abc chathistory\r\n"
12 (batch-start-line "abc" "chathistory")))
14 (test "batch-start-line with params"
15 (assert-equal "BATCH +abc chathistory #channel\r\n"
16 (batch-start-line "abc" "chathistory" params: '("#channel"))))
18 (test "batch-start-line with prefix"
19 (assert-equal ":server BATCH +abc chathistory\r\n"
20 (batch-start-line "abc" "chathistory" prefix: "server")))
22 (test "batch-end-line"
23 (assert-equal "BATCH -abc\r\n" (batch-end-line "abc")))
25 (test "batch-end-line with prefix"
26 (assert-equal ":server BATCH -abc\r\n"
27 (batch-end-line "abc" prefix: "server"))))
30(test-group "Reftag generation"
32 (test "make-batch-reftag yields a non-empty string"
33 (let ((tag (make-batch-reftag)))
34 (assert-true (string? tag))
35 (assert-true (> (string-length tag) 0))))
37 (test "two reftags differ"
38 (assert-false (string=? (make-batch-reftag) (make-batch-reftag))))
40 (test "reftag avoids `=`, `+`, `/`"
41 (let ((tag (make-batch-reftag)))
42 (assert-false (string-contains? tag "="))
43 (assert-false (string-contains? tag "+"))
44 (assert-false (string-contains? tag "/")))))
47(test-group "Batch context tracking"
49 (test "open + close lifecycle"
50 (let ((ctx (make-batch-context)))
51 (assert-false (batch-context-open? ctx "abc"))
52 (batch-open! ctx "abc" "chathistory")
53 (assert-true (batch-context-open? ctx "abc"))
54 (assert-equal "chathistory" (batch-type-of ctx "abc"))
55 (batch-close! ctx "abc")
56 (assert-false (batch-context-open? ctx "abc"))
57 (assert-equal #f (batch-type-of ctx "abc"))))
59 (test "multiple open batches"
60 (let ((ctx (make-batch-context)))
61 (batch-open! ctx "a" "chathistory")
62 (batch-open! ctx "b" "netjoin")
63 (assert-true (batch-context-open? ctx "a"))
64 (assert-true (batch-context-open? ctx "b"))
65 (assert-equal "chathistory" (batch-type-of ctx "a"))
66 (assert-equal "netjoin" (batch-type-of ctx "b")))))
69(test-group "batch-tag-of"
71 (test "extracts batch tag from message"
72 (let ((msg (parse-irc-message "@batch=abc :n!u@h PRIVMSG #c :hi")))
73 (assert-equal "abc" (batch-tag-of msg))))
75 (test "returns #f when batch tag absent"
76 (let ((msg (parse-irc-message ":n!u@h PRIVMSG #c :hi")))
77 (assert-equal #f (batch-tag-of msg)))))
79(run-tests)