From: Vincent Pit Date: Sat, 11 Sep 2010 23:44:38 +0000 (+0200) Subject: Test C::D::G::Atom->fold X-Git-Tag: v0.11~16 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=3a6840c4ec1f85e05975608542b33a53eacbfac1;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Test C::D::G::Atom->fold And make it sort the returned atoms. --- diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index b58ebc3..59f1d6a 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -295,7 +295,7 @@ sub fold { $seen{$key} = defined $cur ? $cur->and($atom) : $atom; } - return values %seen; + return map $seen{$_}, sort keys %seen; } =pod diff --git a/t/32-atom-and.t b/t/32-atom-and.t index 22ceb81..4fff4bb 100644 --- a/t/32-atom-and.t +++ b/t/32-atom-and.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2 * (2 + (8 * 7) / 2 + 2); +use Test::More tests => 2 * (2 + (8 * 7) / 2 + 2) + 3 * 4; use CPANPLUS::Dist::Gentoo::Atom; @@ -123,3 +123,41 @@ for my $t (@tests) { } } } + +my $a1b = A->new( + category => 'test', + name => 'a', + version => '1.0', +); + +my $b1 = A->new( + category => 'test', + name => 'b', + version => '1.0', + range => '<', +); + +my $b2 = A->new( + category => 'test', + name => 'b', + version => '3.0', + range => '<', +); + +my @folded = eval { A->fold($a1b, $a5, $b1, $b2) }; +is $@, '', 'aabb: no error'; +is @folded, 2, 'aabb: fold results in two atoms'; +ok $folded[0] == $a5, 'aabb: first result is >=test/a-2.0'; +ok $folded[1] == $b1, 'aabb: second result is fold($a1b, $b1, $b2, $a5) }; +is $@, '', 'abba: no error'; +is @folded, 2, 'abba: fold results in two atoms'; +ok $folded[0] == $a5, 'abba: first result is >=test/a-2.0'; +ok $folded[1] == $b1, 'abba: second result is fold($a1b, $b1, $a5, $b2) }; +is $@, '', 'abab: no error'; +is @folded, 2, 'abab: fold results in two atoms'; +ok $folded[0] == $a5, 'abab: first result is >=test/a-2.0'; +ok $folded[1] == $b1, 'abab: second result is