| 1 | package mapa |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // IN1 and IN2 (columns and icons spec §5.1, §5.2, §9): which pages are |
| 9 | // inside which, and in what order. |
| 10 | |
| 11 | func insideTitles(t *testing.T, index *Index, scope Scope, |
| 12 | pageID int64) string { |
| 13 | t.Helper() |
| 14 | pages, err := index.Inside(ctx(), scope, pageID) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | var titles []string |
| 19 | for _, page := range pages { |
| 20 | titles = append(titles, page.record.Title) |
| 21 | } |
| 22 | return strings.Join(titles, ", ") |
| 23 | } |
| 24 | |
| 25 | func TestIN1OnlyAnExactFirstInLineIsInside(t *testing.T) { |
| 26 | store := testStore(t) |
| 27 | index := NewIndex(store) |
| 28 | parent := mustCreate(t, store, "Projects", "See [[Beta]] then [[Alpha]].") |
| 29 | for title, body := range map[string]string{ |
| 30 | "Alpha": "In: [[Projects]]\n\nText.", |
| 31 | "Beta": "In: [[Projects|the projects]] ^m1", |
| 32 | "Gamma": "In: [[Projects]]", |
| 33 | "Second": "Intro.\n\nIn: [[Projects]]", |
| 34 | "Dated": "In: [[2026-11-12]]", |
| 35 | "Self": "In: [[Self]]", |
| 36 | "Pending": "In: [[Nowhere]]", |
| 37 | "Sentence": "In: [[Projects]] and more.", |
| 38 | "Old title": "In: [[Old projects]]", |
| 39 | } { |
| 40 | mustCreate(t, store, title, body) |
| 41 | } |
| 42 | _, err := store.Retitle(ctx(), ana, parent.ID, "Old projects") |
| 43 | if err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | if _, err := store.Retitle(ctx(), ana, parent.ID, "Projects"); err != nil { |
| 47 | t.Fatal(err) |
| 48 | } |
| 49 | scratch, err := store.CreateScratch(ctx(), ana, "In: [[Projects]]") |
| 50 | if err != nil { |
| 51 | t.Fatal(err) |
| 52 | } |
| 53 | viewer, _ := store.Viewer(ctx(), ana, nil) |
| 54 | got := insideTitles(t, index, ScopeOf(viewer), parent.ID) |
| 55 | if got != "Beta, Alpha, Gamma, Old title" { |
| 56 | t.Fatalf("inside Projects: %q", got) |
| 57 | } |
| 58 | if got := insideTitles(t, index, ScopeOf(viewer), scratch.ID); got != "" { |
| 59 | t.Fatalf("a private page holds %q", got) |
| 60 | } |
| 61 | } |
| 62 | |