From 798cbf80c9184b4a9fccf953e4d8a2cbe3934ef7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 28 Aug 2024 15:46:39 +0200 Subject: [PATCH] test cases for markdown processor --- tests-markdown.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 tests-markdown.sh diff --git a/tests-markdown.sh b/tests-markdown.sh new file mode 100755 index 0000000..ae71068 --- /dev/null +++ b/tests-markdown.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +BR=' +' +CR="$(printf \r)" +fail() { printf '%s\n' "$@"; exit 1; } + +awk() { /bin/awk "$@"; } +md() { awk -f markdown.awk "$@"; } + +tcount=1 +assert() { + local md="$(printf '%s' "$1" |md)" comp="$2" msg="$3" + printf "%2i: %s ... " $tcount "$msg" + if [ "$md" != "$comp" ]; then + printf "Fail!\n:\n%s\n:\n%s\n" "$md" "$comp" + exit 1 + fi + printf 'OK\n' + tcount=$((tcount + 1)) +} + +# Inline checks +printf '## Testing Inline markup ##\n' + +# strong / em / ... +assert '~~strikeout~~' '

strikeout

' "strikeout" +assert '~~~strikeout~~' '

~strikeout

' "strikeout" +assert '^super^' '

super

' "superscript" +assert '~sub~' '

sub

' "subscript" + +assert "foo ${BR}bar" "

foo
${BR}bar

" 'double space line break' +assert '```©```' "

©

" "code span escape" + +assert '_emphasized text_' '

emphasized text

' "em" +assert '_emphasized_text_' '

emphasized_text

' "em" +assert 'empha*sized* text_' '

emphasized text_

' "em" +assert '__empha*sized* text__' '

emphasized text

' "strong em" +assert '***strem***' '

strem

' "strong em" +assert '***str**em*' '

strem

' "em strong" +assert '_**strem**_' '

strem

' "em strong" + +# Escaping +assert "©" "

©

" "escape" +assert "\©" "

©

" "escape" +assert "AT&T" "

AT&T

" "escape" +assert '`©`' "

©

" "code span escape" + +# Automatic Links +assert '' "

https://de.wikipedia.org

" "automatic link" +assert '' "

http://de.wikipedia.org

" "automatic link" +# assert '' "

http://de.wikipedia.org

" "automatic link" + +# Inline Links +assert '[Wikipedia](http://de.wikipedia.org)' "

Wikipedia

" "inline link" +assert '[Wikipedia](http://de.wikipedia.org "Online Encyclopedia")' "

Wikipedia

" "inline link" +assert '[Wikipedia]( "Online Encyclopedia")' "

Wikipedia

" "inline link" + +# Inline Images (note leading white space) +assert ' ![Testbild](Test Bild.jpg)' '

Testbild

' "inline image" +assert ' ![Testbild](Test Bild.jpg "German Television *test* image ca. 1994")' '

Testbild

' "inline image" +assert ' ![Testbild *ARD*](Test Bild.jpg){tv ard function-check}' '

Testbild *ARD*

' "inline image" +# assert ' ![Testbild *ARD*](Test Bild.jpg){#tv .ard .function-check}' '

Testbild *ARD*

' "inline image id/classes" + +assert '[![Wikipedia](wikilogo.png)]()'\ + '

Wikipedia

'\ + "Image Link" + +# Block checks +printf '\n## Testing Block markup ##\n' + +assert \ +'foo + +bar' \ +'

foo

+ +

bar

' \ +'paragraphs' + +assert '%meta *data block* + ignored `no` __formatting__' \ +'' \ +"meta data block" + +printf '\nAll test passed!\n' -- 2.39.2