summaryrefslogtreecommitdiff
path: root/t/add_depends.t
blob: 9f426187b48ae0d4665d3e4f56b74396f4a15251 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 88;
  5. BEGIN { use_ok("IkiWiki"); }
  6. %config=IkiWiki::defaultconfig();
  7. $config{srcdir}=$config{destdir}="/dev/null";
  8. IkiWiki::checkconfig();
  9. $pagesources{"foo$_"}="foo$_.mdwn" for 0..9;
  10. # avoids adding an unparseable pagespec
  11. ok(! add_depends("foo0", "foo and (bar"));
  12. ok(! add_depends("foo0", "foo another"));
  13. # simple and not-so-simple dependencies split
  14. ok(add_depends("foo0", "*"));
  15. ok(add_depends("foo0", "bar"));
  16. ok(add_depends("foo0", "BAZ"));
  17. ok(exists $IkiWiki::depends_simple{foo0}{"bar"});
  18. ok(exists $IkiWiki::depends_simple{foo0}{"baz"}); # lowercase
  19. ok(! exists $IkiWiki::depends_simple{foo0}{"*"});
  20. ok(! exists $IkiWiki::depends{foo0}{"bar"});
  21. ok(! exists $IkiWiki::depends{foo0}{"baz"});
  22. # default dependencies are content dependencies
  23. ok($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_CONTENT);
  24. ok(! ($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
  25. ok($IkiWiki::depends_simple{foo0}{"bar"} & $IkiWiki::DEPEND_CONTENT);
  26. ok(! ($IkiWiki::depends_simple{foo0}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
  27. # adding other dep types standalone
  28. ok(add_depends("foo2", "*", presence => 1));
  29. ok(add_depends("foo2", "bar", links => 1));
  30. ok($IkiWiki::depends{foo2}{"*"} & $IkiWiki::DEPEND_PRESENCE);
  31. ok(! ($IkiWiki::depends{foo2}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
  32. ok($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_LINKS);
  33. ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
  34. # adding combined dep types
  35. ok(add_depends("foo2", "baz", links => 1, presence => 1));
  36. ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
  37. ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
  38. ok(! ($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
  39. # adding dep types to existing dependencies should merge the flags
  40. ok(add_depends("foo2", "baz"));
  41. ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS);
  42. ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE);
  43. ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT));
  44. ok(add_depends("foo2", "bar", presence => 1)); # had only links before
  45. ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE));
  46. ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT));
  47. ok(add_depends("foo0", "bar", links => 1)); # had only content before
  48. ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
  49. ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
  50. # Adding a pagespec that requires page metadata should add the influence
  51. # as an explicit dependency. In the case of a link, a links dependency.
  52. $links{foo0}=$links{foo9}=[qw{bar baz}];
  53. foreach my $spec ("* and ! link(bar)", "* or link(bar)") {
  54. ok(add_depends("foo3", $spec, presence => 1));
  55. ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  56. ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
  57. ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS);
  58. ok(add_depends("foo4", $spec, links => 1));
  59. ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS);
  60. ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE)));
  61. ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS);
  62. }
  63. # a pagespec with backlinks() will add as an influence the page with the links
  64. $links{foo0}=[qw{foo5 foo7}];
  65. foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") {
  66. ok(add_depends("foo5", $spec, presence => 1));
  67. ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  68. ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)));
  69. ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
  70. ok(add_depends("foo6", $spec, links => 1));
  71. ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS);
  72. ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT)));
  73. ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS);
  74. ok(add_depends("foo7", $spec, presence => 1, links => 1));
  75. ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE);
  76. ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS);
  77. ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT));
  78. ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS);
  79. ok(add_depends("foo8", $spec));
  80. ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT);
  81. ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));
  82. ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS);
  83. }
  84. # content is the default if unknown types are entered
  85. ok(add_depends("foo9", "*", presenCe => 1));
  86. ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT);
  87. ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));