-- Unit checks for custom/extensions/about-render.lua, run under a standalone -- Lua by t0501-about-render.sh with the script path as the first argument. -- The second argument may be nolpeg, which makes the lpeg module fail to -- load so the escaped plain text fallback is proven even on a machine where -- lpeg is installed. Without it the markdown and man checks run when lpeg is -- present and are skipped with a note when it is not, the same way the -- filter itself degrades. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") local script = arg[1] local mode = arg[2] or "" local has_lpeg = false if mode == "nolpeg" then h.preload_failure("lpeg") else has_lpeg = pcall(require, "lpeg") if not has_lpeg then io.write("lpeg not installed, markdown and man checks skipped\n") end end h.load(script) local function render(filename, text) return h.run({ filename }, { text }) end -- Dispatch and the plain text rendering need nothing but the script itself, -- so they run whatever became of lpeg. local out, ret = render("README", "plain & more") h.contains("no extension renders as plain text", out, "
plain <text> & more
") h.equals("close answers zero", ret, 0) out = render("notes.txt", "just text") h.contains("an unknown extension renders as plain text", out, "
just text
") out = render(nil, "no name at all") h.contains("a missing filename renders as plain text", out, "
no name at all
") -- cgit's C sink stops at the first NUL byte, which the script documents, so -- the text past one is lost while the wrapper written separately survives. out = render("README", "before\0after") h.contains("text before a nul byte survives", out, "before") h.excludes("text after a nul byte is dropped", out, "after") h.contains("the wrapper written after the text survives", out, "") out = h.run({ "README" }, { "two ", "writes" }) h.contains("writes are joined before rendering", out, "two writes") if mode == "nolpeg" then out = render("README.md", "# Title") h.contains("markdown without lpeg falls back to plain text", out, "
# Title
") out = render("page.1", ".SH NAME") h.contains("man without lpeg falls back to plain text", out, "
.SH NAME
") h.finish() end if not has_lpeg then h.finish() end -- Markdown. out = render("README.md", "# Title") h.contains("a heading renders inside the wrapper", out, "

Title

") out = render("README.md", "## Sub ##") h.contains("trailing hashes are stripped from a heading", out, "

Sub

") out = render("README.MD", "# Upper") h.contains("the extension matches whatever its case", out, "

Upper

") out = render("readme.markdown", "# Long") h.contains("the long markdown extension dispatches too", out, "

Long

") out = render("README.md", "line one\nline two") h.contains("a paragraph keeps its line break", out, "

line one
line two

") out = render("README.md", "first para\r\nsecond line") h.contains("crlf line endings are normalised", out, "

first para
second line

") out = render("README.md", "a **bold** and *leaning* word") h.contains("double stars embolden", out, "bold") h.contains("single stars lean", out, "leaning") out = render("README.md", "an __up__ and _down_ word") h.contains("double underscores embolden", out, "up") h.contains("single underscores lean", out, "down") out = render("README.md", "run `x < y` here") h.contains("inline code is escaped", out, "x < y") out = render("README.md", "raw here") h.contains("markup in text reaches the page escaped", out, "<script>alert(1)</script>") h.excludes("no live tag slips through", out, "