Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
2.9 KiB

  1. . tests/functions.sh
  2. title "tables"
  3. rc=0
  4. MARKDOWN_FLAGS=
  5. try 'single-column table' \
  6. '|hello
  7. |-----
  8. |sailor' \
  9. '<table>
  10. <thead>
  11. <tr>
  12. <th>hello</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <td>sailor</td>
  18. </tr>
  19. </tbody>
  20. </table>'
  21. try 'two-column table' \
  22. '
  23. a | b
  24. -----|------
  25. hello|sailor' \
  26. '<table>
  27. <thead>
  28. <tr>
  29. <th>a </th>
  30. <th> b</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <tr>
  35. <td>hello</td>
  36. <td>sailor</td>
  37. </tr>
  38. </tbody>
  39. </table>'
  40. try 'three-column table' \
  41. 'a|b|c
  42. -|-|-
  43. hello||sailor'\
  44. '<table>
  45. <thead>
  46. <tr>
  47. <th>a</th>
  48. <th>b</th>
  49. <th>c</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. <tr>
  54. <td>hello</td>
  55. <td></td>
  56. <td>sailor</td>
  57. </tr>
  58. </tbody>
  59. </table>'
  60. try 'two-column table with empty cells' \
  61. '
  62. a | b
  63. -----|------
  64. hello|
  65. |sailor' \
  66. '<table>
  67. <thead>
  68. <tr>
  69. <th>a </th>
  70. <th> b</th>
  71. </tr>
  72. </thead>
  73. <tbody>
  74. <tr>
  75. <td>hello</td>
  76. <td></td>
  77. </tr>
  78. <tr>
  79. <td></td>
  80. <td>sailor</td>
  81. </tr>
  82. </tbody>
  83. </table>'
  84. try 'two-column table with alignment' \
  85. '
  86. a | b
  87. ----:|:-----
  88. hello|sailor' \
  89. '<table>
  90. <thead>
  91. <tr>
  92. <th style="text-align:right;">a </th>
  93. <th style="text-align:left;"> b</th>
  94. </tr>
  95. </thead>
  96. <tbody>
  97. <tr>
  98. <td style="text-align:right;">hello</td>
  99. <td style="text-align:left;">sailor</td>
  100. </tr>
  101. </tbody>
  102. </table>'
  103. try 'table with extra data column' \
  104. '
  105. a | b
  106. -----|------
  107. hello|sailor|boy' \
  108. '<table>
  109. <thead>
  110. <tr>
  111. <th>a </th>
  112. <th> b</th>
  113. </tr>
  114. </thead>
  115. <tbody>
  116. <tr>
  117. <td>hello</td>
  118. <td>sailor|boy</td>
  119. </tr>
  120. </tbody>
  121. </table>'
  122. try -fnotables 'tables with -fnotables' \
  123. 'a|b
  124. -|-
  125. hello|sailor' \
  126. '<p>a|b
  127. -|-
  128. hello|sailor</p>'
  129. try 'deceptive non-table text' \
  130. 'a | b | c
  131. text' \
  132. '<p>a | b | c</p>
  133. <p>text</p>'
  134. try 'table headers only' \
  135. 'a|b|c
  136. -|-|-' \
  137. '<p>a|b|c
  138. -|-|-</p>'
  139. try 'escaped title line' \
  140. 'A\|B
  141. --|-
  142. C |D' \
  143. '<table>
  144. <thead>
  145. <tr>
  146. <th>A|B</th>
  147. </tr>
  148. </thead>
  149. <tbody>
  150. <tr>
  151. <td>C |D</td>
  152. </tr>
  153. </tbody>
  154. </table>'
  155. try 'escaped dashes line' \
  156. 'A |B
  157. -\|-
  158. C |D' \
  159. '<p>A |B
  160. -|-
  161. C |D</p>'
  162. try 'escaped content line' \
  163. 'A |B
  164. --|-
  165. C\|D' \
  166. '<table>
  167. <thead>
  168. <tr>
  169. <th>A </th>
  170. <th>B</th>
  171. </tr>
  172. </thead>
  173. <tbody>
  174. <tr>
  175. <td>C|D</td>
  176. <td></td>
  177. </tr>
  178. </tbody>
  179. </table>'
  180. try 'content line w/o dashes' \
  181. 'A |B
  182. --|-
  183. CD' \
  184. '<p>A |B
  185. &ndash;|-
  186. CD</p>'
  187. try 'table followed by text' \
  188. '
  189. A|B
  190. -|-
  191. C|D
  192. foo?' \
  193. '<table>
  194. <thead>
  195. <tr>
  196. <th>A</th>
  197. <th>B</th>
  198. </tr>
  199. </thead>
  200. <tbody>
  201. <tr>
  202. <td>C</td>
  203. <td>D</td>
  204. </tr>
  205. </tbody>
  206. </table>
  207. <p>foo?</p>'
  208. try "table with flanking |'s" \
  209. '
  210. |A|B|
  211. |-|-|
  212. |D|C|' \
  213. '<table>
  214. <thead>
  215. <tr>
  216. <th>A</th>
  217. <th>B</th>
  218. </tr>
  219. </thead>
  220. <tbody>
  221. <tr>
  222. <td>D</td>
  223. <td>C</td>
  224. </tr>
  225. </tbody>
  226. </table>'
  227. try "table with leading |'s and alignment" \
  228. '|AA|BB|CC
  229. |:-|::|-:
  230. |aa|bb|cc' \
  231. '<table>
  232. <thead>
  233. <tr>
  234. <th style="text-align:left;">AA</th>
  235. <th style="text-align:center;">BB</th>
  236. <th style="text-align:right;">CC</th>
  237. </tr>
  238. </thead>
  239. <tbody>
  240. <tr>
  241. <td style="text-align:left;">aa</td>
  242. <td style="text-align:center;">bb</td>
  243. <td style="text-align:right;">cc</td>
  244. </tr>
  245. </tbody>
  246. </table>'
  247. summary $0
  248. exit $rc