diff options
author | intrigeri <intrigeri@boum.org> | 2008-07-15 12:35:12 +0200 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2008-07-15 13:06:52 +0200 |
commit | 55000fd779816fa059e51e9fd01c7e6772b8efc7 (patch) | |
tree | 916494c8989bab7a6cce88c52ac0abc886696dcc /t | |
parent | 9b8ba60daccb186631e54c2f1af6a29701129bcb (diff) | |
download | ikiwiki-55000fd779816fa059e51e9fd01c7e6772b8efc7.tar ikiwiki-55000fd779816fa059e51e9fd01c7e6772b8efc7.tar.gz |
pedigree: rewrote with different design
(and updated testsuite + docs accordingly)
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 't')
-rwxr-xr-x | t/pedigree.t | 109 | ||||
-rw-r--r-- | t/pedigree/templates/pedigree.tmpl | 6 |
2 files changed, 18 insertions, 97 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'}); diff --git a/t/pedigree/templates/pedigree.tmpl b/t/pedigree/templates/pedigree.tmpl index 3590244ee..5fa25733a 100644 --- a/t/pedigree/templates/pedigree.tmpl +++ b/t/pedigree/templates/pedigree.tmpl @@ -2,9 +2,3 @@ <TMPL_LOOP NAME="PEDIGREE"> </TMPL_LOOP> - -<TMPL_LOOP NAME="PEDIGREE_BUT_ROOT"> -</TMPL_LOOP> - -<TMPL_LOOP NAME="PEDIGREE_BUT_TWO_OLDEST"> -</TMPL_LOOP> |