summaryrefslogtreecommitdiff
path: root/t/pagespec_match_list.t
blob: 301197cc167ac06a0f2819f1fdb4d991b33e340f (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 49;
  5. BEGIN { use_ok("IkiWiki"); }
  6. %config=IkiWiki::defaultconfig();
  7. $config{srcdir}=$config{destdir}="/dev/null";
  8. IkiWiki::checkconfig();
  9. %pagesources=(
  10. foo => "foo.mdwn",
  11. foo2 => "foo2.mdwn",
  12. foo3 => "foo3.mdwn",
  13. bar => "bar.mdwn",
  14. "post/1" => "post/1.mdwn",
  15. "post/2" => "post/2.mdwn",
  16. "post/3" => "post/3.mdwn",
  17. );
  18. $links{foo}=[qw{post/1 post/2}];
  19. $links{foo2}=[qw{bar}];
  20. $links{foo3}=[qw{bar}];
  21. is_deeply([pagespec_match_list("foo", "bar")], ["bar"]);
  22. is_deeply([sort(pagespec_match_list("foo", "* and !post/*"))], ["bar", "foo", "foo2", "foo3"]);
  23. is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]);
  24. is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)],
  25. ["post/3", "post/2", "post/1"]);
  26. is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)],
  27. ["post/1", "post/2"]);
  28. is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)],
  29. ["post/1", "post/2", "post/3"]);
  30. is_deeply([pagespec_match_list("foo", "post/*", sort => "title",
  31. filter => sub { $_[0] =~ /3/}) ],
  32. ["post/1", "post/2"]);
  33. my $r=eval { pagespec_match_list("foo", "beep") };
  34. ok(eval { pagespec_match_list("foo", "beep") } == 0);
  35. ok(! $@, "does not fail with error when unable to match anything");
  36. eval { pagespec_match_list("foo", "this is not a legal pagespec!") };
  37. ok($@, "fails with error when pagespec bad");
  38. # A pagespec that requires page metadata should add influences
  39. # as an explicit dependency. In the case of a link, a links dependency.
  40. foreach my $spec ("* and link(bar)", "* or link(bar)") {
  41. pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
  42. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  43. ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
  44. ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS);
  45. %IkiWiki::depends_simple=();
  46. %IkiWiki::depends=();
  47. pagespec_match_list("foo3", $spec, deptype => deptype("links"));
  48. ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_LINKS);
  49. ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
  50. ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
  51. %IkiWiki::depends_simple=();
  52. %IkiWiki::depends=();
  53. }
  54. # a pagespec with backlinks() will add as an influence the page with the links
  55. foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)") {
  56. pagespec_match_list("foo2", $spec, deptype => deptype("presence"));
  57. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  58. ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
  59. ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
  60. %IkiWiki::depends_simple=();
  61. %IkiWiki::depends=();
  62. pagespec_match_list("foo2", $spec, deptype => deptype("links"));
  63. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
  64. ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
  65. ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
  66. %IkiWiki::depends_simple=();
  67. %IkiWiki::depends=();
  68. pagespec_match_list("foo2", $spec, deptype => deptype("presence", "links"));
  69. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  70. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS);
  71. ok(! ($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT));
  72. ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
  73. %IkiWiki::depends_simple=();
  74. %IkiWiki::depends=();
  75. pagespec_match_list("foo2", $spec);
  76. ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT);
  77. ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
  78. ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS);
  79. }