4 use Test::More tests => 85;
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 dep types to existing dependencies should merge the flags
46 ok(add_depends("foo2", "baz"));
47 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
48 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
49 ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
50 ok(add_depends("foo2", "bar", presence => 1)); # had only links before
51 ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE));
52 ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT));
53 ok(add_depends("foo", "bar", links => 1)); # had only content before
54 ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
55 ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE));
57 # adding a pagespec that requires page metadata should cause a fallback to
58 # a content dependency
59 foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()",
61 "* or unknown(yo)", # this one could actually be acceptably be
62 # detected to not need a content dep .. in
65 ok(add_depends("foo3", $spec, presence => 1));
66 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT);
67 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
68 ok(add_depends("foo4", $spec, links => 1));
69 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT);
70 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
73 # a pagespec with backlinks() in it is acceptable for a links dependency,
74 # but not a presence dependency
75 foreach my $spec ("index or (backlink(index) and !*.png)", "backlink(foo)") {
76 ok(add_depends("foo5", $spec, presence => 1));
77 ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_CONTENT);
78 ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
79 ok(add_depends("foo6", $spec, links => 1));
80 ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS);
81 ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
82 # combining both ends up with a content+links dependency
83 ok(add_depends("foo7", $spec, presence => 1, links => 1));
84 ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT);
85 ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS);
86 ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE));