toc.t 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2006–2015 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 => 30;
  19. use utf8;
  20. add_module('toc.pl');
  21. add_module('usemod.pl');
  22. InitVariables(); # do this after loading usemod.pl!
  23. # Note that we're not calling TocInit between tests, so we rely on
  24. # them being run in order.
  25. run_tests('== make honey ==\n\nMoo.\n',
  26. qq{<h2 id="${TocAnchorPrefix}1">make honey</h2><p>Moo.</p>},
  27. '== make honey ==\nMoo.\n== make honey ==\nMoo.\n',
  28. qq{<h2 id="${TocAnchorPrefix}2">make honey</h2><p>Moo. </p><h2 id="${TocAnchorPrefix}3">make honey</h2><p>Moo.</p>},
  29. );
  30. test_page(update_page('toc', "bla\n"
  31. . "<toc/fnord/mu>\n"
  32. . "murks\n"
  33. . "==two=\n"
  34. . "bla\n"
  35. . "===three==\n"
  36. . "bla\n"
  37. . "=one=\n"),
  38. quotemeta('<div class="toc fnord mu">'));
  39. # check whether the toc remains in the HTML cache
  40. test_page(get_page('toc'),
  41. quotemeta('<div class="toc fnord mu">'));
  42. # no cache
  43. test_page(get_page('action=browse id=toc cache=0'),
  44. quotemeta('<div class="toc fnord mu">'));
  45. # check again!
  46. test_page(get_page('toc'),
  47. quotemeta('<div class="toc fnord mu">'));
  48. # details of the toc
  49. test_page(update_page('toc', "bla\n"
  50. . "=one=\n"
  51. . "blarg\n"
  52. . "==two==\n"
  53. . "bla\n"
  54. . "==two==\n"
  55. . "mu."),
  56. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li><li><a href="#${TocAnchorPrefix}3">two</a></li></ol>}),
  57. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
  58. quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}),
  59. quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2><ol><li><a }),
  60. quotemeta(qq{two</a></li></ol></div><h2 id="${TocAnchorPrefix}1">one</h2>}));
  61. test_page(update_page('toc', "bla\n"
  62. . "==two=\n"
  63. . "bla\n"
  64. . "===three==\n"
  65. . "bla\n"
  66. . "==two==\n"),
  67. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">two</a></li></ol>}),
  68. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  69. quotemeta(qq{<h3 id="${TocAnchorPrefix}2">three</h3>}));
  70. test_page(update_page('toc', "bla\n"
  71. . "<toc>\n"
  72. . "murks\n"
  73. . "==two=\n"
  74. . "bla\n"
  75. . "===three==\n"
  76. . "bla\n"
  77. . "=one=\n"),
  78. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">two</a><ol><li><a href="#${TocAnchorPrefix}2">three</a></li></ol></li><li><a href="#${TocAnchorPrefix}3">one</a></li></ol>}),
  79. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">two</h2>}),
  80. quotemeta(qq{<h2 id="${TocAnchorPrefix}3">one</h2>}),
  81. quotemeta(qq{bla </p><div class="toc"><h2>$TocHeaderText</h2><ol><li><a }),
  82. quotemeta('one</a></li></ol></div><p>murks'));
  83. test_page(update_page('toc', "bla\n"
  84. . "=one=\n"
  85. . "blarg\n"
  86. . "==two==\n"
  87. . "<nowiki>bla\n"
  88. . "==two==\n"
  89. . "mu.</nowiki>\n"
  90. . "<nowiki>bla\n"
  91. . "==two==\n"
  92. . "mu.</nowiki>\n"
  93. . "yadda <code>bla\n"
  94. . "==two==\n"
  95. . "mu.</code>\n"
  96. . "yadda <pre> has no effect! \n"
  97. . "##bla\n"
  98. . "==three==\n"
  99. . "mu.##\n"
  100. . "=one=\n"
  101. . "blarg </pre>\n"),
  102. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li><li><a href="#${TocAnchorPrefix}3">three</a></li><li><a href="#${TocAnchorPrefix}4">one</a></li></ol>}),
  103. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
  104. quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}),
  105. quotemeta(qq{<h2 id="${TocAnchorPrefix}3">three</h2>}),
  106. quotemeta(qq{<h2 id="${TocAnchorPrefix}4">one</h2>}));
  107. add_module('markup.pl');
  108. test_page(update_page('toc', "bla\n"
  109. . "=one=\n"
  110. . "blarg\n"
  111. . "<code>##bla\n"
  112. . "=two=\n"
  113. . "mu.</code>\n"
  114. . "##bla\n"
  115. . "=three=\n"
  116. . "mu.##\n"
  117. . "=four=\n"
  118. . "blarg\n"),
  119. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">four</a></li></ol>}),
  120. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
  121. quotemeta(qq{<h2 id="${TocAnchorPrefix}2">four</h2>}));
  122. test_page(update_page('toc', "bla\n"
  123. . "=one=\n"
  124. . "blarg ##<code>## and <code>##</code>\n"
  125. . "=two=\n"
  126. . "blarg ##</code>##\n"),
  127. quotemeta(qq{<ol><li><a href="#${TocAnchorPrefix}1">one</a></li><li><a href="#${TocAnchorPrefix}2">two</a></li></ol>}),
  128. quotemeta(qq{<h2 id="${TocAnchorPrefix}1">one</h2>}),
  129. quotemeta(qq{<h2 id="${TocAnchorPrefix}2">two</h2>}));