4 use Test::More tests => 90;
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 $IkiWiki::pagectime{foo} = 2;
24 $IkiWiki::pagectime{foo2} = 2;
25 $IkiWiki::pagectime{foo3} = 1;
26 $IkiWiki::pagectime{bar} = 3;
27 $IkiWiki::pagectime{"post/1"} = 6;
28 $IkiWiki::pagectime{"post/2"} = 6;
29 $IkiWiki::pagectime{"post/3"} = 6;
30 $links{foo}=[qw{post/1 post/2}];
31 $links{foo2}=[qw{bar}];
32 $links{foo3}=[qw{bar}];
34 is_deeply([pagespec_match_list("foo", "bar")], ["bar"]);
35 is_deeply([sort(pagespec_match_list("foo", "* and !post/*"))], ["bar", "foo", "foo2", "foo3"]);
36 is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]);
37 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)],
38 ["post/3", "post/2", "post/1"]);
39 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)],
40 ["post/1", "post/2"]);
41 is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)],
42 ["post/1", "post/2", "post/3"]);
43 is_deeply([pagespec_match_list("foo", "post/*", sort => "title",
44 filter => sub { $_[0] =~ /3/}) ],
45 ["post/1", "post/2"]);
46 is_deeply([pagespec_match_list("foo", "*", sort => "path", num => 2)],
48 is_deeply([pagespec_match_list("foo", "foo* or bar*",
49 sort => "-age title")], # oldest first, break ties by title
50 ["foo3", "foo", "foo2", "bar"]);
51 my $r=eval { pagespec_match_list("foo", "beep") };
52 ok(eval { pagespec_match_list("foo", "beep") } == 0);
53 ok(! $@, "does not fail with error when unable to match anything");
54 eval { pagespec_match_list("foo", "this is not a legal pagespec!") };
55 ok($@, "fails with error when pagespec bad");
57 # A pagespec that requires page metadata should add influences
58 # as an explicit dependency. In the case of a link, a links dependency.
59 foreach my $spec ("* and link(bar)", "* or link(bar)") {
60 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
61 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
62 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
63 ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS);
64 %IkiWiki::depends_simple=();
66 pagespec_match_list("foo3", $spec, deptype => deptype("links"));
67 ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_LINKS);
68 ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
69 ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
70 %IkiWiki::depends_simple=();
74 # a pagespec with backlinks() will add as an influence the page with the links
75 foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)") {
76 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
77 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
78 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
79 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
80 %IkiWiki::depends_simple=();
82 pagespec_match_list("foo2", $spec, deptype => deptype("links"));
83 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
84 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
85 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
86 %IkiWiki::depends_simple=();
88 pagespec_match_list("foo2", $spec, deptype => deptype("presence", "links"));
89 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
90 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
91 ok(! ($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT));
92 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
93 %IkiWiki::depends_simple=();
95 pagespec_match_list("foo2", $spec);
96 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT);
97 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
98 ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
99 %IkiWiki::depends_simple=();
100 %IkiWiki::depends=();
103 # Hard fails due to a glob, etc, will block influences of other anded terms.
104 foreach my $spec ("nosuchpage and link(bar)", "link(bar) and nosuchpage",
105 "link(bar) and */Discussion", "*/Discussion and link(bar)",
106 "!foo2 and link(bar)", "link(bar) and !foo2") {
107 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
108 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
109 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
110 ok(! exists $IkiWiki::depends_simple{foo2}{foo2}, "no influence from $spec");
111 %IkiWiki::depends_simple=();
112 %IkiWiki::depends=();
115 # A hard fail will not block influences of other ored terms.
116 foreach my $spec ("nosuchpage or link(bar)", "link(bar) or nosuchpage",
117 "link(bar) or */Discussion", "*/Discussion or link(bar)",
118 "!foo2 or link(bar)", "link(bar) or !foo2",
119 "link(bar) or (!foo2 and !foo1)") {
120 pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
121 ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
122 ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
123 ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS);
124 %IkiWiki::depends_simple=();
125 %IkiWiki::depends=();