add a syntax check
[ikiwiki] / t / globlist_merge.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 25;
5
6 sub same {
7         my $a=shift;
8         my $b=shift;
9         my $match=shift;
10         
11         my $imatch=(IkiWiki::globlist_match($match, $a) ||
12                     IkiWiki::globlist_match($match, $b));
13         my $cmatch=IkiWiki::globlist_match($match, IkiWiki::globlist_merge($a, $b));
14         
15         return $imatch == $cmatch;
16 }
17
18 BEGIN { use_ok("IkiWiki::Render"); }
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(IkiWiki::globlist_match("foo/Discussion",
40         IkiWiki::globlist_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");