X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Nary.git;a=blobdiff_plain;f=t%2F15-misc-xs.t;fp=t%2F15-misc-xs.t;h=bd6baacc1d70327a48de9dd925ef61b9de0a9f4a;hp=0000000000000000000000000000000000000000;hb=1757c35d2d60dd9b52dcbd5af09679cfdaeb1740;hpb=84483a1d32823197ca6c6dcb5e839e8d5650e9e4 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');