| The data model, in Nim d333b6f nandi 9h ago | 1 | ## The naming rules, which are the fiddly part of the model. |
| 2 | |
| 3 | import std/[options, unittest] |
| 4 | import frq/model |
| 5 | |
| 6 | suite "dm": |
| 7 | test "a channel is not a DM": |
| 8 | check not dm("#test") |
| 9 | test "a nick is": |
| 10 | check dm("alice") |
| 11 | test "an empty name is neither": |
| 12 | check not dm("") |
| 13 | |
| 14 | suite "rowId": |
| 15 | test "the server's name wins": |
| 16 | check rowId(Message(id: "srv", localId: "loc")) == "srv" |
| 17 | test "the local name stands in until there is one": |
| 18 | check rowId(Message(localId: "loc")) == "loc" |
| 19 | test "a line with neither has no name": |
| 20 | check rowId(Message()) == "" |
| 21 | |
| 22 | suite "answersTo": |
| 23 | setup: |
| 24 | let m = Message(id: "b", localId: "a", editIds: @["c", "d"]) |
| 25 | |
| 26 | test "the current msgid": |
| 27 | check m.answersTo("b") |
| 28 | test "the local id, for a line not yet echoed": |
| 29 | check m.answersTo("a") |
| 30 | test "any msgid a revision of it has worn": |
| 31 | check m.answersTo("c") |
| 32 | check m.answersTo("d") |
| 33 | test "not somebody else's": |
| 34 | check not m.answersTo("z") |
| 35 | test "an empty id names nothing": |
| 36 | # Otherwise every line with no msgid answers to every lookup that has |
| 37 | # none either, and a reply chip points at an arbitrary message. |
| 38 | check not m.answersTo("") |
| 39 | check not Message().answersTo("") |
| 40 | |
| 41 | suite "messageById": |
| 42 | setup: |
| 43 | var ch = initRoom("#test") |
| 44 | ch.messages = @[Message(id: "1", text: "one"), |
| 45 | Message(id: "2", text: "two", editIds: @["2b"])] |
| 46 | |
| 47 | test "finds by msgid": |
| 48 | check ch.messageById("1").get.text == "one" |
| 49 | test "finds a revision by the name it wore": |
| 50 | check ch.messageById("2b").get.text == "two" |
| 51 | test "answers with nothing for a line it does not hold": |
| 52 | check ch.messageById("9").isNone |
| 53 | test "indexById agrees with it": |
| 54 | check ch.indexById("2") == 1 |
| 55 | check ch.indexById("9") == -1 |