6 use Test::More tests => 22;
8 BEGIN { use_ok("IkiWiki"); }
9 BEGIN { use_ok("IkiWiki::Render"); }
10 BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
11 BEGIN { use_ok("IkiWiki::Plugin::tag"); }
13 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
16 $config{srcdir} = 't/tmp';
17 $config{underlaydir} = 't/tmp';
18 $config{templatedir} = 'templates';
20 $config{htmlext} = 'html';
21 $config{wiki_file_chars} = "-[:alnum:]+/.:_";
22 $config{userdir} = "users";
23 $config{tagbase} = "tags";
24 $config{tag_autocreate} = 1;
25 $config{default_pageext} = "mdwn";
26 $config{wiki_file_prune_regexps} = [qr/^\./];
27 $config{underlaydirbase} = '.';
31 %oldrenderedfiles=%pagectime=();
32 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
33 %destsources=%renderedfiles=%pagecase=%pagestate=();
35 foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
36 $pagesources{$page} = "$page.mdwn";
37 $pagemtime{$page} = $pagectime{$page} = 1000000;
38 writefile("$page.mdwn", "t/tmp", "your ad here");
41 $links{one}=[qw(tags/numbers alpha tags/letters)];
42 $links{two}=[qw(tags/numbers)];
43 $links{alpha}=[qw(tags/letters one)];
44 $links{beta}=[qw(tags/letters)];
45 $typedlinks{one}={tag => {"tags/numbers" => 1 }};
46 $typedlinks{two}={tag => {"tags/numbers" => 1 }};
47 $typedlinks{alpha}={tag => {"tags/letters" => 1 }};
48 $typedlinks{beta}={tag => {"tags/letters" => 1 }};
50 ok(pagespec_match("one", "tagged(numbers)"));
51 ok(!pagespec_match("two", "tagged(alpha)"));
52 ok(pagespec_match("one", "link(tags/numbers)"));
53 ok(pagespec_match("one", "link(alpha)"));
55 # emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
56 # the "numbers" and "primes" tag pages to be auto-created
57 IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
58 is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
59 is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
60 is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
61 is_deeply([sort keys %autofiles], [qw(tags/lucky.mdwn tags/numbers.mdwn tags/primes.mdwn)]);
63 ok(!-e "t/tmp/tags/lucky.mdwn");
65 IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
66 is_deeply(\%pages, {"t/tmp/tags/lucky" => 1});
68 ok(-s "t/tmp/tags/lucky.mdwn");
70 # generating an autofile that already exists does nothing
72 IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
73 is_deeply(\%pages, {});
76 # generating an autofile that we just deleted does nothing
78 @del = ('tags/primes.mdwn');
79 IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
80 is_deeply(\%pages, {});
81 is_deeply(\@del, ['tags/primes.mdwn']);
85 ok(! system("rm -rf t/tmp"));