From a550379d2e90f05599b2e5a4bbc75bd3a070c35f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 11 May 2021 18:40:16 +0100 Subject: pass md unit tests # Please enter the commit message for your changes. Lines starting --- buetow.org.sh | 87 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/buetow.org.sh b/buetow.org.sh index ab2e84d9..ae57c8e6 100755 --- a/buetow.org.sh +++ b/buetow.org.sh @@ -213,7 +213,7 @@ generic::link () { fi if [ $what == markdown ]; then - html::markdown "$link" "$descr" + markdown::link "$link" "$descr" else html::link "$link" "$(html::special "$descr")" fi @@ -368,46 +368,46 @@ html::generate () { } html::test () { - local line="Hello world! This is a paragraph." - assert::equals "$(html::paragraph "$line")" "

Hello world! This is a paragraph.

" + local line='Hello world! This is a paragraph.' + assert::equals "$(html::paragraph "$line")" '

Hello world! This is a paragraph.

' - line="" - assert::equals "$(html::paragraph "$line")" "" + line='' + assert::equals "$(html::paragraph "$line")" '' - line="Foo &<>& Bar!" - assert::equals "$(html::paragraph "$line")" "

Foo &<>& Bar!

" + line='Foo &<>& Bar!' + assert::equals "$(html::paragraph "$line")" '

Foo &<>& Bar!

' - line="# Header 1" - assert::equals "$(html::heading "$line" 1)" "

Header 1

" + line='# Header 1' + assert::equals "$(html::heading "$line" 1)" '

Header 1

' - line="## Header 2" - assert::equals "$(html::heading "$line" 2)" "

Header 2

" + line='## Header 2' + assert::equals "$(html::heading "$line" 2)" '

Header 2

' - line="### Header 3" - assert::equals "$(html::heading "$line" 3)" "

Header 3

" + line='### Header 3' + assert::equals "$(html::heading "$line" 3)" '

Header 3

' - line="> This is a quote" - assert::equals "$(html::quote "$line")" "
This is a quote
" + line='> This is a quote' + assert::equals "$(html::quote "$line")" '
This is a quote
' - line="=> https://example.org" + line='=> https://example.org' assert::equals "$(generic::link html "$line")" \ - "https://example.org
" + 'https://example.org
' - line="=> index.gmi" + line='=> index.gmi' assert::equals "$(generic::link html "$line")" \ - "index.html
" + 'index.html
' - line="=> http://example.org Description of the link" + line='=> http://example.org Description of the link' assert::equals "$(generic::link html "$line")" \ - "Description of the link
" + 'Description of the link
' - line="=> http://example.org/image.png" + line='=> http://example.org/image.png' assert::equals "$(generic::link html "$line")" \ - "
" + '
' - line="=> http://example.org/image.png Image description" + line='=> http://example.org/image.png Image description' assert::equals "$(generic::link html "$line")" \ - "Image description:\"Image
" + 'Image description:Image description
' } ## Markdown module @@ -417,44 +417,42 @@ markdown::img () { local descr="$1"; shift if [ -z "$descr" ]; then - echo -n "" + echo "[![$link]($link)]($link)" else - echo -n "$descr:" - echo -n "\"$descr\"" + echo "[![$descr]($link \"$descr\")]($link)" fi - - echo "
" } markdown::link () { local link="$1"; shift - local -r descr="$1"; shift + local descr="$1"; shift - grep -F -q '://' <<< "$link" || link=${link/.gmi/.html} + grep -F -q '://' <<< "$link" || link=${link/.gmi/.md} test -z "$descr" && descr="$link" - echo "$descr
" + + echo "[$descr]($link)" } markdown::test () { - local line="=> https://example.org" + local line='=> https://example.org' assert::equals "$(generic::link markdown "$line")" \ - "https://example.org
" + '[https://example.org](https://example.org)' - line="=> index.md" + line='=> index.md' assert::equals "$(generic::link markdown "$line")" \ - "index.md
" + '[index.md](index.md)' - line="=> http://example.org Description of the link" + line='=> http://example.org Description of the link' assert::equals "$(generic::link markdown "$line")" \ - "Description of the link
" + '[Description of the link](http://example.org)' - line="=> http://example.org/image.png" + line='=> http://example.org/image.png' assert::equals "$(generic::link markdown "$line")" \ - "
" + '[![http://example.org/image.png](http://example.org/image.png)](http://example.org/image.png)' - line="=> http://example.org/image.png Image description" + line='=> http://example.org/image.png Image description' assert::equals "$(generic::link markdown "$line")" \ - "Image description:\"Image
" + '[![Image description](http://example.org/image.png "Image description")](http://example.org/image.png)' } @@ -473,6 +471,7 @@ HELPHERE case $ARG in --test) html::test + markdown::test ;; --feeds) gemfeed::generate @@ -480,7 +479,7 @@ case $ARG in ;; --generate) html::test - # markdown::test + markdown::test gemfeed::generate atomfeed::generate # markdown::generate -- cgit v1.2.3