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") } }