aboutsummaryrefslogtreecommitdiff
path: root/t/toc.t
blob: dc737764797103e9dd47a79f2af7c6f0f0ac421b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;
use Encode;

BEGIN { use_ok("IkiWiki"); }
BEGIN { use_ok("IkiWiki::Render"); }

%config=IkiWiki::defaultconfig();
$config{srcdir}=$config{destdir}="/dev/null";
$config{add_plugins}=[qw(toc)];

my $installed = $ENV{INSTALLED_TESTS};

unless ($installed) {
	$config{templatedir} = "templates";
	$config{underlaydir} = "underlays/basewiki";
	$config{underlaydirbase} = "underlays";
}

IkiWiki::loadplugins();
IkiWiki::checkconfig();

sub render {
	my $content = shift;
	$IkiWiki::pagesources{foo} = "foo.mdwn";
	$IkiWiki::pagemtime{foo} = 42;
	$IkiWiki::pagectime{foo} = 42;
	$content = IkiWiki::filter("foo", "foo", $content);
	$content = IkiWiki::preprocess("foo", "foo", $content);
	$content = IkiWiki::linkify("foo", "foo", $content);
	$content = IkiWiki::htmlize("foo", "foo", "mdwn", $content);
	$content = IkiWiki::genpage("foo", $content);
	return $content;
}

# https://ikiwiki.info/todo/toc-with-human-readable-anchors/
# (toc-recycle-id part)
like(render('[[!toc ]]
## Weasels

These mustelids are weasilly recognised

<h2 id="the-chapter-on-stoats">Stoats</h2>

These are stoatally different
'),
	qr{(?s)<a href="\#index1h2">.*<a href="\#the-chapter-on-stoats">});

done_testing();