]> sipb.mit.edu Git - ikiwiki.git/blob - t/pagespec_match.t
web commit by JoshTriplett
[ikiwiki.git] / t / pagespec_match.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 46;
5
6 BEGIN { use_ok("IkiWiki"); }
7
8 ok(pagespec_match("foo", "*", ""));
9 ok(pagespec_match("page", "?ag?", ""));
10 ok(! pagespec_match("page", "?a?g?", ""));
11 ok(pagespec_match("foo.png", "*.*", ""));
12 ok(! pagespec_match("foo", "*.*", ""));
13 ok(pagespec_match("foo", "foo or bar", ""), "simple list");
14 ok(pagespec_match("bar", "foo or bar", ""), "simple list 2");
15 ok(pagespec_match("foo", "f?? and !foz", ""));
16 ok(! pagespec_match("foo", "f?? and !foo", ""));
17 ok(! pagespec_match("foo", "* and !foo", ""));
18 ok(! pagespec_match("foo", "foo and !foo", ""));
19 ok(! pagespec_match("foo.png", "* and !*.*", ""));
20 ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))", ""));
21 ok(! pagespec_match("a/foo", "foo", "a/b"), "nonrelative fail");
22 ok(! pagespec_match("foo", "./*", "a/b"), "relative fail");
23 ok(pagespec_match("a/foo", "./*", "a/b"), "relative");
24 ok(pagespec_match("a/b/foo", "./*", "a/b"), "relative 2");
25 ok(pagespec_match("foo", "./*", "a"), "relative toplevel");
26 ok(pagespec_match("foo/bar", "*", "baz"), "absolute");
27
28 # The link and backlink stuff needs this.
29 $config{userdir}="";
30 $links{foo}=[qw{bar baz}];
31 $links{bar}=[];
32 $links{baz}=[];
33 $links{"bugs/foo"}=[qw{bugs/done}];
34 $links{"bugs/done"}=[];
35 $links{"bugs/bar"}=[qw{done}];
36 $links{"done"}=[];
37 $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
38 $links{"examples/softwaresite/bugs/done"}=[];
39
40 ok(pagespec_match("foo", "link(bar)", ""), "link");
41 ok(! pagespec_match("foo", "link(quux)", ""), "failed link");
42 ok(pagespec_match("bugs/foo", "link(done)", "bugs/done"), "link match to bestlink");
43 ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)", 
44                 "bugs/done"), "link match to bestlink");
45 ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate", 
46                 "link(./done)", "examples/softwaresite/bugs/done"), "link relative");
47 ok(! pagespec_match("foo", "link(./bar)", "foo/bar"), "link relative fail");
48 ok(pagespec_match("bar", "backlink(foo)", ""), "backlink");
49 ok(! pagespec_match("quux", "backlink(foo)", ""), "failed backlink");
50
51 $IkiWiki::pagectime{foo}=1154532692; # Wed Aug  2 11:26 EDT 2006
52 $IkiWiki::pagectime{bar}=1154532695; # after
53 ok(pagespec_match("foo", "created_before(bar)"));
54 ok(! pagespec_match("foo", "created_after(bar)"));
55 ok(! pagespec_match("bar", "created_before(foo)"));
56 ok(pagespec_match("bar", "created_after(foo)"));
57 ok(pagespec_match("foo", "creation_year(2006)"), "year");
58 ok(! pagespec_match("foo", "creation_year(2005)"), "other year");
59 ok(pagespec_match("foo", "creation_month(8)"), "month");
60 ok(! pagespec_match("foo", "creation_month(9)"), "other month");
61 ok(pagespec_match("foo", "creation_day(2)"), "day");
62 ok(! pagespec_match("foo", "creation_day(3)"), "other day");
63
64 ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
65
66 # old style globlists
67 ok(pagespec_match("foo", "foo bar"), "simple list");
68 ok(pagespec_match("bar", "foo bar"), "simple list 2");
69 ok(pagespec_match("foo", "f?? !foz"));
70 ok(! pagespec_match("foo", "f?? !foo"));
71 ok(! pagespec_match("foo", "* !foo"));
72 ok(! pagespec_match("foo", "foo !foo"));
73 ok(! pagespec_match("foo.png", "* !*.*"));