]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/toc.t
Submit branch for review.
[git.ikiwiki.info.git] / t / toc.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use Encode;
7 BEGIN { use_ok("IkiWiki"); }
8 BEGIN { use_ok("IkiWiki::Render"); }
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
12 $config{add_plugins}=[qw(toc)];
14 my $installed = $ENV{INSTALLED_TESTS};
16 unless ($installed) {
17         $config{templatedir} = "templates";
18         $config{underlaydir} = "underlays/basewiki";
19         $config{underlaydirbase} = "underlays";
20 }
22 IkiWiki::loadplugins();
23 IkiWiki::checkconfig();
25 sub render {
26         my $content = shift;
27         $IkiWiki::pagesources{foo} = "foo.mdwn";
28         $IkiWiki::pagemtime{foo} = 42;
29         $IkiWiki::pagectime{foo} = 42;
30         $content = IkiWiki::filter("foo", "foo", $content);
31         $content = IkiWiki::preprocess("foo", "foo", $content);
32         $content = IkiWiki::linkify("foo", "foo", $content);
33         $content = IkiWiki::htmlize("foo", "foo", "mdwn", $content);
34         $content = IkiWiki::genpage("foo", $content);
35         return $content;
36 }
38 # https://ikiwiki.info/todo/toc-with-human-readable-anchors/
39 # (toc-recycle-id part)
40 like(render('[[!toc ]]
41 ## Weasels
43 These mustelids are weasilly recognised
45 <h2 id="the-chapter-on-stoats">Stoats</h2>
47 These are stoatally different
48 '),
49         qr{(?s)<a href="\#index1h2">.*<a href="\#the-chapter-on-stoats">});
51 done_testing();