Fix section linking and editing
This commit is contained in:
@@ -252,3 +252,35 @@ func TestCanvasListedWithIcon(t *testing.T) {
|
||||
t.Error("canvas files do not get the canvas icon")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanvasSubpath(t *testing.T) {
|
||||
doc := []byte("# LAN Party 2026\nIntro.\n## Teilnehmer\n| Nr. | Name |\n| --- | --- |\n| 1. | Marci |\n")
|
||||
cases := []struct {
|
||||
subpath, want string
|
||||
ok bool
|
||||
}{
|
||||
{"", string(doc), true},
|
||||
// The last section of the file runs to its end.
|
||||
{"#teilnehmer", "## Teilnehmer\n| Nr. | Name |\n| --- | --- |\n| 1. | Marci |\n", true},
|
||||
// A heading takes the sections nested under it along.
|
||||
{"#LAN Party 2026", string(doc), true},
|
||||
{"#Gäste", "", false},
|
||||
{"#^block", "", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got, ok := canvasSubpath(doc, c.subpath)
|
||||
if ok != c.ok || string(got) != c.want {
|
||||
t.Errorf("canvasSubpath(%q) = %q, %v; want %q, %v", c.subpath, got, ok, c.want, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSectionSpanEndAtLastSection(t *testing.T) {
|
||||
sections := splitSections([]byte("# A\n## B\ntext\n"))
|
||||
if end := secionSpanEnd(sections, 2); end != 3 {
|
||||
t.Errorf("span of the last section ends at %d, want 3", end)
|
||||
}
|
||||
if end := secionSpanEnd(sections, 1); end != 3 {
|
||||
t.Errorf("span of the top section ends at %d, want 3", end)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user