Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Render the man pages that generators write
DocBook, pod2man and hand written pages leaked roff onto the page: font
escapes inside no fill blocks, comments, layout escapes such as \% and
\c, the colours and half line moves around DocBook's links, and the
requests and macro definitions their preambles open with. Those now
draw nothing, the common named characters and strings render, .EX and
pod2man's .Vb read as code, a .TP tag takes a line of its own and the
alternating font macros switch fonts between their arguments. Anything
rarer still falls back to its text.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extensions/test-about-render.lua | 71 | |
| -rwxr-xr-x | tests/t0501-about-render.sh | 43 |
2 files changed, 110 insertions, 4 deletions
diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 0571796..88c136c 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -257,6 +257,15 @@ render("README.md", string.rep("# a\n", 50000)) render("README.md", "| a | b |\n|---|---|\n| x" .. string.rep(" ", 40000) .. "y | z |") h.check("a long run of spaces is trimmed quickly", os.clock() - started < 10) +-- The long forms of the man escapes scan for a closing bracket or quote, so +-- they are bounded the same way, and a line of openers stays linear. +started = os.clock() +render("page.1", string.rep("\\[", 100000)) +render("page.1", string.rep("\\f[", 100000)) +render("page.1", string.rep("\\h'", 100000)) +render("page.1", string.rep("\\s[", 100000)) +h.check("a line of unclosed man escapes renders quickly", os.clock() - started < 10) + out = render("README.md", "Title\n=====\n\nBody") h.contains("equals signs under a line make a heading", out, "<h1 id='title'>Title</h1><p>Body</p>") @@ -334,13 +343,71 @@ h.contains("the bold macro renders strong", out, "<p><strong>bold words</strong> out = render("page.1", "a \\fBbold\\fR c") h.contains("font escapes carry across a run", out, "<p>a <strong>bold</strong> c</p>") -out = render("page.1", "x \\(em y \\- z") -h.contains("character escapes are translated", out, "<p>x - y - z</p>") +out = render("page.1", "x \\(em y \\- z \\(bu \\[co]") +h.contains("character escapes are translated", out, "<p>x — y - z • ©</p>") + +out = render("page.1", "\\*(lqquoted\\*(rq\\*R") +h.contains("predefined strings are expanded", out, "<p>“quoted”®</p>") + +out = render("page.1", "a\\%b c\\:d \\s-1SMALL\\s0 text \\\" a comment") +h.contains("escapes that only steer the layout draw nothing", out, "<p>ab cd SMALL text </p>") out = render("page.1", ".nf\ncode <x>\n.fi\nafter") h.contains("a no fill block renders as code", out, "<pre><code>code <x>\n</code></pre>") h.contains("filling resumes after it", out, "<p>after</p>") +out = render("page.1", ".nf\n\\fBgit\\fR \\-\\-version\n.fi") +h.contains("a no fill block shows the text of its escapes", out, "<pre><code>git --version\n</code></pre>") + +out = render("page.1", ".EX\nline <one>\n.EE") +h.contains("an example block renders as code", out, "<pre><code>line <one>\n</code></pre>") + +out = render("page.1", ".TP\n.B \\-v\nBe verbose.") +h.contains("a tag takes a line of its own", out, "<p><strong>-v</strong><br>\nBe verbose.</p>") + +out = render("page.1", ".IP \\(bu 2\nAn item.\n.IP \\-v 4\nA flag.") +h.contains("a bullet leads its item", out, "<p>• \nAn item.</p>") +h.contains("a longer tag takes a line of its own", out, "<p>-v<br>\nA flag.</p>") + +out = render("page.1", ".BR ls (1),\n.IR file .txt") +h.contains("alternating macros switch fonts between arguments", out, + "<strong>ls</strong>(1),\n<em>file</em>.txt") + +out = render("page.1", '.B "two words" three') +h.contains("a quoted argument keeps its blank", out, "<strong>two words three</strong>") + +out = render("page.1", "one\n.br\ntwo\n.\nthree") +h.contains("a break request breaks the line", out, "<p>one<br>\ntwo\nthree</p>") + +-- pod2man and asciidoctor open their pages with macro definitions and +-- conditional requests, none of which may reach the page as text. +out = render("page.1", table.concat({ + ".de Vb", ".nf", "..", ".de IX", "..", ".if n .ds Aq '", ".ie \\n(.g \\{\\", + ". nr x 1", ".\\}", ".SH NAME", ".IX Header \"NAME\"", ".Vb 2", "\\& code", ".Ve", "after", +}, "\n")) +h.excludes("a page's own macro is not drawn", out, "Header") +h.excludes("a roff request is not drawn", out, "Aq") +h.contains("the heading after the preamble renders", out, "<h2 id='name'>NAME</h2>") +h.contains("pod2man's verbatim macros render code", out, "<pre><code> code\n</code></pre>") +h.contains("text after the definitions renders", out, "<p>after</p>") + +out = render("page.1", ".if n \\\n\\{\\\n.ds x y\n.\\}\nafter") +h.contains("a conditional block's requests and braces draw nothing", out, + "<div class='markdown manpage'><p>after</p></div>") + +out = render("page.1", "The \\m[blue]\\fBManual\\fR\\m[]\\s-2\\u[1]\\d\\s+2 here") +h.contains("DocBook's link colours and footnote marks draw nothing", out, + "<p>The <strong>Manual</strong>[1] here</p>") + +out = render("page.1", ".de x\n.B hidden\n.. \nshown") +h.contains("a definition ends at two dots with blanks after them", out, + "<div class='markdown manpage'><p>shown</p></div>") + +out = render("page.1", ".TP\n.PD 0\n.B \\-a\nall\n.PD\nDon\\*(Aqt") +h.excludes("a spacing macro draws nothing", out, ">0") +h.contains("DocBook's apostrophe string expands", out, "Don't") + + out = render("page.1", '.\\" a comment\nvisible') h.excludes("a roff comment is dropped", out, "comment") h.contains("the line after it renders", out, "visible") diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index 263c79b..339c5e2 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -39,7 +39,20 @@ test_expect_success 'create a repository with a markdown readme' ' See the [roadmap](ROADMAP.md#plan). EOF - git add README.md && + cat >tool.1 <<-\EOF && + .TH TOOL 1 + .SH NAME + tool \- does one thing \(em well + .SH OPTIONS + .TP + .B \-v + Be \fIverbose\fR. + .nf + tool \-v <file> + .fi + EOF + echo "Plain <b>notes</b> & more" >NOTES && + git add README.md tool.1 NOTES && git commit -m "add readme" && git branch next ) @@ -53,11 +66,20 @@ test_expect_success 'point cgit at it through the about filter' ' repo.path=$PWD/repos/md/.git repo.readme=:README.md repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua + repo.url=man + repo.path=$PWD/repos/md/.git + repo.readme=:tool.1 + repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua + repo.url=txt + repo.path=$PWD/repos/md/.git + repo.readme=:NOTES + repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua EOF ' if test "$CGIT_HAS_LUA" -eq 1 then + test_set_prereq CGIT_LUA if cgit_lua_probe "$PWD/repos/md/.git" lpeg then test_set_prereq CGIT_LUA_LPEG @@ -91,10 +113,27 @@ test_expect_success CGIT_LUA_LPEG 'the link stays on the branch shown' ' grep "<a href=./md/tree/ROADMAP.md?h=next#plan.>roadmap</a>" tmp ' +test_expect_success CGIT_LUA_LPEG 'the about page renders a man page' ' + cgit_url "man/about/" >tmp && + grep "<div class=.markdown manpage.><h2 id=.name.>NAME</h2>" tmp && + grep "tool - does one thing — well" tmp && + grep "<strong>-v</strong><br>" tmp && + grep "<pre><code>tool -v <file>" tmp && + ! grep "\\\\f" tmp +' + +test_expect_success CGIT_LUA 'the about page shows plain text as it is' ' + cgit_url "txt/about/" >tmp && + grep "<pre class=.plaintext.>Plain <b>notes</b> & more" tmp +' + test_expect_success CGIT_LUA_NOLPEG 'without lpeg the readme is served escaped' ' cgit_url "md/about/" >tmp && grep "<pre class=.plaintext.>" tmp && - grep "# The Title" tmp + grep "# The Title" tmp && + cgit_url "man/about/" >tmp && + grep "<pre class=.plaintext.>" tmp && + grep ".SH NAME" tmp ' test_done |
