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