summaryrefslogtreecommitdiff
path: root/t/pagespec_match.t
blob: 69cf361de4ed6aa4fa3cb591aa5c3481cab46a49 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 51;
  5. BEGIN { use_ok("IkiWiki"); }
  6. ok(pagespec_match("foo", "*"));
  7. ok(!pagespec_match("foo", ""));
  8. ok(pagespec_match("foo", "!bar"));
  9. ok(pagespec_match("page", "?ag?"));
  10. ok(! pagespec_match("page", "?a?g?"));
  11. ok(pagespec_match("foo.png", "*.*"));
  12. ok(! pagespec_match("foo", "*.*"));
  13. ok(pagespec_match("foo", "foo or bar"), "simple list");
  14. ok(pagespec_match("bar", "foo or bar"), "simple list 2");
  15. ok(pagespec_match("foo", "f?? and !foz"));
  16. ok(! pagespec_match("foo", "f?? and !foo"));
  17. ok(! pagespec_match("foo", "* and !foo"));
  18. ok(! pagespec_match("foo", "foo and !foo"));
  19. ok(! pagespec_match("foo.png", "* and !*.*"));
  20. ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))"));
  21. ok(! pagespec_match("a/foo", "foo", location => "a/b"), "nonrelative fail");
  22. ok(! pagespec_match("foo", "./*", location => "a/b"), "relative fail");
  23. ok(pagespec_match("a/foo", "./*", location => "a/b"), "relative");
  24. ok(pagespec_match("a/b/foo", "./*", location => "a/b"), "relative 2");
  25. ok(pagespec_match("a/foo", "./*", "a/b"), "relative oldstyle call");
  26. ok(pagespec_match("foo", "./*", location => "a"), "relative toplevel");
  27. ok(pagespec_match("foo/bar", "*", location => "baz"), "absolute");
  28. ok(! pagespec_match("foo", "foo and bar"), "foo and bar");
  29. # The link and backlink stuff needs this.
  30. $config{userdir}="";
  31. $links{foo}=[qw{bar baz}];
  32. $links{bar}=[];
  33. $links{baz}=[];
  34. $links{"bugs/foo"}=[qw{bugs/done}];
  35. $links{"bugs/done"}=[];
  36. $links{"bugs/bar"}=[qw{done}];
  37. $links{"done"}=[];
  38. $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
  39. $links{"examples/softwaresite/bugs/done"}=[];
  40. $links{"ook"}=[qw{/blog/tags/foo}];
  41. ok(pagespec_match("foo", "link(bar)"), "link");
  42. ok(pagespec_match("foo", "link(ba?)"), "glob link");
  43. ok(! pagespec_match("foo", "link(quux)"), "failed link");
  44. ok(! pagespec_match("foo", "link(qu*)"), "failed glob link");
  45. ok(pagespec_match("bugs/foo", "link(done)", location => "bugs/done"), "link match to bestlink");
  46. ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)",
  47. location => "bugs/done"), "link match to bestlink");
  48. ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate",
  49. "link(./done)", location => "examples/softwaresite/bugs/done"), "link relative");
  50. ok(! pagespec_match("foo", "link(./bar)", location => "foo/bar"), "link relative fail");
  51. ok(pagespec_match("bar", "backlink(foo)"), "backlink");
  52. ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink");
  53. ok(! pagespec_match("bar", ""), "empty pagespec should match nothing");
  54. ok(! pagespec_match("bar", " "), "blank pagespec should match nothing");
  55. ok(pagespec_match("ook", "link(blog/tags/foo)"), "link internal absolute success");
  56. ok(pagespec_match("ook", "link(/blog/tags/foo)"), "link explicit absolute success");
  57. $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
  58. $IkiWiki::pagectime{bar}=1154532695; # after
  59. ok(pagespec_match("foo", "created_before(bar)"));
  60. ok(! pagespec_match("foo", "created_after(bar)"));
  61. ok(! pagespec_match("bar", "created_before(foo)"));
  62. ok(pagespec_match("bar", "created_after(foo)"));
  63. ok(pagespec_match("foo", "creation_year(2006)"), "year");
  64. ok(! pagespec_match("foo", "creation_year(2005)"), "other year");
  65. ok(pagespec_match("foo", "creation_month(8)"), "month");
  66. ok(! pagespec_match("foo", "creation_month(9)"), "other month");
  67. ok(pagespec_match("foo", "creation_day(2)"), "day");
  68. ok(! pagespec_match("foo", "creation_day(3)"), "other day");
  69. ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
  70. my $ret=pagespec_match("foo", "(invalid");
  71. ok(! $ret, "syntax error");
  72. ok($ret =~ /syntax error/, "error message");