summaryrefslogtreecommitdiff
path: root/t/calculate_changed_links.t
blob: bf6e2af4538967311a0e372153c4e043ac7b706b (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use Test::More tests => 5;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Render"); }
  8. %config=IkiWiki::defaultconfig();
  9. $config{srcdir}=$config{destdir}="/dev/null";
  10. %oldrenderedfiles=%pagectime=();
  11. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  12. %destsources=%renderedfiles=%pagecase=%pagestate=();
  13. IkiWiki::checkconfig();
  14. foreach my $page (qw(tags/a tags/b Reorder Add Remove TypeAdd TypeRemove)) {
  15. $pagesources{$page} = "$page.mdwn";
  16. $pagemtime{$page} = $pagectime{$page} = 1000000;
  17. }
  18. $oldlinks{Reorder} = [qw{tags/a tags/b}];
  19. $links{Reorder} = [qw{tags/b tags/a}];
  20. $oldlinks{Add} = [qw{tags/b}];
  21. $links{Add} = [qw{tags/a tags/b}];
  22. $oldlinks{Remove} = [qw{tags/a}];
  23. $links{Remove} = [];
  24. $oldlinks{TypeAdd} = [qw{tags/a tags/b}];
  25. $links{TypeAdd} = [qw{tags/a tags/b}];
  26. # This causes TypeAdd to be rebuilt, but isn't a backlink change, so it doesn't
  27. # cause tags/b to be rebuilt.
  28. $oldtypedlinks{TypeAdd}{tag} = { "tags/a" => 1 };
  29. $typedlinks{TypeAdd}{tag} = { "tags/a" => 1, "tags/b" => 1 };
  30. $oldlinks{TypeRemove} = [qw{tags/a tags/b}];
  31. $links{TypeRemove} = [qw{tags/a tags/b}];
  32. # This causes TypeRemove to be rebuilt, but isn't a backlink change, so it
  33. # doesn't cause tags/b to be rebuilt.
  34. $oldtypedlinks{TypeRemove}{tag} = { "tags/a" => 1 };
  35. $typedlinks{TypeRemove}{tag} = { "tags/a" => 1, "tags/b" => 1 };
  36. my $oldlink_targets = calculate_old_links([keys %pagesources], []);
  37. is_deeply($oldlink_targets, {
  38. Reorder => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
  39. Add => { "tags/b" => "tags/b" },
  40. Remove => { "tags/a" => "tags/a" },
  41. TypeAdd => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
  42. TypeRemove => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
  43. });
  44. my ($backlinkchanged, $linkchangers) = calculate_changed_links([keys %pagesources], [], $oldlink_targets);
  45. is_deeply($backlinkchanged, { "tags/a" => 1 });
  46. is_deeply($linkchangers, { add => 1, remove => 1, typeadd => 1, typeremove => 1 });