markdown-converter.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2018 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 utf8;
  19. use Test::More tests => 24;
  20. add_module('markdown-converter.pl');
  21. my $input = qq{
  22. # mu
  23. 1 * 2 * 3
  24. *foo*
  25. **bar**
  26. *foo bar*
  27. /baz/
  28. //quux//
  29. ##oort##
  30. [http://example.com/ example]
  31. {{{
  32. code
  33. }}}
  34. {{{also code}}}
  35. };
  36. update_page('test', $input);
  37. my $output = get_page('action=convert id=test');
  38. unlike $output, qr'<p>#MARKDOWN</p>', 'No Markdown marker in the HTML';
  39. like $output, qr'#MARKDOWN\n', 'Markdown marker';
  40. like $output, qr'1\. mu', 'list item';
  41. like $output, qr'1 \* 2 \* 3', 'lone asterisk';
  42. like $output, qr'\*\*foo\*\*', 'short strong emphasis';
  43. like $output, qr'\*\*bar\*\*', 'long strong emphasis';
  44. like $output, qr'\*\*foo bar\*\*', 'spaces ok';
  45. like $output, qr'\*baz\*', 'short emphasis';
  46. like $output, qr'\*quux\*', 'long emphasis';
  47. like $output, qr'`oort`', 'code';
  48. like $output, qr'\[example\]\(http://example.com/\)', 'link';
  49. like $output, qr'```\ncode\n```', 'fenced code';
  50. like $output, qr'`also code`', 'inline code';
  51. # Errors found and fixed at a later date
  52. $input = qq{
  53. /Toe’s Reach/
  54. {{{
  55. one
  56. }}}
  57. == heading
  58. {{{
  59. two
  60. }}}
  61. nothing but {{{#REDIRECT [[Rhysalis Eina]]}}}
  62. ##eins## und ##zwei##
  63. };
  64. update_page('test', $input);
  65. my $output = get_page('action=convert id=test');
  66. like $output, qr'\*Toe’s Reach\*', 'Toe’s Reach';
  67. like $output, qr'^```\none\n```$'m, 'code block one';
  68. like $output, qr'^```\none\n```$'m, 'code block two';
  69. like $output, qr'^## heading$'m, 'heading';
  70. like $output, qr'`#REDIRECT \[\[Rhysalis Eina\]\]`', 'inline code again';
  71. like $output, qr'`eins`', 'eins';
  72. like $output, qr'`zwei`', 'zwei';
  73. # check whether the candidates are listed correctly
  74. test_page(get_page('action=conversion-candidates'), 'test');
  75. # convert the file so it isn't listed anymore
  76. update_page('test', "#MARKDOWN\nhello\n");
  77. # add an image which cannot be converted
  78. AppendStringToFile($ConfigFile, "\$UploadAllowed = 1;\n");
  79. $page = update_page('pic', "#FILE image/png\niVBORw0KGgoAAAA");
  80. test_page($page, 'This page contains an uploaded file:');
  81. test_page_negative(get_page('action=conversion-candidates'), 'test', 'pic');