summaryrefslogtreecommitdiff
path: root/t/add_depends.t
blob: 9b074818c1f7a133e1c30c3c5583bfa4190efe27 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 38;
  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", "*", deptype("presence")));
  29. ok(add_depends("foo2", "bar", deptype("links")));
  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", deptype("links", "presence")));
  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", deptype("presence"))); # 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", deptype("links"))); # had only content before
  48. ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS));
  49. ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE));
  50. # content is the default if unknown types are entered
  51. ok(add_depends("foo9", "*", deptype("monkey")));
  52. ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT);
  53. ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS)));