From: Vincent Pit Date: Tue, 5 Aug 2008 10:30:57 +0000 (+0200) Subject: keys/values return a 'list', each return zero or two scalars X-Git-Tag: v0.02~7 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=08ec5acb4cc88d8cc10fec0520d8cd075c08fda1;p=perl%2Fmodules%2FSub-Nary.git keys/values return a 'list', each return zero or two scalars --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 4a02bc2..eb26dfc 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -204,6 +204,7 @@ $ops{$_} = 1 for qw/padsv/; $ops{$_} = 'list' for qw/padav/; $ops{$_} = 'list' for qw/padhv rv2hv/; $ops{$_} = 'list' for qw/padany flip match entereval readline/; +$ops{each} = { 0 => 0.5, 2 => 0.5 }; $ops{stat} = { 0 => 0.5, 13 => 0.5 }; $ops{caller} = sub { my @a = caller 0; scalar @a }->(); $ops{localtime} = do { my @a = localtime; scalar @a }; diff --git a/t/20-return.t b/t/20-return.t index b47babb..98fecc9 100644 --- a/t/20-return.t +++ b/t/20-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 53; +use Test::More tests => 55; use Sub::Nary; @@ -39,6 +39,8 @@ my @tests = ( [ sub { return @h{qw/a b/} }, 2 ], [ sub { return @h{@a[1 .. 3]} }, 3 ], [ sub { return @h{@a[$y .. 3]} }, 'list' ], + [ sub { return keys %h }, 'list' ], + [ sub { return values %h }, 'list' ], [ sub { return $x, $a[3], $h{c} }, 3 ], [ sub { return $x, @a }, 'list' ], diff --git a/t/21-list.t b/t/21-list.t index 4f97358..62c9bc0 100644 --- a/t/21-list.t +++ b/t/21-list.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 39; +use Test::More tests => 41; use Sub::Nary; @@ -33,6 +33,8 @@ my @tests = ( [ sub { %h }, 'list' ], [ sub { $h{a} }, 1 ], [ sub { @h{qw/a b/} }, 2 ], + [ sub { keys %h }, 'list' ], + [ sub { values %h }, 'list' ], [ sub { $x, $a[3], $h{c} }, 3 ], [ sub { $x, @a }, 'list' ], diff --git a/t/23-branch.t b/t/23-branch.t index 914b975..72451e4 100644 --- a/t/23-branch.t +++ b/t/23-branch.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 17; use Sub::Nary; @@ -60,8 +60,10 @@ my @tests = ( [ \&retinif, { 2 => 1 } ], - [ sub { <*.*> }, { list => 1 / 3, 1 => 2 / 3 } ], + [ sub { each %h }, { 0 => 0.5, 2 => 0.5 } ], [ sub { stat $0 }, { 0 => 0.5, 13 => 0.5 } ], + + [ sub { <*.*> }, { list => 1 / 3, 1 => 2 / 3 } ], ); my $i = 1;