Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Cover how link-commits applies its rules
Skipping a malformed rule, the tie between two rules, the scan past an
empty match, a rule with no capture and the switch for object names
were all untested, and none of the shipped examples beyond the issue
rule had ever been loaded.
Diffstat (limited to 'tests/extensions')
| -rw-r--r-- | tests/extensions/test-link-commits.lua | 41 |
1 file changed, 41 insertions, 0 deletions
diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua index 45a3f60..fa3a040 100644 --- a/tests/extensions/test-link-commits.lua +++ b/tests/extensions/test-link-commits.lua @@ -85,4 +85,45 @@ h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"T:(%S+ out = render("T:a'b%c") h.equals("a captured value is percent-encoded into the url", out, "<a href='https://t/a%27b%25c'>T:a'b%c</a>") +-- A malformed pattern is the operator's error, so that rule is skipped and +-- the others still run. +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"(%d+\", url = \"https://x/%s\" }," } }) +out = render("fixed 42 in deadbee") +h.equals("a malformed rule is skipped and object names still link", out, + "fixed 42 in <a href='./?id=deadbee'>deadbee</a>") + +-- Two rules matching at the same place leave it to the one listed first. +h.load_with(script, { { "local rules = {", + "local rules = { { pattern = \"#(%d+)\", url = \"https://a/%s\" }, { pattern = \"#(%d%d)\", url = \"https://b/%s\" }," } }) +out = render("#12") +h.equals("the rule listed first wins a tie", out, "<a href='https://a/12'>#12</a>") + +-- A pattern that can match nothing still moves the scan on, or the page +-- would never finish. +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"x*\", url = \"https://x/%s\" }," } }) +out = render("abc") +h.equals("a rule matching the empty string still reaches the end", (out:gsub("<[^>]*>", "")), "abc") + +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"RFC%d+\", url = \"https://r/%s\" }," } }) +out = render("see RFC123") +h.equals("a rule with no capture puts the whole match in the url", out, "see <a href='https://r/RFC123'>RFC123</a>") + +h.load_with(script, { { "enabled = true,", "enabled = false," } }) +out = render("fixed in deadbee") +h.equals("object names can be left unlinked", out, "fixed in deadbee") + +h.load_with(script, { + { "-- { pattern = \"CVE", "{ pattern = \"CVE" }, + { "-- url = \"https://www.cve.org", " url = \"https://www.cve.org" }, + { "-- { pattern = \"!", "{ pattern = \"!" }, + { "-- url = \"https://gitlab", " url = \"https://gitlab" }, + { "-- { pattern = \"RFC", "{ pattern = \"RFC" }, + { "-- url = \"https://www.rfc-editor", " url = \"https://www.rfc-editor" }, +}) +out = render("CVE-2024-12345, !42 and RFC 9110") +h.equals("the shipped examples link what they describe", out, + "<a href='https://www.cve.org/CVERecord?id=CVE-2024-12345'>CVE-2024-12345</a>, " .. + "<a href='https://gitlab.example.com/my/repo/-/merge_requests/42'>!42</a> and " .. + "<a href='https://www.rfc-editor.org/rfc/rfc9110'>RFC 9110</a>") + h.finish() |
