4 use Test::More tests => 50;
6 BEGIN { use_ok("IkiWiki"); }
7 %config=IkiWiki::defaultconfig();
8 $config{srcdir}=$config{destdir}="/dev/null";
9 IkiWiki::checkconfig();
11 # avoids adding an unparseable pagespec
12 ok(! add_depends("foo", "foo and (bar"));
13 ok(! add_depends("foo", "foo another"));
15 # simple and not-so-simple dependencies split
16 ok(add_depends("foo", "*"));
17 ok(add_depends("foo", "bar"));
18 ok(add_depends("foo", "BAZ"));
19 ok(exists $IkiWiki::depends_simple{foo}{"bar"});
20 ok(exists $IkiWiki::depends_simple{foo}{"baz"}); # lowercase
21 ok(! exists $IkiWiki::depends_simple{foo}{"*"});
22 ok(! exists $IkiWiki::depends{foo}{"bar"});
23 ok(! exists $IkiWiki::depends{foo}{"baz"});
25 # default dependencies are content dependencies
26 ok($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_CONTENT);
27 ok(! ($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
28 ok($IkiWiki::depends_simple{foo}{"bar"} & $IkiWiki::DEPEND_CONTENT);
29 ok(! ($IkiWiki::depends_simple{foo}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
31 # adding other dep types standalone
32 ok(add_depends("foo2", "*", presence => 1));
33 ok(add_depends("foo2", "bar", links => 1));
34 ok($IkiWiki::depends{foo2}{"*"} & $IkiWiki::DEPEND_PRESENCE);
35 ok(! ($IkiWiki::depends{foo2}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
36 ok($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_LINKS);
37 ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
39 # adding combined dep types
40 ok(add_depends("foo2", "baz", links => 1, presence => 1));
41 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
42 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
43 ok(! ($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
45 # adding a pagespec that requires page metadata should cause a fallback to
46 # a content dependency
47 foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()",
49 "* or backlink(yo)", # this one could actually be acceptably be
50 # detected to not need a content dep .. in
53 ok(add_depends("foo3", $spec, presence => 1));
54 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT);
55 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
58 # adding dep types to existing dependencies should merge the flags
59 ok(add_depends("foo2", "baz"));
60 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
61 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
62 ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
63 ok(add_depends("foo2", "bar", presence => 1)); # had only links before
64 ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE));
65 ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT));
66 ok(add_depends("foo", "bar", links => 1)); # had only content before
67 ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
68 ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE));