shell dot on steroids https://pagure.io/shellfu

TF_RUN 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. . "$TF_DIR/include/subtest.sh"
  3. . "$TF_DIR/include/tools.sh"
  4. . "$(sfpath)" || tf_exit_error "failed to init shellfu"
  5. export PRETTY=plain
  6. shellfu import mdfmt || tf_exit_error "failed to import mdfmt"
  7. tf_enum_subtests() {
  8. #
  9. # Whole text as single argument (fragment)
  10. #
  11. echo "single_h1"
  12. echo "single_h2"
  13. echo "single_h3"
  14. echo "single_p"
  15. echo "single_ul"
  16. echo "single_ol"
  17. echo "single_pre"
  18. #
  19. # Each line as separate argument (fragment)
  20. #
  21. echo "args_h1"
  22. echo "args_h2"
  23. echo "args_h3"
  24. echo "args_p"
  25. echo "args_ul"
  26. echo "args_ol"
  27. echo "args_pre"
  28. #
  29. # Blockquoted elements (single argument)
  30. #
  31. echo "blockquoted_h1"
  32. echo "blockquoted_h2"
  33. echo "blockquoted_h3"
  34. echo "blockquoted_p"
  35. echo "blockquoted_ul"
  36. echo "blockquoted_ol"
  37. echo "blockquoted_pre"
  38. #
  39. # Pairs of element types
  40. #
  41. echo "pair_h1_h2"
  42. echo "pair_h1_p"
  43. echo "pair_p_ol"
  44. echo "pair_p_ul"
  45. echo "pair_p_pre"
  46. #
  47. # Nested pairs of element types
  48. #
  49. echo "nest_ol_ol"
  50. echo "nest_ol_ul"
  51. echo "nest_ol_p"
  52. echo "nest_ol_pre"
  53. echo "nest_ul_ol"
  54. echo "nest_ul_ul"
  55. echo "nest_ul_p"
  56. echo "nest_ul_pre"
  57. #
  58. # A more full-fletched example
  59. #
  60. echo "doc_egg"
  61. }
  62. lipsum() {
  63. case $elm in
  64. p|ol|ul)
  65. echo -n \
  66. "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed" \
  67. " do eiusmod tempor incididunt ut labore et dolore magna aliqua." \
  68. " Ut enim ad minim veniam, quis nostrud exercitation ullamco" \
  69. " laboris nisi ut aliquip ex ea commodo consequat. Duis aute" \
  70. " irure dolor in reprehenderit in voluptate velit esse cillum" \
  71. " dolore eu fugiat nulla pariatur. Excepteur sint occaecat" \
  72. " cupidatat non proident, sunt in culpa qui officia deserunt" \
  73. " mollit anim id est laborum."
  74. ;;
  75. h*)
  76. echo "How did I grow my rhino nose"
  77. ;;
  78. pre)
  79. echo 'found = False'
  80. echo 'for x in sequence:'
  81. echo ' if pred(x.n):'
  82. echo ' found = True'
  83. echo 'if found:'
  84. echo ' ...'
  85. ;;
  86. esac
  87. }
  88. do_mdfmt() {
  89. #
  90. #
  91. #
  92. local elm=$1
  93. local pass=$2
  94. local nest=$3
  95. local args=()
  96. local frags=()
  97. test -n "$nest" && args=( --nest "$nest" )
  98. case $name in
  99. blockquoted_*) args+=( --quote )
  100. esac
  101. case $pass in
  102. line2frag)
  103. IFS=$'\n' frags=( $(lipsum) )
  104. ;;
  105. single)
  106. frags=("$(lipsum)")
  107. ;;
  108. esac
  109. args+=( "$elm" "${frags[@]}")
  110. mdfmt "${args[@]}"
  111. }
  112. mkresult() {
  113. local elm elm1 elm2 elms
  114. case $name in
  115. single_*)
  116. elm=${name#single_}
  117. do_mdfmt "$elm" single
  118. ;;
  119. args_*)
  120. elm=${name#args_}
  121. do_mdfmt "$elm" line2frag
  122. ;;
  123. blockquoted_*)
  124. elm=${name#blockquoted_}
  125. do_mdfmt "$elm" single
  126. ;;
  127. pair_*)
  128. local elms=${name#pair_}
  129. local elm1=${elms%_*}
  130. local elm2=${elms#*_}
  131. do_mdfmt "$elm1" line2frag
  132. do_mdfmt "$elm2" line2frag
  133. ;;
  134. nest_*)
  135. local elms=${name#nest_}
  136. local elm1=${elms%_*}
  137. local elm2=${elms#*_}
  138. do_mdfmt "$elm1" line2frag
  139. do_mdfmt "$elm2" line2frag 1
  140. ;;
  141. doc_egg)
  142. mdfmt h1 "how to boil an egg"
  143. mdfmt p "this tutorial shows you how to boil an egg" \
  144. "the best way possible"
  145. mdfmt h2 "variant 1"
  146. mdfmt ol "take egg"
  147. mdfmt ol "put it in a pot full of water"
  148. mdfmt ol "place pot onto stove"
  149. mdfmt ol "turn on stove"
  150. mdfmt ol "wait"
  151. mdfmt --nest 1 ul "for soft-boiled, wait 3 minutes"
  152. mdfmt --nest 2 ol "wait first minute"
  153. mdfmt --nest 2 ol "wait second minute"
  154. mdfmt --nest 2 ol "wait third minute"
  155. mdfmt --nest 1 ul "for hard-boiled, wait 10 minutes"
  156. mdfmt ol "turn off the stove"
  157. mdfmt ol "replace water with cold water "
  158. mdfmt ol "break and replace shell from the egg"
  159. mdfmt h2 "variant 1"
  160. mdfmt ol "start your favorite browser"
  161. mdfmt ol "open youtube:"
  162. mdfmt --nest 1 pre "https://www.youtube.com/"
  163. mdfmt ol "enter following text in Search box:"
  164. mdfmt --nest 1 pre "how to boil an egg"
  165. mdfmt ol "watch at least 5 videos"
  166. mdfmt ol "go to the closest restaurant and ask for" \
  167. "a boiled egg"
  168. mdfmt h2 "conclusion"
  169. mdfmt p "We hope you enjoy the egg. Seriously."
  170. mdfmt h2 "references"
  171. mdfmt p "This is what fsumsal said about it:"
  172. mdfmt -q p "OK. I feel honored by inclusion in the test."
  173. mdfmt p "A more thorough review by mr. knowitalmostall:"
  174. mdfmt -q p "The egg was good, except"
  175. mdfmt -q ul "the shell could have been softer,"
  176. mdfmt -q ul "the yolk could have been harder,"
  177. mdfmt -q ul "the white could have been yellower."
  178. mdfmt -q p "Overall, I liked it."
  179. mdfmt p "(It's worth noting that mr. knowitalmostall does not work" \
  180. "in the egg review business anymore.)"
  181. ;;
  182. esac
  183. }
  184. tf_do_subtest() {
  185. local name=$1
  186. tf_testflt -n "$name" -O "oracle/$name.stdout" "mkresult"
  187. }
  188. tf_do_subtests