AtlatestRepositorysigil-irc
1
;;; Tests for MONITOR command parsing + numeric reply builders.3
(import (sigil test)4
(sigil string)5
(sigil irc message)6
(sigil irc monitor)7
(sigil irc numerics))9
(test-group "MONITOR parsing"11
(test "MONITOR + with single nick"12
(let* ((msg (parse-irc-message "MONITOR + alice"))13
(mc (parse-monitor-line msg)))14
(assert-true mc)15
(assert-equal "+" (monitor-command-subcommand mc))16
(assert-equal '("alice") (monitor-command-targets mc))))18
(test "MONITOR + with comma list"19
(let* ((msg (parse-irc-message "MONITOR + alice,bob,carol"))20
(mc (parse-monitor-line msg)))21
(assert-true mc)22
(assert-equal '("alice" "bob" "carol") (monitor-command-targets mc))))24
(test "MONITOR -"25
(let* ((msg (parse-irc-message "MONITOR - alice"))26
(mc (parse-monitor-line msg)))27
(assert-true mc)28
(assert-equal "-" (monitor-command-subcommand mc))))30
(test "MONITOR C / L / S have empty targets"31
(let ((msg-c (parse-irc-message "MONITOR C"))32
(msg-l (parse-irc-message "MONITOR L"))33
(msg-s (parse-irc-message "MONITOR S")))34
(assert-equal '() (monitor-command-targets (parse-monitor-line msg-c)))35
(assert-equal '() (monitor-command-targets (parse-monitor-line msg-l)))36
(assert-equal '() (monitor-command-targets (parse-monitor-line msg-s)))))38
(test "rejects MONITOR + without targets"39
(let* ((msg (parse-irc-message "MONITOR +"))40
(mc (parse-monitor-line msg)))41
(assert-equal #f mc)))43
(test "rejects unknown subcommand"44
(let* ((msg (parse-irc-message "MONITOR Q alice"))45
(mc (parse-monitor-line msg)))46
(assert-equal #f mc))))49
(test-group "MONITOR client line builder"51
(test "+ list"52
(assert-equal "MONITOR + alice,bob\r\n"53
(monitor-line "+" '("alice" "bob"))))55
(test "C clear"56
(assert-equal "MONITOR C\r\n" (monitor-line "C")))58
(test "L list query"59
(assert-equal "MONITOR L\r\n" (monitor-line "L"))))62
(test-group "MONITOR server numeric reply builders"64
(test "RPL-MONONLINE (730)"65
(let ((line (monitor-online-line "alice"66
'("bob!b@host" "carol!c@host"))))67
(assert-true (string-contains? line RPL-MONONLINE))68
(assert-true (string-contains? line "alice"))69
(assert-true (string-contains? line "bob!b@host,carol!c@host"))))71
(test "RPL-MONOFFLINE (731)"72
(let ((line (monitor-offline-line "alice" '("bob"))))73
(assert-true (string-contains? line RPL-MONOFFLINE))74
(assert-true (string-contains? line "bob"))))76
(test "RPL-ENDOFMONLIST (733)"77
(let ((line (monitor-end-of-list-line "alice")))78
(assert-true (string-contains? line RPL-ENDOFMONLIST))79
(assert-true (string-contains? line "End of MONITOR list"))))81
(test "ERR-MONLISTFULL (734) includes limit and rejected nicks"82
(let ((line (monitor-list-full-line "alice" 100 '("dan"))))83
(assert-true (string-contains? line ERR-MONLISTFULL))84
(assert-true (string-contains? line "100"))85
(assert-true (string-contains? line "dan")))))87
(run-tests)