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
|
## The naming rules, which are the fiddly part of the model.
import std/[options, unittest]
import frq/model
suite "dm":
test "a channel is not a DM":
check not dm("#test")
test "a nick is":
check dm("alice")
test "an empty name is neither":
check not dm("")
suite "rowId":
test "the server's name wins":
check rowId(Message(id: "srv", localId: "loc")) == "srv"
test "the local name stands in until there is one":
check rowId(Message(localId: "loc")) == "loc"
test "a line with neither has no name":
check rowId(Message()) == ""
suite "answersTo":
setup:
let m = Message(id: "b", localId: "a", editIds: @["c", "d"])
test "the current msgid":
check m.answersTo("b")
test "the local id, for a line not yet echoed":
check m.answersTo("a")
test "any msgid a revision of it has worn":
check m.answersTo("c")
check m.answersTo("d")
test "not somebody else's":
check not m.answersTo("z")
test "an empty id names nothing":
# Otherwise every line with no msgid answers to every lookup that has
# none either, and a reply chip points at an arbitrary message.
check not m.answersTo("")
check not Message().answersTo("")
suite "messageById":
setup:
var ch = initRoom("#test")
ch.messages = @[Message(id: "1", text: "one"),
Message(id: "2", text: "two", editIds: @["2b"])]
test "finds by msgid":
check ch.messageById("1").get.text == "one"
test "finds a revision by the name it wore":
check ch.messageById("2b").get.text == "two"
test "answers with nothing for a line it does not hold":
check ch.messageById("9").isNone
test "indexById agrees with it":
check ch.indexById("2") == 1
check ch.indexById("9") == -1
|