summaryrefslogtreecommitdiff
path: root/t/globlist_merge.t
blob: db76f1cd44229ed20deecfd461c8d15919279db2 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 25;
  5. sub same {
  6. my $a=shift;
  7. my $b=shift;
  8. my $match=shift;
  9. my $imatch=(IkiWiki::globlist_match($match, $a) ||
  10. IkiWiki::globlist_match($match, $b));
  11. my $cmatch=IkiWiki::globlist_match($match, IkiWiki::globlist_merge($a, $b));
  12. return $imatch == $cmatch;
  13. }
  14. BEGIN { use_ok("IkiWiki::Render"); }
  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("* !foo", "!bar", "bar"), "matching glob and matching inversion");
  27. ok(same("* !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion");
  28. ok(same("* !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(IkiWiki::globlist_match("foo/Discussion",
  35. IkiWiki::globlist_merge("* !*/Discussion", "*/Discussion")), "should match");
  36. ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
  37. ok(same("*/Discussion", "* !*/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");