4 use Test::More tests => 53;
6 BEGIN { use_ok("IkiWiki"); }
8 ok(pagespec_match("foo", "*"));
9 ok(!pagespec_match("foo", ""));
10 ok(pagespec_match("foo", "!bar"));
11 ok(pagespec_match("page", "?ag?"));
12 ok(! pagespec_match("page", "?a?g?"));
13 ok(pagespec_match("foo.png", "*.*"));
14 ok(! pagespec_match("foo", "*.*"));
15 ok(pagespec_match("foo", "foo or bar"), "simple list");
16 ok(pagespec_match("bar", "foo or bar"), "simple list 2");
17 ok(pagespec_match("foo", "f?? and !foz"));
18 ok(! pagespec_match("foo", "f?? and !foo"));
19 ok(! pagespec_match("foo", "* and !foo"));
20 ok(! pagespec_match("foo", "foo and !foo"));
21 ok(! pagespec_match("foo.png", "* and !*.*"));
22 ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))"));
23 ok(! pagespec_match("a/foo", "foo", location => "a/b"), "nonrelative fail");
24 ok(! pagespec_match("foo", "./*", location => "a/b"), "relative fail");
25 ok(pagespec_match("a/foo", "./*", location => "a/b"), "relative");
26 ok(pagespec_match("a/b/foo", "./*", location => "a/b"), "relative 2");
27 ok(pagespec_match("a/foo", "./*", "a/b"), "relative oldstyle call");
28 ok(pagespec_match("foo", "./*", location => "a"), "relative toplevel");
29 ok(pagespec_match("foo/bar", "*", location => "baz"), "absolute");
30 ok(! pagespec_match("foo", "foo and bar"), "foo and bar");
31 ok(pagespec_match("{f}oo", "{*}*"), "curly match");
32 ok(! pagespec_match("foo", "{*}*"), "curly !match");
34 # The link and backlink stuff needs this.
36 $links{foo}=[qw{bar baz}];
39 $links{"bugs/foo"}=[qw{bugs/done}];
40 $links{"bugs/done"}=[];
41 $links{"bugs/bar"}=[qw{done}];
43 $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
44 $links{"examples/softwaresite/bugs/done"}=[];
45 $links{"ook"}=[qw{/blog/tags/foo}];
47 ok(pagespec_match("foo", "link(bar)"), "link");
48 ok(pagespec_match("foo", "link(ba?)"), "glob link");
49 ok(! pagespec_match("foo", "link(quux)"), "failed link");
50 ok(! pagespec_match("foo", "link(qu*)"), "failed glob link");
51 ok(pagespec_match("bugs/foo", "link(done)", location => "bugs/done"), "link match to bestlink");
52 ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)",
53 location => "bugs/done"), "link match to bestlink");
54 ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate",
55 "link(./done)", location => "examples/softwaresite/bugs/done"), "link relative");
56 ok(! pagespec_match("foo", "link(./bar)", location => "foo/bar"), "link relative fail");
57 ok(pagespec_match("bar", "backlink(foo)"), "backlink");
58 ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink");
59 ok(! pagespec_match("bar", ""), "empty pagespec should match nothing");
60 ok(! pagespec_match("bar", " "), "blank pagespec should match nothing");
61 ok(pagespec_match("ook", "link(blog/tags/foo)"), "link internal absolute success");
62 ok(pagespec_match("ook", "link(/blog/tags/foo)"), "link explicit absolute success");
64 $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
65 $IkiWiki::pagectime{bar}=1154532695; # after
66 ok(pagespec_match("foo", "created_before(bar)"));
67 ok(! pagespec_match("foo", "created_after(bar)"));
68 ok(! pagespec_match("bar", "created_before(foo)"));
69 ok(pagespec_match("bar", "created_after(foo)"));
70 ok(pagespec_match("foo", "creation_year(2006)"), "year");
71 ok(! pagespec_match("foo", "creation_year(2005)"), "other year");
72 ok(pagespec_match("foo", "creation_month(8)"), "month");
73 ok(! pagespec_match("foo", "creation_month(9)"), "other month");
74 ok(pagespec_match("foo", "creation_day(2)"), "day");
75 ok(! pagespec_match("foo", "creation_day(3)"), "other day");
77 ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
79 my $ret=pagespec_match("foo", "(invalid");
80 ok(! $ret, "syntax error");
81 ok($ret =~ /syntax error/, "error message");