2010-04-02 01:28:02 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2011-02-09 19:11:14 +01:00
|
|
|
use Test::More tests => 24;
|
2010-04-02 01:28:02 +02:00
|
|
|
|
|
|
|
BEGIN { use_ok("IkiWiki"); }
|
2010-12-25 23:53:57 +01:00
|
|
|
BEGIN { use_ok("IkiWiki::Render"); }
|
|
|
|
BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
|
2010-04-02 01:28:02 +02:00
|
|
|
BEGIN { use_ok("IkiWiki::Plugin::tag"); }
|
|
|
|
|
|
|
|
ok(! system("rm -rf t/tmp; mkdir t/tmp"));
|
|
|
|
|
2010-12-25 23:53:57 +01:00
|
|
|
$config{srcdir} = 't/tmp';
|
|
|
|
$config{underlaydir} = 't/tmp';
|
|
|
|
$config{templatedir} = 'templates';
|
|
|
|
$config{usedirs} = 1;
|
|
|
|
$config{htmlext} = 'html';
|
|
|
|
$config{wiki_file_chars} = "-[:alnum:]+/.:_";
|
2010-04-02 01:28:02 +02:00
|
|
|
$config{userdir} = "users";
|
|
|
|
$config{tagbase} = "tags";
|
2010-12-25 23:53:57 +01:00
|
|
|
$config{tag_autocreate} = 1;
|
2011-01-07 21:11:19 +01:00
|
|
|
$config{tag_autocreate_commit} = 0;
|
2010-12-25 23:53:57 +01:00
|
|
|
$config{default_pageext} = "mdwn";
|
|
|
|
$config{wiki_file_prune_regexps} = [qr/^\./];
|
|
|
|
$config{underlaydirbase} = '.';
|
|
|
|
|
|
|
|
is(checkconfig(), 1);
|
2010-04-02 01:28:02 +02:00
|
|
|
|
|
|
|
%oldrenderedfiles=%pagectime=();
|
|
|
|
%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
|
|
|
|
%destsources=%renderedfiles=%pagecase=%pagestate=();
|
|
|
|
|
|
|
|
foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
|
|
|
|
$pagesources{$page} = "$page.mdwn";
|
|
|
|
$pagemtime{$page} = $pagectime{$page} = 1000000;
|
2010-12-25 23:53:57 +01:00
|
|
|
writefile("$page.mdwn", "t/tmp", "your ad here");
|
2010-04-02 01:28:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$links{one}=[qw(tags/numbers alpha tags/letters)];
|
|
|
|
$links{two}=[qw(tags/numbers)];
|
|
|
|
$links{alpha}=[qw(tags/letters one)];
|
|
|
|
$links{beta}=[qw(tags/letters)];
|
|
|
|
$typedlinks{one}={tag => {"tags/numbers" => 1 }};
|
|
|
|
$typedlinks{two}={tag => {"tags/numbers" => 1 }};
|
|
|
|
$typedlinks{alpha}={tag => {"tags/letters" => 1 }};
|
|
|
|
$typedlinks{beta}={tag => {"tags/letters" => 1 }};
|
|
|
|
|
|
|
|
ok(pagespec_match("one", "tagged(numbers)"));
|
|
|
|
ok(!pagespec_match("two", "tagged(alpha)"));
|
|
|
|
ok(pagespec_match("one", "link(tags/numbers)"));
|
|
|
|
ok(pagespec_match("one", "link(alpha)"));
|
|
|
|
|
2010-12-25 23:53:57 +01:00
|
|
|
# emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
|
|
|
|
# the "numbers" and "primes" tag pages to be auto-created
|
|
|
|
IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
|
|
|
|
is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
|
|
|
|
is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
|
|
|
|
is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
|
2010-12-28 14:39:26 +01:00
|
|
|
is_deeply([sort keys %autofiles], [qw(tags/lucky.mdwn tags/numbers.mdwn tags/primes.mdwn)]);
|
2010-12-25 23:53:57 +01:00
|
|
|
|
|
|
|
ok(!-e "t/tmp/tags/lucky.mdwn");
|
|
|
|
my (%pages, @del);
|
|
|
|
IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
|
2011-01-07 21:11:19 +01:00
|
|
|
ok(! -s "t/tmp/tags/lucky.mdwn");
|
|
|
|
ok(-s "t/tmp/.ikiwiki/transient/tags/lucky.mdwn");
|
2011-02-09 19:11:06 +01:00
|
|
|
is_deeply(\%pages, {"t/tmp/tags/lucky" => 1}) || diag explain \%pages;
|
|
|
|
is_deeply(\@del, []) || diag explain \@del;
|
2010-12-25 23:53:57 +01:00
|
|
|
|
|
|
|
# generating an autofile that already exists does nothing
|
|
|
|
%pages = @del = ();
|
|
|
|
IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
|
2011-01-24 22:23:58 +01:00
|
|
|
is_deeply(\%pages, {});
|
|
|
|
is_deeply(\@del, []);
|
2010-12-25 23:53:57 +01:00
|
|
|
|
|
|
|
# generating an autofile that we just deleted does nothing
|
|
|
|
%pages = ();
|
|
|
|
@del = ('tags/primes.mdwn');
|
|
|
|
IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
|
2011-01-24 22:23:58 +01:00
|
|
|
is_deeply(\%pages, {});
|
|
|
|
is_deeply(\@del, ['tags/primes.mdwn']);
|
2010-12-25 23:53:57 +01:00
|
|
|
|
2011-01-25 00:58:51 +01:00
|
|
|
|
|
|
|
# cleanup
|
|
|
|
ok(! system("rm -rf t/tmp"));
|
|
|
|
|
2010-04-02 01:28:02 +02:00
|
|
|
1;
|