6 use Test::More tests => 3 + 14 + (($^V ge v5.10.0) ? 4 : 0);
8 use Scalar::Util qw/set_prototype/;
9 use Sub::Prototype::Util qw/recall/;
11 eval { recall undef };
12 like($@, qr/^Wrong\s+subroutine/, 'recall undef croaks');
14 like($@, qr/^Wrong\s+subroutine/, 'recall "" croaks');
15 eval { recall 'hlagh' };
16 like($@, qr/^Undefined\s+subroutine/, 'recall <unknown> croaks');
18 sub noproto { $_[1], $_[0] }
19 sub mytrunc ($;$) { $_[1], $_[0] }
20 sub mygrep1 (&@) { grep { $_[0]->() } @_[1 .. $#_] }
21 sub mygrep2 (\&@) { grep { $_[0]->() } @_[1 .. $#_] }
22 sub modify ($) { my $old = $_[0]; $_[0] = 5; $old }
24 my $t = [ 1, 2, 3, 4 ];
25 my $g = [ sub { $_ > 2 }, 1 .. 5 ];
28 [ 'main::noproto', 'no prototype', $t, $t, [ 2, 1 ] ],
29 [ 'CORE::push', 'push', [ [ 1, 2 ], 3, 5 ], [ [ 1, 2, 3, 5 ], 3, 5 ], [ 4 ] ],
30 [ 'main::mytrunc', 'truncate 1', [ 1 ], [ 1 ], [ undef, 1 ] ],
31 [ 'main::mytrunc', 'truncate 2', $t, $t, [ 2, 1 ] ],
32 [ 'main::mygrep1', 'grep1', $g, $g, [ 3 .. 5 ] ],
33 [ 'main::mygrep2', 'grep2', $g, $g, [ 3 .. 5 ] ],
34 [ 'main::modify', 'modify arguments', [ 1 ], [ 5 ], [ 1 ] ],
37 sub myit { push @{$_[0]->[2]}, 3; return 4 };
39 set_prototype \&myit, '_';
40 push @tests, [ 'main::myit', '_ with argument',
42 [ [ 1, 2, [ 3 ] ], 5 ],
45 push @tests, [ 'main::myit', '_ with no argument', [ ], [ 3 ], [ 4 ] ];
49 my $r = [ recall $_->[0], @{$_->[2]} ];
50 is_deeply($r, $_->[4], $_->[1] . ' return value');
51 is_deeply($_->[2], $_->[3], $_->[1] . ' arguments modification');