markdown-rule.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2014–2019 Alex Schroeder <alex@gnu.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. require './t/test.pl';
  17. package OddMuse;
  18. use Test::More tests => 68;
  19. add_module('markdown-rule.pl');
  20. add_module('bbcode.pl');
  21. # ApplyRules strips trailing newlines, so write tests accordingly.
  22. run_tests(split(/\n/,<<'EOT'));
  23. 1. one
  24. <ol><li>one</li></ol>
  25. 2. one
  26. 2. one
  27. 1. one\n2. two
  28. <ol><li>one</li><li>two</li></ol>
  29. 1. one\n\n2. two
  30. <ol><li>one</li><li>two</li></ol>
  31. 1. one\n 2. two\n 3. three
  32. <ol><li>one<ol><li>two</li><li>three</li></ol></li></ol>
  33. 1. one\n\n 2. two\n\n 3. three
  34. <ol><li>one<ol><li>two</li><li>three</li></ol></li></ol>
  35. - one
  36. <ul><li>one</li></ul>
  37. - one\n-- Alex
  38. <ul><li>one -- Alex</li></ul>
  39. - one\n\n- Alex
  40. <ul><li>one</li><li>Alex</li></ul>
  41. * one\n * two
  42. <ul><li>one<ul><li>two</li></ul></li></ul>
  43. * one\n * two\n* three
  44. <ul><li>one<ul><li>two</li></ul></li><li>three</li></ul>
  45. 1. one\n- two
  46. <ol><li>one</li></ol><ul><li>two</li></ul>
  47. this is ***bold italic*** yo!
  48. this is <em><strong>bold italic</strong></em> yo!
  49. this is **bold**
  50. this is <strong>bold</strong>
  51. **bold**
  52. <strong>bold</strong>
  53. *italic*
  54. <em>italic</em>
  55. *italic* less.
  56. <em>italic</em> less.
  57. *italic.* more.
  58. <em>italic.</em> more.
  59. __underline__
  60. <em style="font-style: normal; text-decoration: underline">underline</em>
  61. _underline_
  62. <em style="font-style: normal; text-decoration: underline">underline</em>
  63. _italic._ more.
  64. <em style="font-style: normal; text-decoration: underline">italic.</em> more.
  65. //italic//
  66. <em>italic</em>
  67. /italic/
  68. <em>italic</em>
  69. /italic./ more.
  70. <em>italic.</em> more.
  71. foo\nbar
  72. foo bar
  73. foo\n===\nbar
  74. <h2>foo</h2><p>bar</p>
  75. foo\n---\nbar
  76. <h3>foo</h3><p>bar</p>
  77. foo\n=== bar
  78. foo === bar
  79. foo\n=\nbar
  80. <h2>foo</h2><p>bar</p>
  81. # foo
  82. <h1>foo</h1>
  83. ## foo
  84. <h2>foo</h2>
  85. ### foo
  86. <h3>foo</h3>
  87. #### foo
  88. <h4>foo</h4>
  89. ##### foo
  90. <h5>foo</h5>
  91. ###### foo
  92. <h6>foo</h6>
  93. ####### foo
  94. <h6># foo</h6>
  95. ## foo ##
  96. <h2>foo ##</h2>
  97. bar\n##foo\nbar
  98. bar <h2>foo</h2><p>bar</p>
  99. this is #foo tag
  100. this is #foo tag
  101. ```\nfoo\n```\nbar
  102. <pre>foo</pre><p>bar</p>
  103. ```\nfoo\n```
  104. <pre>foo</pre>
  105. ```\nfoo\n``` bar
  106. ``` foo ``` bar
  107. `bar`
  108. <code>bar</code>
  109. """\n*foo*\n"""\nhallo
  110. <blockquote><p><em>foo</em></p></blockquote><p>hallo</p>
  111. > *foo*\nhallo
  112. <blockquote><p><em>foo</em></p></blockquote><p>hallo</p>
  113. |a|b|\n|c|d|\nbar
  114. <table><tr><th>a</th><th>b</th></tr><tr><td>c</td><td>d</td></tr></table><p>bar</p>
  115. |a|b|\n|c|d|
  116. <table><tr><th>a</th><th>b</th></tr><tr><td>c</td><td>d</td></tr></table>
  117. |a
  118. <table><tr><th>a</th></tr></table>
  119. |*foo*
  120. <table><tr><th><em>foo</em></th></tr></table>
  121. |/foo/
  122. <table><tr><th><em>foo</em></th></tr></table>
  123. |_foo_
  124. <table><tr><th><em style="font-style: normal; text-decoration: underline">foo</em></th></tr></table>
  125. | a| b|\n| c| d|
  126. <table><tr><th style="text-align: right">a</th><th style="text-align: right">b</th></tr><tr><td style="text-align: right">c</td><td style="text-align: right">d</td></tr></table>
  127. | a | b |\n| c | d |
  128. <table><tr><th style="text-align: center">a</th><th style="text-align: center">b</th></tr><tr><td style="text-align: center">c</td><td style="text-align: center">d</td></tr></table>
  129. foo ~~bar~~
  130. foo <del>bar</del>
  131. pay 1.-/month
  132. pay 1.-/month
  133. EOT
  134. xpath_run_tests(split(/\n/,<<'EOT'));
  135. [example](http://example.com/)
  136. //a[@class="url"][@href="http://example.com/"][text()="example"]
  137. [an example](http://example.com/)
  138. //a[@class="url"][@href="http://example.com/"][text()="an example"]
  139. [an example](http://example.com/ "Title")
  140. //a[@class="url"][@href="http://example.com/"][@title="Title"][text()="an example"]
  141. [an\nexample](http://example.com/)
  142. //a[@class="url"][@href="http://example.com/"][text()="an\nexample"]
  143. \n[an\n\nexample](http://example.com/)
  144. //p[text()="[an"]/following-sibling::p//text()[contains(string(),"example](")]
  145. EOT
  146. # test the quote again, writing an actual page
  147. test_page(update_page('cache', qq{"""\n*foo*\n"""\nhallo}),
  148. '<blockquote><p><em>foo</em></p></blockquote><p>hallo</p>');
  149. # test the page again to find errors in dirty block marking
  150. test_page(get_page('cache'),
  151. '<blockquote><p><em>foo</em></p></blockquote><p>hallo</p>');
  152. # test the other quote again, writing an actual page
  153. test_page(update_page('cache', qq{> *foo*\n> bar\nhallo}),
  154. '<blockquote><p><em>foo</em> bar</p></blockquote><p>hallo</p>');
  155. # test the page again to find errors in dirty block marking
  156. test_page(get_page('cache'),
  157. '<blockquote><p><em>foo</em> bar</p></blockquote><p>hallo</p>');
  158. @MyRules = grep { $_ ne \&MarkdownExtraRule } @MyRules;
  159. run_tests(split(/\n/,<<'EOT'));
  160. __underline__
  161. __underline__
  162. _underline_
  163. _underline_
  164. //italic//
  165. //italic//
  166. /italic/
  167. /italic/
  168. EOT