]> sipb.mit.edu Git - ikiwiki.git/blob - t/use_pagespec.t
92d7977cfd94ee0e7c672b5a1d1ce784d2bff6c6
[ikiwiki.git] / t / use_pagespec.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 10;
5
6 BEGIN { use_ok("IkiWiki"); }
7
8 %pagesources=(
9         foo => "foo.mdwn",
10         bar => "bar.mdwn",
11         "post/1" => "post/1.mdwn",
12         "post/2" => "post/2.mdwn",
13         "post/3" => "post/3.mdwn",
14 );
15
16 is_deeply([use_pagespec("foo", "bar")], ["bar"]);
17 is_deeply([sort(use_pagespec("foo", "post/*"))], ["post/1", "post/2", "post/3"]);
18 is_deeply([use_pagespec("foo", "post/*", sort => "title", reverse => 1)],
19         ["post/3", "post/2", "post/1"]);
20 is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 2)],
21         ["post/1", "post/2"]);
22 is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 50)],
23         ["post/1", "post/2", "post/3"]);
24 is_deeply([use_pagespec("foo", "post/*", sort => "title",
25                          limit => sub { $_[0] !~ /3/}) ],
26         ["post/1", "post/2"]);
27 my $r=eval { use_pagespec("foo", "beep") };
28 ok(eval { use_pagespec("foo", "beep") } == 0);
29 ok(! $@, "does not fail with error when unable to match anything");
30 eval { use_pagespec("foo", "this is not a legal pagespec!") };
31 ok($@, "fails with error when pagespec bad");