creole.t 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2006-2014 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 => 111;
  19. add_module('creole.pl');
  20. # Permit testing of dash-style list markup.
  21. $CreoleDashStyleUnorderedLists = 1;
  22. $WikiLinks = 1;
  23. run_tests(split('\n',<<'EOT'));
  24. # one
  25. <ol><li>one</li></ol>
  26. # one
  27. <ol><li>one</li></ol>
  28. # one
  29. <ol><li>one</li></ol>
  30. # one\n# two
  31. <ol><li>one</li><li>two</li></ol>
  32. # one\n\n# two
  33. <ol><li>one</li><li>two</li></ol>
  34. * one
  35. <ul><li>one</li></ul>
  36. * one\n** two\n*** three\n* four
  37. <ul><li>one<ul><li>two<ul><li>three</li></ul></li></ul></li><li>four</li></ul>
  38. * one\n ** two\n *** three\n * four
  39. <ul><li>one<ul><li>two<ul><li>three</li></ul></li></ul></li><li>four</li></ul>
  40. - one
  41. <ul><li>one</li></ul>
  42. - one\n-- Alex
  43. <ul><li>one -- Alex</li></ul>
  44. - one\n\n-- Alex
  45. <ul><li>one</li></ul><p>-- Alex</p>
  46. this is **bold**
  47. this is <strong>bold</strong>
  48. **bold**
  49. <strong>bold</strong>
  50. *item\n**item**
  51. <ul><li>item <strong>item</strong></li></ul>
  52. *item\n\n**item**
  53. <ul><li>item</li></ul><p><strong>item</strong></p>
  54. *item\n** **item**
  55. <ul><li>item<ul><li><strong>item</strong></li></ul></li></ul>
  56. *item\n* **item**
  57. <ul><li>item</li><li><strong>item</strong></li></ul>
  58. //italic//
  59. <em>italic</em>
  60. this is **//bold italic**//italic
  61. this is <strong><em>bold italic</em></strong><em>italic</em>
  62. //**bold italic//**bold
  63. <em><strong>bold italic</strong></em><strong>bold</strong>
  64. = foo
  65. <h1>foo</h1>
  66. == foo
  67. <h2>foo</h2>
  68. === foo
  69. <h3>foo</h3>
  70. ==== foo
  71. <h4>foo</h4>
  72. ===== foo
  73. <h5>foo</h5>
  74. ====== foo
  75. <h6>foo</h6>
  76. ======= foo
  77. <h6 class="h7">foo</h6>
  78. == foo ==
  79. <h2>foo </h2>
  80. ========= h9 ======
  81. <h6 class="h9">h9</h6>
  82. == foo = =
  83. <h2>foo =</h2>
  84. == foo\nbar
  85. <h2>foo</h2><p>bar</p>
  86. foo\n\nbar
  87. foo<p>bar</p>
  88. foo\nbar
  89. foo bar
  90. {{{\nfoo\n}}}
  91. <pre class="real">foo</pre>
  92. {{{\nfoo\n}}} bar
  93. {{{ foo }}} bar
  94. {{{\nfoo\n}}} bar \n}}}\n
  95. <pre class="real">foo\n}}} bar </pre>
  96. {{{\nfoo\n}}} bar\n{{{\nfoobar\n}}}
  97. <pre class="real">foo\n}}} bar\n{{{\nfoobar</pre>
  98. {{{\nfoo\n}}}\n
  99. <pre class="real">foo</pre>
  100. {{{foo}}} bar {{{\nbaz\n}}}
  101. <code>foo</code> bar {{{ baz }}}
  102. {{{\nfoo\n}}}\n{{{\nbar\n}}}
  103. <pre class="real">foo</pre><pre class="real">bar</pre>
  104. {{{foo}}}}}}
  105. <code>foo}}}</code>
  106. foo {{{bar}}}
  107. foo <code>bar</code>
  108. foo {{{bar}}} and {{{baz}}}
  109. foo <code>bar</code> and <code>baz</code>
  110. foo {{{{bar}}}}
  111. foo <code>{bar}</code>
  112. foo {{{*bar*}}}
  113. foo <code>*bar*</code>
  114. {{{[[http://example.org|example]]}}}
  115. <code>[[http://example.org|example]]</code>
  116. ----
  117. <hr />
  118. -----
  119. -----
  120. foo -----
  121. foo -----
  122. ----\nfoo
  123. <hr /><p>foo</p>
  124. foo\n----
  125. foo <hr />
  126. |a|
  127. <table class="user"><tr><td>a</td></tr></table>
  128. |a
  129. <table class="user"><tr><td>a</td></tr></table>
  130. |a|b|\n|c|d
  131. <table class="user"><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>
  132. |a|b\nc|d
  133. <table class="user"><tr><td>a</td><td>b c</td><td>d</td></tr></table>
  134. |a\\b|\n|c\n\nd|
  135. <table class="user"><tr><td>a<br />b</td></tr><tr><td>c</td></tr></table><p>d|</p>
  136. |a|b|c\n|d|e|\nf|
  137. <table class="user"><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>d</td><td>e</td></tr></table><p>f|</p>
  138. |a|b|c|\n|d|e|f
  139. <table class="user"><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>d</td><td>e</td><td>f</td></tr></table>
  140. |=a|=b|=c|\n|d|e|f|
  141. <table class="user"><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>d</td><td>e</td><td>f</td></tr></table>
  142. |=a|b|c|\n|=d|e|f|
  143. <table class="user"><tr><th>a</th><td>b</td><td>c</td></tr><tr><th>d</th><td>e</td><td>f</td></tr></table>
  144. | a| b| c\n| d | e | f |
  145. <table class="user"><tr><td align="right">a</td><td align="right">b</td><td align="right">c</td></tr><tr><td align="center">d </td><td align="center">e </td><td align="center">f </td></tr></table>
  146. |a||c\n||e|f|
  147. <table class="user"><tr><td>a</td><td colspan="2">c</td></tr><tr><td colspan="2">e</td><td>f</td></tr></table>
  148. ~#1
  149. #1
  150. ~http://www.foo.com/
  151. http://www.foo.com/
  152. ~CamelCaseLink
  153. CamelCaseLink
  154. ~ does not escape whitespace
  155. ~ does not escape whitespace
  156. foo ~bar
  157. foo bar
  158. | 1|foo |
  159. <table class="user"><tr><td align="right">1</td><td>foo </td></tr></table>
  160. EOT
  161. xpath_run_tests(split('\n',<<'EOT'));
  162. == [[http://foo.org]]
  163. //h2/a[@class="url http outside"][@href="http://foo.org"][text()="http://foo.org"]
  164. EOT
  165. $CreoleTildeAlternative = 1;
  166. # subtle differences
  167. run_tests(split('\n',<<'EOT'));
  168. ~#1
  169. #1
  170. ~http://www.foo.com/
  171. http://www.foo.com/
  172. ~CamelCaseLink
  173. ~CamelCaseLink
  174. ~ does not escape whitespace
  175. ~ does not escape whitespace
  176. foo ~bar
  177. foo ~bar
  178. EOT
  179. $CreoleLineBreaks = 1;
  180. run_tests(split('\n',<<'EOT'));
  181. foo\nbar
  182. foo<br />bar
  183. * foo\n* bar
  184. <ul><li>foo</li><li>bar</li></ul>
  185. foo\\\nbar
  186. foo<br />bar
  187. EOT
  188. # Mixed lists are not supported
  189. # - Item 1\n- Item 2\n## Item 2.1\n## Item 2.2
  190. # <ul><li>Item 1</li><li>Item 2<ol><li>Item 2.1</li><li>Item 2.2</li></ol></li></ul>
  191. update_page('InterMap', " Ohana http://www.wikiohana.org/\n", 0, 0, 1);
  192. update_page('link', 'test');
  193. update_page('pic', 'test');
  194. ReInit();
  195. xpath_run_tests(split('\n',<<'EOT'));
  196. [[http://www.wikicreole.org/]]
  197. //a[@class="url http outside"][@href="http://www.wikicreole.org/"][text()="http://www.wikicreole.org/"]
  198. http://www.wikicreole.org/
  199. //a[@class="url http"][@href="http://www.wikicreole.org/"][text()="http://www.wikicreole.org/"]
  200. http://www.wikicreole.org/.
  201. //a[@class="url http"][@href="http://www.wikicreole.org/"][text()="http://www.wikicreole.org/"]
  202. [[http://www.wikicreole.org/|Visit the **WikiCreole** website]]
  203. //a[@class="url http outside"][@href="http://www.wikicreole.org/"][text()="Visit the "][strong[text()="WikiCreole"]][text()=" website"]
  204. [[http://www.wikicreole.org/|//Visit the\nWikiCreole website//]]
  205. //a[@class="url http outside"][@href="http://www.wikicreole.org/"][em[text()="Visit the WikiCreole website"]]
  206. [[http://www.wikicreole.org/ | Visit the WikiCreole website]]
  207. //a[@class="url http outside"][@href="http://www.wikicreole.org/"][text()="Visit the WikiCreole website"]
  208. [[foo bar]]
  209. //div[text()[.="[[foo_bar"]/following-sibling::a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/test.pl?action=edit;id=foo_bar"][text()="?"]/following-sibling::text()[.="]]"]]
  210. [[foo_bar]]
  211. //div[text()[.="[[foo_bar"]/following-sibling::a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/test.pl?action=edit;id=foo_bar"][text()="?"]/following-sibling::text()[.="]]"]]
  212. [[foo bar|text]]
  213. //div[text()[.="[[foo_bar"]/following-sibling::a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/test.pl?action=edit;id=foo_bar"][text()="?"]/following-sibling::text()[.="|text]]"]]
  214. [[link]]
  215. //a[text()="link"]
  216. [[link|Go to my page]]
  217. //a[@class="local"][@href="http://localhost/test.pl/link"][text()="Go to my page"]
  218. [[link|Go to\nmy page]]
  219. //a[@class="local"][@href="http://localhost/test.pl/link"][text()="Go to my page"]
  220. {{pic}}
  221. //a[@class="image"][@href="http://localhost/test.pl/pic"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="pic"]]
  222. [[link|{{pic}}]]
  223. //a[@class="image"][@href="http://localhost/test.pl/link"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="link"]]
  224. [[link|{{http://example.com/}}]]
  225. //a[@class="image"][@href="http://localhost/test.pl/link"][img[@class="url outside"][@src="http://example.com/"][@alt="link"]]
  226. [[http://example.com/|{{pic}}]]
  227. //a[@class="image outside"][@href="http://example.com/"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="http://example.com/"]]
  228. {{http://example.com/}}
  229. //a[@class="image outside"][@href="http://example.com/"][img[@class="url outside"][@src="http://example.com/"]]
  230. [[http://example.com/|{{http://mu.org/}}]]
  231. //a[@class="image outside"][@href="http://example.com/"][img[@class="url outside"][@src="http://mu.org/"]]
  232. {{pic|a description}}
  233. //a[@class="image"][@href="http://localhost/test.pl/pic"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="a description"]]
  234. [[link|{{pic|a description}}]]
  235. //a[@class="image"][@href="http://localhost/test.pl/link"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="a description"]]
  236. [[link|{{http://example.com/|a description}}]]
  237. //a[@class="image"][@href="http://localhost/test.pl/link"][img[@class="url outside"][@src="http://example.com/"][@alt="a description"]]
  238. [[http://example.com/|{{pic|a description}}]]
  239. //a[@class="image outside"][@href="http://example.com/"][img[@class="upload"][@src="http://localhost/test.pl/download/pic"][@alt="a description"]]
  240. {{http://example.com/|a description}}
  241. //a[@class="image outside"][@href="http://example.com/"][img[@class="url outside"][@src="http://example.com/"][@alt="a description"]]
  242. [[http://example.com/|{{http://mu.org/|a description}}]]
  243. //a[@class="image outside"][@href="http://example.com/"][img[@class="url outside"][@src="http://mu.org/"][@alt="a description"]]
  244. [[Ohana:WikiFamily]]
  245. //div/child::node()[1]/self::a[@class="inter Ohana"][@href="http://www.wikiohana.org/WikiFamily"]/span[@class="site"][text()="Ohana"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="page"][text()="WikiFamily"]
  246. |[[http://www.wikicreole.org/|Visit the WikiCreole website]]
  247. //table[@class="user"]/tr/td/a[@class="url http outside"][@href="http://www.wikicreole.org/"][text()="Visit the WikiCreole website"]
  248. |[[http://www.wikicreole.org/| Visit the WikiCreole website]]
  249. //table[@class="user"]/tr/td/a[@class="url http outside"][@href="http://www.wikicreole.org/"][text()="Visit the WikiCreole website"]
  250. http://www.foo.com/~bar/
  251. //a[@class="url http"][@href="http://www.foo.com/~bar/"][text()="http://www.foo.com/~bar/"]
  252. InterMap
  253. //a[@class="local"][@href="http://localhost/test.pl/InterMap"][text()="InterMap"]
  254. EOT
  255. xpath_test(update_page('test','{{pic}}'),
  256. '//a[@class="image"][@href="http://localhost/wiki.pl/pic"][img[@class="upload"][@src="http://localhost/wiki.pl/download/pic"][@alt="pic"]]');
  257. # Make sure not problem exists with caching
  258. $page = get_page('test');
  259. xpath_test($page,
  260. '//a[@class="image"][@href="http://localhost/wiki.pl/pic"][img[@class="upload"][@src="http://localhost/wiki.pl/download/pic"][@alt="pic"]]');
  261. negative_xpath_test($page,
  262. '//a[@class="image"]/following-sibling::a[@class="image"]');
  263. xpath_test(update_page('source', 'this is a [[link]].'),
  264. '//a[text()="link"]');
  265. negative_xpath_test(get_page('source'),
  266. '//a[text()="link"]/following-sibling::a[text()="link"]');