tvl-depot/web/panettone/test/inline-markdown_test.lisp
sterni 82e07fc046 feat(panettone): render a subset of markdown in issue subjects
This is achieved by implementing a simple markdown renderer in CL which
has the following limitations:

* Only supports inline `code`, *emphasize 1*, _emphasize 2_ and
  ~~strikethrough~~.
* Does not support nested markup.

This allows for a relatively simple renderer which doesn't need to parse
markdown into a in-memory data structure first. The rendered result is
directly written to a stream to integrate well with cl-who which is also
reused for rendering tags and xml-escaping strings.

Fixes #90.

Change-Id: Ice88ed770b1fab6365f3b93e8663e25077befa0b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2389
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: tazjin <mail@tazj.in>
2021-01-25 21:02:38 +00:00

54 lines
1.8 KiB
Common Lisp

(in-package :panettone.tests)
(declaim (optimize (safety 3)))
(defmacro inline-markdown-unit-test (name input expected)
`(test ,name
(is (equal
,expected
(with-output-to-string (*standard-output*)
(render-inline-markdown ,input))))))
(inline-markdown-unit-test
inline-markdown-typical-test
"hello _world_, here is ~~no~~ `code`!"
"hello <em>world</em>, here is <del>no</del> <code>code</code>!")
(inline-markdown-unit-test
inline-markdown-two-emphasize-types-test
"_stress_ *this*"
"<em>stress</em> <em>this</em>")
(inline-markdown-unit-test
inline-markdown-html-escaping-test
"<tag>öäü"
"&lt;tag&gt;&#246;&#228;&#252;")
(inline-markdown-unit-test
inline-markdown-nesting-test
"`inside code *anything* goes`, but also ~~*here*~~"
"<code>inside code *anything* goes</code>, but also <del>*here*</del>")
(inline-markdown-unit-test
inline-markdown-escaping-test
"A backslash \\\\ shows: \\*, \\_, \\` and \\~~"
"A backslash \\ shows: *, _, ` and ~~")
(inline-markdown-unit-test
inline-markdown-nested-escaping-test
"`prevent \\`code\\` from ending, but never stand alone \\\\`"
"<code>prevent `code` from ending, but never stand alone \\</code>")
(inline-markdown-unit-test
inline-markdown-escape-normal-tokens-test
"\\Normal tokens \\escaped?"
"\\Normal tokens \\escaped?")
(inline-markdown-unit-test
inline-markdown-no-unclosed-tags-test
"A tag, once opened, _must be closed"
"A tag, once opened, <em>must be closed</em>")
(inline-markdown-unit-test
inline-markdown-unicode-safe
"Does Unicode 👨‍👨‍👧‍👦 break \\👩🏾‍🦰 tokenization?"
"Does Unicode &#128104;&#8205;&#128104;&#8205;&#128103;&#8205;&#128102; break \\&#128105;&#127998;&#8205;&#129456; tokenization?")