aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2010-04-02 00:28:02 +0100
committerSimon McVittie <smcv@debian.org>2010-04-04 00:43:48 +0100
commitc1a42e76bc6667bfb2882a12d53c25d9f952ca82 (patch)
treef540ca41ab5668dd417c4df17b64af2aa0ee83e0 /t
parent05b6e8ceee2bec4442727e2475abf8a8861d5e0a (diff)
downloadikiwiki-c1a42e76bc6667bfb2882a12d53c25d9f952ca82.tar
ikiwiki-c1a42e76bc6667bfb2882a12d53c25d9f952ca82.tar.gz
implement typed links; add tagged_is_strict config option
Diffstat (limited to 't')
-rwxr-xr-xt/index.t17
-rwxr-xr-xt/tag.t45
2 files changed, 59 insertions, 3 deletions
diff --git a/t/index.t b/t/index.t
index 2f23524a7..44273059d 100755
--- a/t/index.t
+++ b/t/index.t
@@ -4,7 +4,7 @@ use strict;
use IkiWiki;
package IkiWiki; # use internal variables
-use Test::More tests => 27;
+use Test::More tests => 31;
$config{wikistatedir}="/tmp/ikiwiki-test.$$";
system "rm -rf $config{wikistatedir}";
@@ -31,6 +31,7 @@ $renderedfiles{"bar"}=["bar.html", "bar.rss", "sparkline-foo.gif"];
$renderedfiles{"bar.png"}=["bar.png"];
$links{"Foo"}=["bar.png"];
$links{"bar"}=["Foo", "new-page"];
+$typedlinks{"bar"}={tag => {"Foo" => 1}};
$links{"bar.png"}=[];
$depends{"Foo"}={};
$depends{"bar"}={"foo*" => 1};
@@ -45,7 +46,7 @@ ok(-s "$config{wikistatedir}/indexdb", "index file created");
# Clear state.
%oldrenderedfiles=%pagectime=();
-%pagesources=%pagemtime=%oldlinks=%links=%depends=
+%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
%destsources=%renderedfiles=%pagecase=%pagestate=();
ok(loadindex(), "load index");
@@ -104,10 +105,16 @@ is_deeply(\%destsources, {
"sparkline-foo.gif" => "bar",
"bar.png" => "bar.png",
}, "%destsources generated correctly");
+is_deeply(\%typedlinks, {
+ bar => {tag => {"Foo" => 1}},
+}, "%typedlinks loaded correctly");
+is_deeply(\%oldtypedlinks, {
+ bar => {tag => {"Foo" => 1}},
+}, "%oldtypedlinks loaded correctly");
# Clear state.
%oldrenderedfiles=%pagectime=();
-%pagesources=%pagemtime=%oldlinks=%links=%depends=
+%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
%destsources=%renderedfiles=%pagecase=%pagestate=();
# When state is loaded for a wiki rebuild, only ctime and oldrenderedfiles
@@ -140,5 +147,9 @@ is_deeply(\%pagecase, {
}, "%pagecase generated correctly");
is_deeply(\%destsources, {
}, "%destsources generated correctly");
+is_deeply(\%typedlinks, {
+}, "%typedlinks cleared correctly");
+is_deeply(\%oldtypedlinks, {
+}, "%oldtypedlinks cleared correctly");
system "rm -rf $config{wikistatedir}";
diff --git a/t/tag.t b/t/tag.t
new file mode 100755
index 000000000..3383fd475
--- /dev/null
+++ b/t/tag.t
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+package IkiWiki;
+
+use warnings;
+use strict;
+use Test::More tests => 10;
+
+BEGIN { use_ok("IkiWiki"); }
+BEGIN { use_ok("IkiWiki::Plugin::tag"); }
+
+ok(! system("rm -rf t/tmp; mkdir t/tmp"));
+
+$config{userdir} = "users";
+$config{tagbase} = "tags";
+$config{tagged_is_strict} = 1;
+
+%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;
+}
+
+$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)"));
+
+ok(pagespec_match("one", "typedlink(tag tags/numbers)"));
+ok(!pagespec_match("one", "typedlink(tag tags/letters)"));
+# invalid syntax
+ok(pagespec_match("one", "typedlink(tag)")->isa("IkiWiki::ErrorReason"));
+
+1;