portrait-support.t 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env perl
  2. # Copyright (C) 2006, 2007 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 => 18;
  19. add_module('portrait-support.pl');
  20. # nothing
  21. update_page('headers', "[new]foo\n== no header ==\n\ntext\n");
  22. test_page(get_page('headers'),
  23. '<div class="color one level0"><p>foo == no header ==</p><p>text</p></div>');
  24. # usemod only
  25. add_module('usemod.pl');
  26. update_page('headers', "[new]foo\n== is header ==\n\ntext\n");
  27. test_page(get_page('headers'), '<div class="color one level0"><p>foo </p></div><h2>is header</h2>');
  28. # usemod + toc only
  29. add_module('toc.pl');
  30. test_page(update_page('headers', "[new]foo\n== one ==\ntext\n== two ==\ntext\n== three ==\ntext\n"),
  31. # default to before the header
  32. '<div class="content browse" lang="en"><div class="color one level0"><p>foo </p></div>',
  33. '<div class="toc"><h2>Contents</h2><ol>',
  34. qq{<li><a href="#${TocAnchorPrefix}1">one</a></li>},
  35. qq{<li><a href="#${TocAnchorPrefix}2">two</a></li>},
  36. qq{<li><a href="#${TocAnchorPrefix}3">three</a></li></ol></div>},
  37. qq{<h2 id="${TocAnchorPrefix}1">one</h2><p>text </p>},
  38. qq{<h2 id="${TocAnchorPrefix}2">two</h2>}, );
  39. remove_module('toc.pl');
  40. # The next two are necessary so that toc.pl can be reloaded safely later!
  41. *ApplyRules = \&OldTocApplyRules;
  42. *RunMyRules = \&RunMyRulesTocOld;
  43. remove_rule(\&TocRule);
  44. remove_module('usemod.pl');
  45. remove_rule(\&UsemodRule);
  46. # headers only
  47. add_module('headers.pl');
  48. update_page('headers', "[new]foo\nis header\n=========\n\ntext\n");
  49. test_page(get_page('headers'), '<div class="color one level0"><p>foo </p></div><h2>is header</h2>');
  50. remove_module('headers.pl');
  51. remove_rule(\&HeadersRule);
  52. # portrait-support, toc, and usemod
  53. add_module('usemod.pl');
  54. add_module('toc.pl');
  55. test_page(update_page('headers', "[new]foo\n== one ==\ntext\n== two ==\ntext\n== three ==\ntext\n"),
  56. qq{<li><a href="#${TocAnchorPrefix}1">one</a></li>},
  57. qq{<li><a href="#${TocAnchorPrefix}2">two</a></li>},
  58. '<div class="color one level0"><p>foo </p></div>',
  59. qq{<h2 id="${TocAnchorPrefix}1">one</h2>},
  60. qq{<h2 id="${TocAnchorPrefix}2">two</h2>}, );
  61. run_tests(split('\n',<<'EOT'));
  62. [new]\nfoo
  63. <div class="color one level0"><p> foo</p></div>
  64. :[new]\nfoo
  65. <div class="color two level1"><p> foo</p></div>
  66. ::[new]\nfoo
  67. <div class="color one level2"><p> foo</p></div>
  68. EOT