]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/calculate_changed_links.t
bugfixes
[git.ikiwiki.info.git] / t / calculate_changed_links.t
1 #!/usr/bin/perl
2 package IkiWiki;
4 use warnings;
5 use strict;
6 use Test::More tests => 5;
8 BEGIN { use_ok("IkiWiki"); }
9 BEGIN { use_ok("IkiWiki::Render"); }
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
13 %oldrenderedfiles=%pagectime=();
14 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
15 %destsources=%renderedfiles=%pagecase=%pagestate=();
17 IkiWiki::checkconfig();
19 foreach my $page (qw(tags/a tags/b Reorder Add Remove TypeAdd TypeRemove)) {
20         $pagesources{$page} = "$page.mdwn";
21         $pagemtime{$page} = $pagectime{$page} = 1000000;
22 }
24 $oldlinks{Reorder} = [qw{tags/a tags/b}];
25 $links{Reorder} = [qw{tags/b tags/a}];
27 $oldlinks{Add} = [qw{tags/b}];
28 $links{Add} = [qw{tags/a tags/b}];
30 $oldlinks{Remove} = [qw{tags/a}];
31 $links{Remove} = [];
33 $oldlinks{TypeAdd} = [qw{tags/a tags/b}];
34 $links{TypeAdd} = [qw{tags/a tags/b}];
35 # This causes TypeAdd to be rebuilt, but isn't a backlink change, so it doesn't
36 # cause tags/b to be rebuilt.
37 $oldtypedlinks{TypeAdd}{tag} = { "tags/a" => 1 };
38 $typedlinks{TypeAdd}{tag} = { "tags/a" => 1, "tags/b" => 1 };
40 $oldlinks{TypeRemove} = [qw{tags/a tags/b}];
41 $links{TypeRemove} = [qw{tags/a tags/b}];
42 # This causes TypeRemove to be rebuilt, but isn't a backlink change, so it
43 # doesn't cause tags/b to be rebuilt.
44 $oldtypedlinks{TypeRemove}{tag} = { "tags/a" => 1 };
45 $typedlinks{TypeRemove}{tag} = { "tags/a" => 1, "tags/b" => 1 };
47 my $oldlink_targets = calculate_old_links([keys %pagesources], []);
48 is_deeply($oldlink_targets, {
49                 Reorder => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
50                 Add => { "tags/b" => "tags/b" },
51                 Remove => { "tags/a" => "tags/a" },
52                 TypeAdd => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
53                 TypeRemove => { "tags/a" => "tags/a", "tags/b" => "tags/b" },
54         });
55 my ($backlinkchanged, $linkchangers) = calculate_changed_links([keys %pagesources], [], $oldlink_targets);
57 is_deeply($backlinkchanged, { "tags/a" => 1 });
58 is_deeply($linkchangers, { add => 1, remove => 1, typeadd => 1, typeremove => 1 });