// SPDX-License-Identifier: AGPL-3.0-or-later package directory import "testing" func TestRelPath(t *testing.T) { for _, c := range []struct{ from, to, want string }{ {"A.md", "B.md", "B.md"}, {"A.md", "A/B.md", "A/B.md"}, {"A/B.md", "A.md", "../A.md"}, {"A/B/C.md", "A/D.md", "../D.md"}, {"Guides/Set up.md", "_files/a b.png", "../_files/a%20b.png"}, {"index.md", "X/Y.md", "X/Y.md"}, } { if got := relPath(c.from, c.to); got != c.want { t.Errorf("relPath(%q, %q) = %q, want %q", c.from, c.to, got, c.want) } } } func TestUniqueName(t *testing.T) { taken := map[string]map[string]bool{"": {"index": true}} for _, want := range []string{"Notes", "Notes (2)", "Notes (3)"} { if got := uniqueName(taken, "", "Notes"); got != want { t.Errorf("got %q, want %q", got, want) } } if got := uniqueName(taken, "", "Index"); got != "Index (2)" { t.Errorf("index not reserved: %q", got) } if got := uniqueName(taken, "Notes", "Notes"); got != "Notes" { t.Errorf("folders share names: %q", got) } }