1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
local test_directory = arg[0]:match("^(.*)/") or "."
local h = dofile(test_directory .. "/harness.lua")
local script = arg[1]
h.load(script)
local function render(key, text)
return h.run({ key, "commit" }, { text })
end
h.equals("an unedited copy leaves a Closes mark as text", render("Closes", "#45"), "#45")
h.load_with(script, {
{ "-- { key = \"Closes\"", "{ key = \"Closes\"" },
{ "-- { key = \"Bug\"", "{ key = \"Bug\"" },
})
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.equals("six hex characters stay text", out, "123456")
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&b=2")
h.equals("a bare URL links to itself with its escaping kept", out,
"<a href='https://example.com/?a=1&b=2'>https://example.com/?a=1&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 = render("Reported-by", "a & b <c>")
h.equals("an escaped value passes through as it came", out, "a & b <c>")
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.load_with(script, { { "local rules = {", "local rules = { { key = \"Ref\", pattern = \"^(%S+)$\", url = \"https://t/%s\" }," } })
out = render("Ref", "a'b%c")
h.equals("a captured value is percent-encoded into the url", out, "<a href='https://t/a%27b%25c'>a'b%c</a>")
h.load_with(script, { { "local rules = {", "local rules = { { key = \"Fixes\", pattern = \"(%x+\", url = \"https://x/%s\" }," } })
out = render("Fixes", "1234567")
h.equals("a malformed rule is skipped for the next one", out, "<a href='./?id=1234567'>1234567</a>")
out = render("Link", "javascript://x")
h.equals("a url of any other scheme stays text", out, "javascript://x")
h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"^T(%d+)$\", url = \"https://t/%s\" }," } })
out = render("Whatever", "T12")
h.equals("a rule without a key applies to every trailer", out, "<a href='https://t/12'>T12</a>")
h.load_with(script, { { "local link_urls = true", "local link_urls = false" } })
out = render("Link", "https://example.com/x")
h.equals("bare urls can be left as text", out, "https://example.com/x")
h.load_with(script, {
{ "-- { key = \"CVE\"", "{ key = \"CVE\"" },
{ "-- url = \"https://www.cve.org", " url = \"https://www.cve.org" },
})
out = render("CVE", "CVE-2024-12345")
h.equals("the shipped CVE example links to its record", out,
"<a href='https://www.cve.org/CVERecord?id=CVE-2024-12345'>CVE-2024-12345</a>")
h.stays_linear("a long value is checked in linear time", function(text)
return (render("Link", text))
end, function(count) return string.rep("http://", count) .. " " end, 10000)
h.finish()
|