4 use Test::More tests => 89;
6 BEGIN { use_ok("IkiWiki"); }
8 %config=IkiWiki::defaultconfig();
9 $config{srcdir}=$config{destdir}="/dev/null";
10 IkiWiki::checkconfig();
12 hook(type => "sort", id => "path", call => sub { $_[0] cmp $_[1] });
19 "post/1" => "post/1.mdwn",
20 "post/2" => "post/2.mdwn",
21 "post/3" => "post/3.mdwn",
23 $links{foo}=[qw{post/1 post/2}];
24 $links{foo2}=[qw{bar}];
25 $links{foo3}=[qw{bar}];
27 is_deeply([pagespec_match_list("foo", "bar")], ["bar"]);
28 is_deeply([sort(pagespec_match_list("foo", "* and !post/*"))], ["bar", "foo", "foo2", "foo3"]);
29 is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]);
30 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)],
31 ["post/3", "post/2", "post/1"]);
32 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)],
33 ["post/1", "post/2"]);
34 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)],
35 ["post/1", "post/2", "post/3"]);
36 is_deeply([pagespec_match_list("foo", "post/*", sort => "title",
37 filter => sub { $_[0] =~ /3/}) ],
38 ["post/1", "post/2"]);
39 is_deeply([pagespec_match_list("foo", "*", sort => "path", num => 2)],
41 my $r=eval { pagespec_match_list("foo", "beep") };
42 ok(eval { pagespec_match_list("foo", "beep") } == 0);
43 ok(! $@, "does not fail with error when unable to match anything");
44 eval { pagespec_match_list("foo", "this is not a legal pagespec!") };
45 ok($@, "fails with error when pagespec bad");
47 # A pagespec that requires page metadata should add influences
48 # as an explicit dependency. In the case of a link, a links dependency.
49 foreach my $spec ("* and link(bar)", "* or link(bar)") {
50 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
51 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
52 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
53 ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS);
54 %IkiWiki::depends_simple=();
56 pagespec_match_list("foo3", $spec, deptype => deptype("links"));
57 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_LINKS);
58 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
59 ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
60 %IkiWiki::depends_simple=();
64 # a pagespec with backlinks() will add as an influence the page with the links
65 foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)") {
66 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
67 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
68 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
69 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
70 %IkiWiki::depends_simple=();
72 pagespec_match_list("foo2", $spec, deptype => deptype("links"));
73 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
74 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
75 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
76 %IkiWiki::depends_simple=();
78 pagespec_match_list("foo2", $spec, deptype => deptype("presence", "links"));
79 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
80 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
81 ok(! ($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT));
82 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
83 %IkiWiki::depends_simple=();
85 pagespec_match_list("foo2", $spec);
86 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT);
87 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
88 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
89 %IkiWiki::depends_simple=();
93 # Hard fails due to a glob, etc, will block influences of other anded terms.
94 foreach my $spec ("nosuchpage and link(bar)", "link(bar) and nosuchpage",
95 "link(bar) and */Discussion", "*/Discussion and link(bar)",
96 "!foo2 and link(bar)", "link(bar) and !foo2") {
97 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
98 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
99 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
100 ok(! exists $IkiWiki::depends_simple{foo2}{foo2}, "no influence from $spec");
101 %IkiWiki::depends_simple=();
102 %IkiWiki::depends=();
105 # A hard fail will not block influences of other ored terms.
106 foreach my $spec ("nosuchpage or link(bar)", "link(bar) or nosuchpage",
107 "link(bar) or */Discussion", "*/Discussion or link(bar)",
108 "!foo2 or link(bar)", "link(bar) or !foo2",
109 "link(bar) or (!foo2 and !foo1)") {
110 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
111 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
112 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
113 ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS);
114 %IkiWiki::depends_simple=();
115 %IkiWiki::depends=();