From: Vincent Pit Date: Fri, 8 Aug 2008 22:07:53 +0000 (+0200) Subject: Move misc XS tests to t/15-misc-xs.t, including scalops tests. Simplify pp_rv2av X-Git-Tag: v0.03~2 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Nary.git;a=commitdiff_plain;h=1757c35d2d60dd9b52dcbd5af09679cfdaeb1740 Move misc XS tests to t/15-misc-xs.t, including scalops tests. Simplify pp_rv2av --- diff --git a/MANIFEST b/MANIFEST index 922c7e3..a6d62d3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -9,7 +9,7 @@ t/00-load.t t/02-can.t t/10-obj.t t/11-cache.t -t/15-scalops.t +t/15-misc-xs.t t/16-combine.t t/20-return.t t/21-list.t diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index ef92fa1..838fab0 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -446,12 +446,11 @@ sub pp_rv2av { my ($self, $op) = @_; $op = $op->first; - my ($r, $l) = $self->inspect($op); - if (name($op) ne 'const') { - my $c = 1 - count $r; - $l = $c ? { list => $c } : 0; + if (name($op) eq 'gv') { + return undef, { list => 1 }; } - return $r, $l; + + $self->inspect($op); } sub pp_aassign { diff --git a/t/15-misc-xs.t b/t/15-misc-xs.t new file mode 100644 index 0000000..bd6baac --- /dev/null +++ b/t/15-misc-xs.t @@ -0,0 +1,36 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 12; + +use Sub::Nary; + +my @scalops = Sub::Nary::scalops(); +my $nbr = Sub::Nary::scalops(); + +is($nbr, scalar @scalops, 'scalops return values in list/scalar context are consistent'); + +*normalize = *Sub::Nary::normalize{CODE}; + +is_deeply(normalize(1), { 1 => 1 }, 'normalize const'); +is_deeply(normalize({}), { 0 => 1 }, 'normalize empty-ref'); + +*scale = *Sub::Nary::scale{CODE}; + +is_deeply(scale(1, {}), { 0 => 1 }, 'scale const, empty-ref'); + +*add = *Sub::Nary::add{CODE}; + +is_deeply(add('list'), { list => 1 }, 'add list'); +is_deeply(add(1, 'list'), { list => 1 }, 'add const, list'); +is_deeply(add({ }, 'list'), { list => 1 }, 'add empty-ref, list'); +is_deeply(add({ 1 => 1 }, 'list'), { list => 1 }, 'add ref, list'); +is_deeply(add({ 1 => 1 }, 1), { 1 => 2 }, 'add ref, prev-const'); + +*cumulate = *Sub::Nary::cumulate{CODE}; + +is_deeply(cumulate('list', 1, 1), 'list', 'cumulate const, non-zero, non-zero'); +is_deeply(cumulate({ 1 => 1 }, 1, 0), { 1 => 1 }, 'cumulate ref, non-zero, zero'); +is_deeply(cumulate({ }, 1, 1), undef, 'cumulate empty-ref, non-zero, non-zero'); diff --git a/t/15-scalops.t b/t/15-scalops.t deleted file mode 100644 index 0efd039..0000000 --- a/t/15-scalops.t +++ /dev/null @@ -1,13 +0,0 @@ -#!perl -T - -use strict; -use warnings; - -use Test::More tests => 1; - -use Sub::Nary; - -my @scalops = Sub::Nary::scalops(); -my $nbr = Sub::Nary::scalops(); - -is($nbr, scalar @scalops, 'Sub::Nary::scalops return values in list/scalar context are consistent'); diff --git a/t/24-ops.t b/t/24-ops.t index a69cd0a..3bfe542 100644 --- a/t/24-ops.t +++ b/t/24-ops.t @@ -57,7 +57,7 @@ my @tests = ( [ sub { endprotoent }, 1 ], [ sub { endservent }, 1 ], - [ sub { <*.*> }, { list => 0.5, 1 => 0.5 } ], + [ sub { <*.*> }, 1 ], ); my $i = 1; diff --git a/t/25-grepmap.t b/t/25-grepmap.t index 06a4ddf..2a64d83 100644 --- a/t/25-grepmap.t +++ b/t/25-grepmap.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 31; +use Test::More tests => 32; use Sub::Nary; @@ -69,8 +69,9 @@ my @tests = ( [ sub { map { return $_ ? 2 : (3, 4) } do { return 3 .. 5 if $x; () } }, { 3 => 0.5, 0 => 0.5 } ], - [ sub { grep { 1 } 1 .. 10 }, 'list' ], - [ sub { grep { 1 } @_ }, 'list' ], + [ sub { grep { 1 } 1 .. 10 }, 'list' ], + [ sub { grep { 1 } @_ }, 'list' ], + [ sub { grep { 1 } () }, 0 ], [ sub { map { $_ } 1 .. 3 }, 3 ], [ sub { map { () } @_ }, 0 ],