From 151ea12251ed876aa87bb486da1bc337e25369e9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 1 Aug 2026 16:18:19 -0300 Subject: --- main_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main_test.go (limited to 'main_test.go') 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") + } +} -- cgit v1.3