6 use Test::More tests => (3 + 3) * 5 + 1;
10 sub add { $_[0] + $_[1] }
11 sub mul { $_[0] * $_[1] }
12 sub fma { add mul($_[0], $_[1]), $_[2] }
13 sub wut { fma $_[0], 2, $_[1] }
16 my ($brd, $yes, $no, $l) = @_;
17 my $code = $brd->coderef2text(\&wut);
19 like($code, qr/\b$_\b/, "expansion at level $l contains $_");
22 unlike($code, qr/\b$_\b/, "expansion at level $l does not contain $_");
24 $code = eval 'sub ' . $code;
25 is($@, '', "result compiles at level $l");
26 is_deeply( [ defined $code, ref $code ], [ 1, 'CODE' ], "result compiles to a code reference at level $l");
27 is($code->(1, 3), wut(1, 3), "result compiles to the good thing at level $l");
30 my $br_args = '-sCi0v1';
32 my $brd = B::RecDeparse->new(deparse => [ $br_args ], level => -1);
33 which $brd, [ ], [ qw<add mul fma> ], -1;
35 $brd = B::RecDeparse->new(deparse => [ $br_args ], level => 0);
36 which $brd, [ qw<fma> ], [ qw<add mul> ], 0;
38 $brd = B::RecDeparse->new(deparse => [ $br_args ], level => 1);
39 which $brd, [ qw<add mul> ], [ qw<fma> ], 1;
41 $brd = B::RecDeparse->new(deparse => [ $br_args ], level => 2);
42 which $brd, [ ], [ qw<add mul fma> ], 2;
44 $brd = B::RecDeparse->new(deparse => [ $br_args ], level => 3);
45 which $brd, [ ], [ qw<add mul fma> ], 2;
47 sub fakegv { return @_ }
48 eval { $brd->coderef2text(sub { return fakegv() }) };
49 is($@, '', 'don\'t croak on non-CV GV\'s at level >= 1');