aboutsummaryrefslogtreecommitdiff
path: root/t/pedigree.t
diff options
context:
space:
mode:
Diffstat (limited to 't/pedigree.t')
-rwxr-xr-xt/pedigree.t109
1 files changed, 18 insertions, 91 deletions
diff --git a/t/pedigree.t b/t/pedigree.t
index aa78cbe67..74871cfa8 100755
--- a/t/pedigree.t
+++ b/t/pedigree.t
@@ -24,61 +24,15 @@ $expected{'pedigree'} =
{
"" => [],
"ikiwiki" => [],
- "ikiwiki/pagespec" => [
- {absdepth => 0,
- distance => 2,
- is_root => 1,
- is_second_ancestor => '',
- is_grand_mother => 1,
- is_mother => '',
- },
- {absdepth => 1,
- distance => 1,
- is_root => '',
- is_second_ancestor => 1,
- is_grand_mother => '',
- is_mother => 1,
- },
- ],
- "ikiwiki/pagespec/attachment" => [
- {absdepth => 0,
- distance => 3,
- is_root => 1,
- is_second_ancestor => '',
- is_grand_mother => '',
- is_mother => '',
- },
- {absdepth => 1,
- distance => 2,
- is_root => '',
- is_second_ancestor => 1,
- is_grand_mother => 1,
- is_mother => '',
- },
- {absdepth => 2,
- distance => 1,
- is_root => '',
- is_second_ancestor => '',
- is_grand_mother => '',
- is_mother => 1,
- },
- ],
- };
-
-$expected{'pedigree_but_root'} =
- {
- "" => [],
- "ikiwiki" => [],
- "ikiwiki/pagespec" => [],
- "ikiwiki/pagespec/attachment" => [],
- };
-
-$expected{'pedigree_but_two_oldest'} =
- {
- "" => [],
- "ikiwiki" => [],
- "ikiwiki/pagespec" => [],
- "ikiwiki/pagespec/attachment" => [],
+ "ikiwiki/pagespec" =>
+ [ {depth => 0, height => 2, },
+ {depth => 1, height => 1, },
+ ],
+ "ikiwiki/pagespec/attachment" =>
+ [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
+ {depth => 1, height => 2, },
+ {depth => 2, height => 1, },
+ ],
};
# Test function
@@ -87,15 +41,6 @@ sub test_loop($$) {
my $expected=shift;
my $template;
my %params;
- my $offset;
-
- if ($loop eq 'pedigree') {
- $offset=0;
- } elsif ($loop eq 'pedigree_but_root') {
- $offset=1;
- } elsif ($loop eq 'pedigree_but_two_oldest') {
- $offset=2;
- }
ok($template=template('pedigree.tmpl'), "template created");
ok($params{template}=$template, "params populated");
@@ -103,12 +48,6 @@ sub test_loop($$) {
while ((my $page, my $exp) = each %{$expected}) {
my @path=(split("/", $page));
my $pagedepth=@path;
- my $expdepth;
- if (($pagedepth - $offset) >= 0) {
- $expdepth=$pagedepth - $offset;
- } else {
- $expdepth=0;
- }
my $msgprefix="$page $loop";
# manually run the plugin hook
@@ -117,28 +56,18 @@ sub test_loop($$) {
IkiWiki::Plugin::pedigree::pagetemplate(%params);
my $res=$template->param($loop);
- is(scalar(@$res), $expdepth, "$msgprefix: path length");
+ is(scalar(@$res), $pagedepth, "$msgprefix: path length");
# logic & arithmetic validation tests
- for (my $i=0; $i<$expdepth; $i++) {
+ for (my $i=0; $i<$pagedepth; $i++) {
my $r=$res->[$i];
- is($r->{distance}, $pagedepth - $r->{absdepth},
- "$msgprefix\[$i\]: distance = pagedepth - absdepth");
- ok($r->{absdepth} ge 0, "$msgprefix\[$i\]: absdepth>=0");
- ok($r->{distance} ge 0, "$msgprefix\[$i\]: distance>=0");
- unless ($loop eq 'pedigree') {
- ok($r->{reldepth} ge 0, "$msgprefix\[$i\]: reldepth>=0");
- TODO: {
- local $TODO = "Known bug" if
- (($loop eq 'pedigree_but_root')
- && ($i >= $offset));
- is($r->{reldepth} + $offset, $r->{absdepth},
- "$msgprefix\[$i\]: reldepth+offset=absdepth");
- }
- }
+ is($r->{height}, $pagedepth - $r->{depth},
+ "$msgprefix\[$i\]: height = pagedepth - depth");
+ ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
+ ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
}
# comparison tests, iff the test-suite has been written
- if (scalar(@$exp) eq $expdepth) {
- for (my $i=0; $i<$expdepth; $i++) {
+ if (scalar(@$exp) eq $pagedepth) {
+ for (my $i=0; $i<$pagedepth; $i++) {
my $e=$exp->[$i];
my $r=$res->[$i];
map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
@@ -151,6 +80,4 @@ sub test_loop($$) {
}
# Main
-map {
- test_loop($_, $expected{$_});
-} ('pedigree', 'pedigree_but_root', 'pedigree_but_two_oldest');
+test_loop('pedigree', $expected{'pedigree'});