]> sipb.mit.edu Git - ikiwiki.git/blob - t/pagespec_merge.t
template suggestion
[ikiwiki.git] / t / pagespec_merge.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 25;
5
6 BEGIN { use_ok("IkiWiki"); }
7
8 sub same {
9         my $a=shift;
10         my $b=shift;
11         my $match=shift;
12         
13         my $imatch=(pagespec_match($match, $a) ||
14                     pagespec_match($match, $b));
15         my $cmatch=pagespec_match($match, IkiWiki::pagespec_merge($a, $b));
16         
17         return $imatch == $cmatch;
18 }
19
20 ok(same("foo", "bar", "foo"), "basic match 1");
21 ok(same("foo", "bar", "bar"), "basic match 2");
22 ok(same("foo", "bar", "foobar"), "basic failed match");
23 ok(same("foo", "!bar", "foo"), "basic match with inversion");
24 ok(same("foo", "!bar", "bar"), "basic failed match with inversion");
25 ok(same("!foo", "bar", "foo"), "basic failed match with inversion 2");
26 ok(same("!foo", "bar", "bar"), "basic match with inversion 2");
27 ok(same("!foo", "!bar", "foo"), "double inversion failed match");
28 ok(same("!foo", "!bar", "bar"), "double inversion failed match 2");
29 ok(same("*", "!bar", "foo"), "glob+inversion match");
30 ok(same("*", "!bar", "bar"), "matching glob and matching inversion");
31 ok(same("* !foo", "!bar", "bar"), "matching glob and matching inversion");
32 ok(same("* !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion");
33 ok(same("* !foo", "!foo", "foo"), "matching glob with matching inversion and matching inversion");
34 ok(same("b??", "!b??", "bar"), "matching glob and matching inverted glob");
35 ok(same("f?? !f??", "!bar", "bar"), "matching glob and matching inverted glob");
36 ok(same("b??", "!b?z", "bar"), "matching glob and non-matching inverted glob");
37 ok(same("f?? !f?z", "!bar", "bar"), "matching glob and non-matching inverted glob");
38 ok(same("!foo bar baz", "!bar", "bar"), "matching list and matching inversion");
39 ok(pagespec_match("foo/Discussion",
40         IkiWiki::pagespec_merge("* !*/Discussion", "*/Discussion")), "should match");
41 ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
42 ok(same("*/Discussion", "* !*/Discussion", "foo/Discussion"), "Discussion merge 2");
43 ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/Discussion"), "bidirectional merge 1");
44 ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/bar"), "bidirectional merge 2");