package api
import (
"strings"
"testing"
"craftdesign.group/quarry/internal/markup"
)
// A compiled wiki's citations name one file at one check-in in either
// of fossil's spellings; both reach quarry's file page, and a technote
// this repository does not hold goes to the list rather than a 404.
func TestFossilFileAndTechnoteLinksResolve(t *testing.T) {
r := resolver{repo: "kb"}
for in, want := range map[string]string{
"/file?name=sources/specs/a.md&ci=0123456789abcdef&txt=1": "/r/kb/file/0123456789abcdef/sources/specs/a.md?txt=1",
"/file/sources/specs/a.md?ci=0123456789abcdef": "/r/kb/file/0123456789abcdef/sources/specs/a.md",
"/file?name=README.md": "/r/kb/file/trunk/README.md",
"/file?name=dir/with%20space.md&ci=abc0123456": "/r/kb/file/abc0123456/dir/with%20space.md",
"/file": "",
"/technote/0123456789abcdef": "/r/kb/technote",
} {
if got := r.ResolvePath(in); got != want {
t.Errorf("FAIL: %s -> %q, want %q", in, got, want)
}
}
}
// Through the Markdown renderer, as a wiki page is drawn: the & in the
// rendered href is written &, and the check-in must survive it.
func TestAWikiCitationRendersAsALinkToTheFile(t *testing.T) {
out, err := markup.Render([]byte("See [the spec](/file?name=sources/specs/a.md&ci=0123456789abcdef&txt=1)."), resolver{repo: "kb"})
if err != nil {
t.Fatal(err)
}
if want := `href="/r/kb/file/0123456789abcdef/sources/specs/a.md?txt=1"`; !strings.Contains(string(out), want) {
t.Errorf("FAIL: rendered %s, want a link %s", out, want)
}
}