summaryrefslogtreecommitdiff
path: root/t/pagespec_match.t
blob: fe9624370625a74a57146f8f7de80c56c6215a0b (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 87;
  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("foo", "(
  22. bar
  23. or (
  24. (meep and foo)
  25. or
  26. (baz or foo)
  27. or beep
  28. )
  29. )"), "multiline complex pagespec");
  30. ok(! pagespec_match("a/foo", "foo", location => "a/b"), "nonrelative fail");
  31. ok(! pagespec_match("foo", "./*", location => "a/b"), "relative fail");
  32. ok(pagespec_match("a/foo", "./*", location => "a/b"), "relative");
  33. ok(pagespec_match("a/b/foo", "./*", location => "a/b"), "relative 2");
  34. ok(pagespec_match("a/foo", "./*", "a/b"), "relative oldstyle call");
  35. ok(pagespec_match("foo", "./*", location => "a"), "relative toplevel");
  36. ok(pagespec_match("foo/bar", "*", location => "baz"), "absolute");
  37. ok(! pagespec_match("foo", "foo and bar"), "foo and bar");
  38. ok(pagespec_match("{f}oo", "{*}*"), "curly match");
  39. ok(! pagespec_match("foo", "{*}*"), "curly !match");
  40. ok(pagespec_match("somepage", "user(frodo)", user => "frodo"));
  41. ok(pagespec_match("somepage", "user(frodo)", user => "Frodo"));
  42. ok(! pagespec_match("somepage", "user(frodo)", user => "Sam"));
  43. ok(pagespec_match("somepage", "user(*o)", user => "Bilbo"));
  44. ok(pagespec_match("somepage", "user(*o)", user => "frodo"));
  45. ok(! pagespec_match("somepage", "user(*o)", user => "Sam"));
  46. ok(pagespec_match("somepage", "user(http://*.myopenid.com/)", user => "http://foo.myopenid.com/"));
  47. ok(pagespec_match("somepage", "user(*://*)", user => "http://foo.myopenid.com/"));
  48. # The link and backlink stuff needs this.
  49. $config{userdir}="";
  50. $links{foo}=[qw{bar baz}];
  51. $links{bar}=[];
  52. $links{baz}=[];
  53. $links{meh}=[];
  54. $links{"bugs/foo"}=[qw{bugs/done}];
  55. $links{"bugs/done"}=[];
  56. $links{"bugs/bar"}=[qw{done}];
  57. $links{"done"}=[];
  58. $links{"done"}=[];
  59. $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
  60. $links{"examples/softwaresite/bugs/done"}=[];
  61. $links{"ook"}=[qw{/blog/tags/foo}];
  62. foreach my $p (keys %links) {
  63. $pagesources{$p}="$p.mdwn";
  64. }
  65. $pagesources{"foo.png"}="foo.png";
  66. $pagesources{"foo"}="foo.mdwn";
  67. $IkiWiki::hooks{htmlize}{mdwn}={};
  68. ok(pagespec_match("foo", "foo"), "simple");
  69. ok(! pagespec_match("foo", "bar"), "simple fail");
  70. ok(pagespec_match("foo", "foo"), "simple glob");
  71. ok(pagespec_match("foo", "f*"), "simple glob fail");
  72. ok(pagespec_match("foo", "page(foo)"), "page()");
  73. print pagespec_match("foo", "page(foo)")."\n";
  74. ok(! pagespec_match("foo", "page(bar)"), "page() fail");
  75. ok(! pagespec_match("foo.png", "page(foo.png)"), "page() fails on non-page");
  76. ok(! pagespec_match("foo.png", "page(foo*)"), "page() fails on non-page glob");
  77. ok(pagespec_match("foo", "page(foo)"), "page() glob");
  78. ok(pagespec_match("foo", "page(f*)"), "page() glob fail");
  79. ok(pagespec_match("foo", "link(bar)"), "link");
  80. ok(pagespec_match("foo", "link(.)", location => "bar"), "link with .");
  81. ok(! pagespec_match("foo", "link(.)"), "link with . but missing location");
  82. ok(pagespec_match("foo", "link(ba?)"), "glob link");
  83. ok(! pagespec_match("foo", "link(quux)"), "failed link");
  84. ok(! pagespec_match("foo", "link(qu*)"), "failed glob link");
  85. ok(pagespec_match("bugs/foo", "link(done)", location => "bugs/done"), "link match to bestlink");
  86. ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)",
  87. location => "bugs/done"), "link match to bestlink");
  88. ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate",
  89. "link(./done)", location => "examples/softwaresite/bugs/done"), "link relative");
  90. ok(! pagespec_match("foo", "link(./bar)", location => "foo/bar"), "link relative fail");
  91. ok(pagespec_match("bar", "backlink(foo)"), "backlink");
  92. ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink");
  93. ok(! pagespec_match("bar", ""), "empty pagespec should match nothing");
  94. ok(! pagespec_match("bar", " "), "blank pagespec should match nothing");
  95. ok(pagespec_match("ook", "link(blog/tags/foo)"), "link internal absolute success");
  96. ok(pagespec_match("ook", "link(/blog/tags/foo)"), "link explicit absolute success");
  97. ok(pagespec_match("meh", "!link(done)"), "negated failing match is a success");
  98. $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
  99. $IkiWiki::pagectime{bar}=1154532695; # after
  100. ok(pagespec_match("foo", "created_before(bar)"));
  101. ok(! pagespec_match("foo", "created_after(bar)"));
  102. ok(! pagespec_match("bar", "created_before(foo)"));
  103. ok(pagespec_match("bar", "created_after(foo)"));
  104. ok(pagespec_match("foo", "creation_year(2006)"), "year");
  105. ok(! pagespec_match("foo", "creation_year(2005)"), "other year");
  106. ok(pagespec_match("foo", "creation_month(8)"), "month");
  107. ok(! pagespec_match("foo", "creation_month(9)"), "other month");
  108. ok(pagespec_match("foo", "creation_day(2)"), "day");
  109. ok(! pagespec_match("foo", "creation_day(3)"), "other day");
  110. ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
  111. my $ret=pagespec_match("foo", "(invalid");
  112. ok(! $ret, "syntax error");
  113. ok($ret =~ /syntax error/, "error message");
  114. $ret=pagespec_match("foo", "bar or foo");
  115. ok($ret, "simple match");
  116. is($ret, "foo matches foo", "stringified return");
  117. my $i=pagespec_match("foo", "link(bar)")->influences;
  118. is(join(",", keys %$i), 'foo', "link is influenced by the page with the link");
  119. $i=pagespec_match("bar", "backlink(foo)")->influences;
  120. is(join(",", keys %$i), 'foo', "backlink is influenced by the page with the link");
  121. $i=pagespec_match("bar", "backlink(foo)")->influences;
  122. is(join(",", keys %$i), 'foo', "backlink is influenced by the page with the link");
  123. $i=pagespec_match("bar", "created_before(foo)")->influences;
  124. is(join(",", keys %$i), 'foo', "created_before is influenced by the comparison page");
  125. $i=pagespec_match("bar", "created_after(foo)")->influences;
  126. is(join(",", keys %$i), 'foo', "created_after is influenced by the comparison page");
  127. $i=pagespec_match("foo", "link(baz) and created_after(bar)")->influences;
  128. is(join(",", sort keys %$i), 'bar,foo', "influences add up over AND");
  129. $i=pagespec_match("foo", "link(baz) and created_after(bar)")->influences;
  130. is(join(",", sort keys %$i), 'bar,foo', "influences add up over OR");
  131. $i=pagespec_match("foo", "!link(baz) and !created_after(bar)")->influences;
  132. is(join(",", sort keys %$i), 'bar,foo', "influences unaffected by negation");
  133. $i=pagespec_match("foo", "!link(baz) and !created_after(bar)")->influences;
  134. is(join(",", sort keys %$i), 'bar,foo', "influences unaffected by negation");
  135. $i=pagespec_match("meh", "!link(done)")->influences;
  136. is(join(",", sort keys %$i), 'meh', "a negated, failing link test is successful, so the page is a link influence");