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