summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-01 16:18:19 -0300
committerGabriel Schneider <[email protected]>2026-08-01 18:21:40 -0300
commit151ea12251ed876aa87bb486da1bc337e25369e9 (patch)
tree0363d90b5df6fc8b17b1737ef2793ba3825ba4d4 /main_test.go
parent8ec4e135e318c7799b2576a8729493c063da4a97 (diff)
downloadnotevi-151ea12251ed876aa87bb486da1bc337e25369e9.tar.gz
notevi-151ea12251ed876aa87bb486da1bc337e25369e9.zip
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go
new file mode 100644
index 0000000..134f222
--- /dev/null
+++ b/main_test.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "encoding/json"
+ "strings"
+ "testing"
+)
+
+func TestReplyToRoundTripsInTheLog(t *testing.T) {
+ b, err := json.Marshal(Entry{Op: "note", NoteID: 2, ReplyTo: 7, Text: "child"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(string(b), `"reply_to":7`) {
+ t.Fatalf("reply edge missing from %s", b)
+ }
+ var got Entry
+ if err := json.Unmarshal(b, &got); err != nil {
+ t.Fatal(err)
+ }
+ if got.ReplyTo != 7 {
+ t.Errorf("reply_to = %d, want 7", got.ReplyTo)
+ }
+}
+
+func TestHasNoteUsesLogWideNumbers(t *testing.T) {
+ entries := []Entry{
+ {Op: "read"},
+ {Op: "note", Session: "a", NoteID: 1},
+ {Op: "note", Session: "b", NoteID: 1},
+ }
+ if !hasNote(entries, 2) {
+ t.Error("second log-wide note was not found when its session-local id repeated")
+ }
+ if hasNote(entries, 3) || hasNote(entries, 0) {
+ t.Error("a nonexistent log-wide note was accepted")
+ }
+}