diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Add the link-trailers extension
Diffstat (limited to '')
-rw-r--r--tests/extensions/test-link-trailers.lua66
1 file changed, 66 insertions, 0 deletions
diff --git a/tests/extensions/test-link-trailers.lua b/tests/extensions/test-link-trailers.lua
new file mode 100644
index 0000000..c879340
--- /dev/null
+++ b/tests/extensions/test-link-trailers.lua
@@ -0,0 +1,66 @@
+-- Unit checks for custom/extensions/link-trailers.lua, run under a standalone
+-- Lua by t0506-link-trailers.sh with the script path as the argument. The
+-- shipped configuration links Fixes and Reverts object names to ./?id=,
+-- Closes and Bug marks to bugs.example.com and a bare URL to itself, and
+-- everything here checks that shape, the key matching and the values that
+-- must pass through untouched.
+
+local test_directory = arg[0]:match("^(.*)/") or "."
+local h = dofile(test_directory .. "/harness.lua")
+
+h.load(arg[1])
+
+local function render(key, text)
+ return h.run({ key, "commit" }, { text })
+end
+
+local out, ret = render("Fixes", "1234567 (\"plain commit\")")
+h.contains("a Fixes object name links to its commit", out,
+ "<a href='./?id=1234567'>1234567</a> (\"plain commit\")")
+h.equals("close answers zero", ret, 0)
+
+out = render("fixes", "1234567")
+h.contains("the key matches case insensitively", out, "<a href='./?id=1234567'>1234567</a>")
+
+out = render("Fixes", "123456")
+h.excludes("six hex characters stay text", out, "<a")
+
+out = render("Reverts", "cafebabe")
+h.contains("a Reverts object name links too", out, "<a href='./?id=cafebabe'>cafebabe</a>")
+
+out = render("Closes", "#45")
+h.equals("a Closes mark links to the tracker", out,
+ "<a href='https://bugs.example.com/?bug=45'>#45</a>")
+
+out = render("Bug", "45")
+h.equals("a bare Bug number links to the tracker", out,
+ "<a href='https://bugs.example.com/?bug=45'>45</a>")
+
+out = render("Closes", "not a number")
+h.equals("a Closes value that is no number stays text", out, "not a number")
+
+out = render("Link", "https://example.com/?a=1&amp;b=2")
+h.equals("a bare URL links to itself with its escaping kept", out,
+ "<a href='https://example.com/?a=1&amp;b=2'>https://example.com/?a=1&amp;b=2</a>")
+
+out = render("Whatever", "https://example.com/x")
+h.contains("a URL links under any key", out, "<a href='https://example.com/x'>")
+
+out = render("Link", "https://example.com/it's")
+h.equals("a URL holding a quote stays text", out, "https://example.com/it's")
+
+out = render("Link", "see https://example.com/x")
+h.equals("a URL inside other text stays text", out, "see https://example.com/x")
+
+out = render("Reported-by", "someone")
+h.equals("a key with no rule passes through", out, "someone")
+
+out = h.run({ "Fixes", "commit" }, { "12345", "67 tail" })
+h.contains("a value split across writes is seen whole", out,
+ "<a href='./?id=1234567'>1234567</a> tail")
+
+out, ret = render("Fixes", "")
+h.equals("an empty value stays empty", out, "")
+h.equals("an empty value still answers zero", ret, 0)
+
+h.finish()