AtlatestRepositorysigil-irc
1
;;; Tests for CHATHISTORY query parsing/serialization.3
(import (sigil test)4
(sigil irc message)5
(sigil irc chathistory))7
(test-group "Chathistory selector parsing"9
(test "* selector"10
(let ((s (parse-chathistory-selector "*")))11
(assert-equal 'star (chathistory-selector-kind s))12
(assert-equal #f (chathistory-selector-value s))))14
(test "timestamp= selector"15
(let ((s (parse-chathistory-selector "timestamp=2026-04-27T12:00:00Z")))16
(assert-equal 'timestamp (chathistory-selector-kind s))17
(assert-equal "2026-04-27T12:00:00Z" (chathistory-selector-value s))))19
(test "msgid= selector"20
(let ((s (parse-chathistory-selector "msgid=abc-123")))21
(assert-equal 'msgid (chathistory-selector-kind s))22
(assert-equal "abc-123" (chathistory-selector-value s))))24
(test "rejects unknown form"25
(assert-equal #f (parse-chathistory-selector "garbage"))))28
(test-group "Chathistory selector serialization"30
(test "* round-trip"31
(assert-equal "*"32
(chathistory-selector->string33
(parse-chathistory-selector "*"))))35
(test "timestamp round-trip"36
(let ((token "timestamp=2026-04-27T12:00:00Z"))37
(assert-equal token38
(chathistory-selector->string39
(parse-chathistory-selector token)))))41
(test "msgid round-trip"42
(let ((token "msgid=abc-123"))43
(assert-equal token44
(chathistory-selector->string45
(parse-chathistory-selector token))))))48
(test-group "parse-chathistory-line"50
(test "BEFORE query"51
(let* ((msg (parse-irc-message52
"CHATHISTORY BEFORE #channel timestamp=2026-04-27T12:00:00Z 50"))53
(q (parse-chathistory-line msg)))54
(assert-true q)55
(assert-equal "BEFORE" (chathistory-query-subcommand q))56
(assert-equal "#channel" (chathistory-query-target q))57
(assert-equal 'timestamp58
(chathistory-selector-kind (chathistory-query-selector1 q)))59
(assert-equal 50 (chathistory-query-limit q))))61
(test "LATEST with msgid"62
(let* ((msg (parse-irc-message63
"CHATHISTORY LATEST #foo msgid=abc 100"))64
(q (parse-chathistory-line msg)))65
(assert-true q)66
(assert-equal "LATEST" (chathistory-query-subcommand q))67
(assert-equal 'msgid68
(chathistory-selector-kind (chathistory-query-selector1 q)))69
(assert-equal "abc"70
(chathistory-selector-value (chathistory-query-selector1 q)))))72
(test "BETWEEN with two selectors"73
(let* ((msg (parse-irc-message74
"CHATHISTORY BETWEEN #foo timestamp=2026-04-27T00:00:00Z timestamp=2026-04-27T23:59:59Z 200"))75
(q (parse-chathistory-line msg)))76
(assert-true q)77
(assert-equal "BETWEEN" (chathistory-query-subcommand q))78
(assert-equal "#foo" (chathistory-query-target q))79
(assert-true (chathistory-query-selector2 q))80
(assert-equal 200 (chathistory-query-limit q))))82
(test "TARGETS query"83
(let* ((msg (parse-irc-message84
"CHATHISTORY TARGETS timestamp=2026-04-27T00:00:00Z timestamp=2026-04-28T00:00:00Z 50"))85
(q (parse-chathistory-line msg)))86
(assert-true q)87
(assert-equal "TARGETS" (chathistory-query-subcommand q))88
(assert-equal #f (chathistory-query-target q))89
(assert-equal 50 (chathistory-query-limit q))))91
(test "rejects malformed (missing limit)"92
(let* ((msg (parse-irc-message "CHATHISTORY BEFORE #foo *"))93
(q (parse-chathistory-line msg)))94
(assert-equal #f q)))96
(test "rejects unknown subcommand"97
(let* ((msg (parse-irc-message "CHATHISTORY SIDEWAYS #foo * 10"))98
(q (parse-chathistory-line msg)))99
(assert-equal #f q))))102
(test-group "chathistory-line serialization"104
(test "BEFORE round-trips"105
(let* ((msg (parse-irc-message106
"CHATHISTORY BEFORE #channel timestamp=2026-04-27T12:00:00Z 50"))107
(q (parse-chathistory-line msg))108
(line (chathistory-line q)))109
(assert-equal110
"CHATHISTORY BEFORE #channel timestamp=2026-04-27T12:00:00Z 50\r\n"111
line)))113
(test "BETWEEN round-trips"114
(let* ((msg (parse-irc-message115
"CHATHISTORY BETWEEN #foo * msgid=xyz 25"))116
(q (parse-chathistory-line msg))117
(line (chathistory-line q)))118
(assert-equal119
"CHATHISTORY BETWEEN #foo * msgid=xyz 25\r\n"120
line))))122
(run-tests)