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