#!/bin/bash . "$TF_DIR/include/subtest.sh" . "$TF_DIR/include/tools.sh" . "$(sfpath)" || tf_exit_error "failed to init shellfu" export PRETTY=plain shellfu import mdfmt || tf_exit_error "failed to import mdfmt" tf_enum_subtests() { # # Whole text as single argument (fragment) # echo "single_h1" echo "single_h2" echo "single_h3" echo "single_p" echo "single_ul" echo "single_ol" echo "single_pre" # # Each line as separate argument (fragment) # echo "args_h1" echo "args_h2" echo "args_h3" echo "args_p" echo "args_ul" echo "args_ol" echo "args_pre" # # Blockquoted elements (single argument) # echo "blockquoted_h1" echo "blockquoted_h2" echo "blockquoted_h3" echo "blockquoted_p" echo "blockquoted_ul" echo "blockquoted_ol" echo "blockquoted_pre" # # Pairs of element types # echo "pair_h1_h2" echo "pair_h1_p" echo "pair_p_ol" echo "pair_p_ul" echo "pair_p_pre" # # Nested pairs of element types # echo "nest_ol_ol" echo "nest_ol_ul" echo "nest_ol_p" echo "nest_ol_pre" echo "nest_ul_ol" echo "nest_ul_ul" echo "nest_ul_p" echo "nest_ul_pre" # # A more full-fletched example # echo "doc_egg" } lipsum() { case $elm in p|ol|ul) echo -n \ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed" \ " do eiusmod tempor incididunt ut labore et dolore magna aliqua." \ " Ut enim ad minim veniam, quis nostrud exercitation ullamco" \ " laboris nisi ut aliquip ex ea commodo consequat. Duis aute" \ " irure dolor in reprehenderit in voluptate velit esse cillum" \ " dolore eu fugiat nulla pariatur. Excepteur sint occaecat" \ " cupidatat non proident, sunt in culpa qui officia deserunt" \ " mollit anim id est laborum." ;; h*) echo "How did I grow my rhino nose" ;; pre) echo 'found = False' echo 'for x in sequence:' echo ' if pred(x.n):' echo ' found = True' echo 'if found:' echo ' ...' ;; esac } do_mdfmt() { # # # local elm=$1 local pass=$2 local nest=$3 local args=() local frags=() test -n "$nest" && args=( --nest "$nest" ) case $name in blockquoted_*) args+=( --quote ) esac case $pass in line2frag) IFS=$'\n' frags=( $(lipsum) ) ;; single) frags=("$(lipsum)") ;; esac args+=( "$elm" "${frags[@]}") mdfmt "${args[@]}" } mkresult() { local elm elm1 elm2 elms case $name in single_*) elm=${name#single_} do_mdfmt "$elm" single ;; args_*) elm=${name#args_} do_mdfmt "$elm" line2frag ;; blockquoted_*) elm=${name#blockquoted_} do_mdfmt "$elm" single ;; pair_*) local elms=${name#pair_} local elm1=${elms%_*} local elm2=${elms#*_} do_mdfmt "$elm1" line2frag do_mdfmt "$elm2" line2frag ;; nest_*) local elms=${name#nest_} local elm1=${elms%_*} local elm2=${elms#*_} do_mdfmt "$elm1" line2frag do_mdfmt "$elm2" line2frag 1 ;; doc_egg) mdfmt h1 "how to boil an egg" mdfmt p "this tutorial shows you how to boil an egg" \ "the best way possible" mdfmt h2 "variant 1" mdfmt ol "take egg" mdfmt ol "put it in a pot full of water" mdfmt ol "place pot onto stove" mdfmt ol "turn on stove" mdfmt ol "wait" mdfmt --nest 1 ul "for soft-boiled, wait 3 minutes" mdfmt --nest 2 ol "wait first minute" mdfmt --nest 2 ol "wait second minute" mdfmt --nest 2 ol "wait third minute" mdfmt --nest 1 ul "for hard-boiled, wait 10 minutes" mdfmt ol "turn off the stove" mdfmt ol "replace water with cold water " mdfmt ol "break and replace shell from the egg" mdfmt h2 "variant 1" mdfmt ol "start your favorite browser" mdfmt ol "open youtube:" mdfmt --nest 1 pre "https://www.youtube.com/" mdfmt ol "enter following text in Search box:" mdfmt --nest 1 pre "how to boil an egg" mdfmt ol "watch at least 5 videos" mdfmt ol "go to the closest restaurant and ask for" \ "a boiled egg" mdfmt h2 "conclusion" mdfmt p "We hope you enjoy the egg. Seriously." mdfmt h2 "references" mdfmt p "This is what fsumsal said about it:" mdfmt -q p "OK. I feel honored by inclusion in the test." mdfmt p "A more thorough review by mr. knowitalmostall:" mdfmt -q p "The egg was good, except" mdfmt -q ul "the shell could have been softer," mdfmt -q ul "the yolk could have been harder," mdfmt -q ul "the white could have been yellower." mdfmt -q p "Overall, I liked it." mdfmt p "(It's worth noting that mr. knowitalmostall does not work" \ "in the egg review business anymore.)" ;; esac } tf_do_subtest() { local name=$1 tf_testflt -n "$name" -O "oracle/$name.stdout" "mkresult" } tf_do_subtests