]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/add_depends.t
optimization: pagespec_match_list with no num limit matches before sorting
[git.ikiwiki.info.git] / t / add_depends.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 38;
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", "*", 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)));
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));
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));
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)));