Skip to content
quarry Artifact [85ffa45be4]
Login

Artifact [85ffa45be4]

Artifact 85ffa45be419b14eed800130025d7bad7e8a4d475f5f677925869014ffbb86dd:


package web

import "testing"

func TestCommentHTML(t *testing.T) {
	for in, want := range map[string]string{
		"fix [0123abcdef] regression": `fix <a href="/r/tk/info/0123abcdef">0123abcdef</a> regression`,
		"see [0123abcdef|the fix]":    `see <a href="/r/tk/info/0123abcdef">the fix</a>`,
		"per [https://x.test/a|docs]": `per <a href="https://x.test/a">docs</a>`,
		"read [Release Notes]":        `read [Release Notes]`,
		"a <b> & [c|<d>]":             `a &lt;b&gt; &amp; [c|&lt;d&gt;]`,
		"case[0] in code":             `case[0] in code`,
		"empty [] brackets":           `empty [] brackets`,
		// An unlabelled fossil route must not print its own path as the
		// link text. quarry aims these at the forum INDEX on purpose:
		// measured against a fossil clone, 303 of 304 cited forum
		// hashes are not present locally, so a deep link would 404.
		"see [/forumpost/741c673e9e]":                             `see <a href="/r/tk/forum">forum post 741c673e9e</a>`,
		"ref [forum:/forumpost/9adfe7e46b|forum post 9adfe7e46b]": `ref <a href="/r/tk/forum">forum post 9adfe7e46b</a>`,
		// A label that WAS given always wins over the derived one.
		"see [/forumpost/741c673e9e|the report]": `see <a href="/r/tk/forum">the report</a>`,
		// The explicit spellings of an artifact citation reach the same
		// page a bare [hash] does; fossil's own comments use these.
		"per [/info/0123abcdef]":           `per <a href="/r/tk/info/0123abcdef">0123abcdef</a>`,
		"per [/artifact/0123abcdef|art]":   `per <a href="/r/tk/info/0123abcdef">art</a>`,
		"per [/whatis/0123abcdef|what]":    `per <a href="/r/tk/info/0123abcdef">what</a>`,
		"see [/tktview/0123abcdef]":        `see <a href="/r/tk/ticket/0123abcdef">ticket 0123abcdef</a>`,
		"see [/tktview?name=0123abcdef|t]": `see <a href="/r/tk/ticket/0123abcdef">t</a>`,
		// A timestamp names nothing quarry can resolve, so it keeps its
		// documented fate: the label, never the raw markup.
		"bug [/info/2020-06-02T17:38z|introduced then]": `bug introduced then`,
		// Routes quarry has no page for still degrade to their label.
		"see [/finfo?name=src/x.c|the file]": `see the file`,
		"see [/brlist|branches]":             `see branches`,
	} {
		if got := string(commentHTML("tk", in)); got != want {
			t.Errorf("commentHTML(%q)\n got  %s\n want %s", in, got, want)
		}
	}
}