add news item for ikiwiki 3.20101112
[ikiwiki] / t / add_depends.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 40;
5
6 BEGIN { use_ok("IkiWiki"); }
7 %config=IkiWiki::defaultconfig();
8 $config{srcdir}=$config{destdir}="/dev/null";
9 IkiWiki::checkconfig();
10
11 $pagesources{"foo$_"}="foo$_.mdwn" for 0..9;
12
13 # avoids adding an unparseable pagespec
14 ok(! add_depends("foo0", "foo and (bar"));
15 ok(! add_depends("foo0", "foo another"));
16
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"});
26
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)));
32
33 # adding other dep types standalone
34 ok(add_depends("foo2", "*", deptype("presence")));
35 ok(add_depends("foo2", "bar", deptype("links")));
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)));
40
41 # adding combined dep types
42 ok(add_depends("foo2", "baz", deptype("links", "presence")));
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));
46
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", deptype("presence"))); # 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", deptype("links"))); # had only content before
56 ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
57 ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
58
59 # content is the default if unknown types are entered
60 ok(add_depends("foo9", "*", deptype("monkey")));
61 ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT);
62 ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
63
64 # Influences are added for dependencies involving links.
65 $pagesources{"foo"}="foo.mdwn";
66 $links{foo}=[qw{bar}]; 
67 $pagesources{"bar"}="bar.mdwn";
68 $links{bar}=[qw{}];
69 ok(add_depends("foo", "link(bar) and backlink(meep)"));
70 ok($IkiWiki::depends_simple{foo}{foo} == $IkiWiki::DEPEND_LINKS);