4 use Test::More tests => 88;
6 BEGIN { use_ok("IkiWiki"); }
7 %config=IkiWiki::defaultconfig();
8 $config{srcdir}=$config{destdir}="/dev/null";
9 IkiWiki::checkconfig();
11 $pagesources{"foo$_"}="foo$_.mdwn" for 0..9;
13 # avoids adding an unparseable pagespec
14 ok(! add_depends("foo0", "foo and (bar"));
15 ok(! add_depends("foo0", "foo another"));
17 # simple and not-so-simple dependencies split
18 ok(add_depends("foo0", "*"));
19 ok(add_depends("foo0", "bar"));
20 ok(add_depends("foo0", "BAZ"));
21 ok(exists $IkiWiki::depends_simple{foo0}{"bar"});
22 ok(exists $IkiWiki::depends_simple{foo0}{"baz"}); # lowercase
23 ok(! exists $IkiWiki::depends_simple{foo0}{"*"});
24 ok(! exists $IkiWiki::depends{foo0}{"bar"});
25 ok(! exists $IkiWiki::depends{foo0}{"baz"});
27 # default dependencies are content dependencies
28 ok($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_CONTENT);
29 ok(! ($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
30 ok($IkiWiki::depends_simple{foo0}{"bar"} & $IkiWiki::DEPEND_CONTENT);
31 ok(! ($IkiWiki::depends_simple{foo0}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
33 # adding other dep types standalone
34 ok(add_depends("foo2", "*", presence => 1));
35 ok(add_depends("foo2", "bar", links => 1));
36 ok($IkiWiki::depends{foo2}{"*"} & $IkiWiki::DEPEND_PRESENCE);
37 ok(! ($IkiWiki::depends{foo2}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
38 ok($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_LINKS);
39 ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
41 # adding combined dep types
42 ok(add_depends("foo2", "baz", links => 1, presence => 1));
43 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
44 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
45 ok(! ($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
47 # adding dep types to existing dependencies should merge the flags
48 ok(add_depends("foo2", "baz"));
49 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
50 ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
51 ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
52 ok(add_depends("foo2", "bar", presence => 1)); # had only links before
53 ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE));
54 ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT));
55 ok(add_depends("foo0", "bar", links => 1)); # had only content before
56 ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
57 ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
59 # Adding a pagespec that requires page metadata should add the influence
60 # as an explicit dependency. In the case of a link, a links dependency.
61 $links{foo0}=$links{foo9}=[qw{bar baz}];
62 foreach my $spec ("* and ! link(bar)", "* or link(bar)") {
63 ok(add_depends("foo3", $spec, presence => 1));
64 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE);
65 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
66 ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
67 ok(add_depends("foo4", $spec, links => 1));
68 ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS);
69 ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
70 ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS);
73 # a pagespec with backlinks() will add as an influence the page with the links
74 $links{foo0}=[qw{foo5 foo7}];
75 foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") {
76 ok(add_depends("foo5", $spec, presence => 1));
77 ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE);
78 ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
79 ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
80 ok(add_depends("foo6", $spec, links => 1));
81 ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS);
82 ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
83 ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
84 ok(add_depends("foo7", $spec, presence => 1, links => 1));
85 ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE);
86 ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS);
87 ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT));
88 ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS);
89 ok(add_depends("foo8", $spec));
90 ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT);
91 ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
92 ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS);
95 # content is the default if unknown types are entered
96 ok(add_depends("foo9", "*", presenCe => 1));
97 ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT);
98 ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));