From e974027848e4f969aa2b21d79b2276d13cf2bafb Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Tue, 1 Sep 2026 17:22:14 -1000 Subject: Add a test suite for the shipped extensions --- tests/extensions/test-link-commits.lua | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/extensions/test-link-commits.lua (limited to 'tests/extensions/test-link-commits.lua') diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua new file mode 100644 index 0000000..6c6d28d --- /dev/null +++ b/tests/extensions/test-link-commits.lua @@ -0,0 +1,77 @@ +-- Unit checks for custom/extensions/link-commits.lua, run under a standalone +-- Lua by t0503-link-commits.sh with the script path as the argument. The +-- shipped configuration links bare object names to ./?id= and issue marks +-- like #123 to bugs.example.com, and everything here checks that shape, the +-- length bounds and frontier on hash recognition, and the rule that no run +-- of text is ever wrapped twice. + +local test_directory = arg[0]:match("^(.*)/") or "." +local h = dofile(test_directory .. "/harness.lua") + +h.load(arg[1]) + +local function render(text) + return h.run({}, { text }) +end + +local out, ret = render("see #123 for details") +h.contains("issue mark becomes a link", out, + "#123") +h.contains("text around the link survives", out, "see ") +h.contains("text after the link survives", out, " for details") +h.equals("close answers zero", ret, 0) + +out = render("fixed in deadbee") +h.contains("seven hex characters link", out, + "deadbee") + +out = render("fixed in deadbe") +h.excludes("six hex characters stay text", out, "1234567") + +local sha1 = string.rep("0123456789abcdef", 2) .. "01234567" +out = render("commit " .. sha1) +h.contains("a full sha1 name links", out, "'./?id=" .. sha1 .. "'") + +local sha256 = string.rep("0123456789abcdef", 4) +out = render("commit " .. sha256) +h.contains("a full sha256 name links", out, "'./?id=" .. sha256 .. "'") + +out = render("commit " .. sha256 .. "0") +h.excludes("sixty five hex characters stay text", out, "#1234567") +h.excludes("the overlapped hash is dropped", out, "./?id=") + +out = render("#12 and cafebabe12") +h.contains("both rules fire on one message", out, "?bug=12'>#12") +h.contains("the object link also fires", out, + "cafebabe12") + +-- One request is delivered as several writes, and a match split across two of +-- them has to be seen whole. +out = h.run({}, { "see #45", "6 and be done" }) +h.contains("a match split across writes still links", out, + "?bug=456'>#456") + +out, ret = render("") +h.equals("an empty message stays empty", out, "") +h.equals("an empty message still answers zero", ret, 0) + +out = render("plain words only") +h.equals("a message with no matches passes through", out, "plain words only") + +h.finish() -- cgit v2.8.0