Reuse parsed validation content by blob
This commit is contained in:
@@ -87,11 +87,13 @@ func TestParseMarkdownHeadingAnchors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarkdownCacheKeepsParsedDocumentsPerCandidatePath(t *testing.T) {
|
||||
func TestMarkdownCacheSharesParsedDocumentsByBlobObjectID(t *testing.T) {
|
||||
repository := newTreeRepository(t)
|
||||
writeTreeFile(t, repository, "guide.md", []byte("# Guide\n[other](other.md)\n"))
|
||||
writeTreeFile(t, repository, "other.md", []byte("# Other\n"))
|
||||
gitTree(t, repository, "add", "guide.md", "other.md")
|
||||
shared := []byte("# Guide\n[other](other.md \"title\")\n")
|
||||
writeTreeFile(t, repository, "one/guide.md", shared)
|
||||
writeTreeFile(t, repository, "two/guide.md", shared)
|
||||
writeTreeFile(t, repository, "one/other.md", []byte("# Other\n"))
|
||||
gitTree(t, repository, "add", "one/guide.md", "two/guide.md", "one/other.md")
|
||||
gitTree(t, repository, "commit", "-m", "add markdown files")
|
||||
|
||||
commit := strings.TrimSpace(gitTree(t, repository, "rev-parse", "HEAD"))
|
||||
@@ -101,25 +103,28 @@ func TestMarkdownCacheKeepsParsedDocumentsPerCandidatePath(t *testing.T) {
|
||||
}
|
||||
cleanupCandidateTree(t, tree)
|
||||
cache := newMarkdownCache(tree)
|
||||
first, err := cache.document(context.Background(), "guide.md")
|
||||
first, err := cache.document(context.Background(), "one/guide.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := cache.document(context.Background(), "guide.md")
|
||||
second, err := cache.document(context.Background(), "two/guide.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if first != second {
|
||||
t.Fatal("repeated document lookup returned a different parsed document")
|
||||
t.Fatal("identical Markdown blobs returned different parsed documents")
|
||||
}
|
||||
other, err := cache.document(context.Background(), "other.md")
|
||||
other, err := cache.document(context.Background(), "one/other.md")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if other == first {
|
||||
t.Fatal("different candidate paths shared a parsed document")
|
||||
t.Fatal("different Markdown blobs shared a parsed document")
|
||||
}
|
||||
if _, ok := other.anchors["other"]; !ok {
|
||||
t.Fatalf("other document anchors = %#v", other.anchors)
|
||||
}
|
||||
if got := first.links[0]; got.Destination != "other.md" || got.Title != "title" || got.Location.Line != 2 {
|
||||
t.Fatalf("shared Markdown link = %#v, want content-relative destination, title, and location", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user