8 use blib 't/Sub-Op-LexicalSub';
10 use Test::More tests => 1 * 11 + 3 * 12 + 2 * 18 + 4;
13 my %hash = (a => 'b');
23 my ($code, $params) = split /----\s*/, $_;
24 my ($names, $ret, $exp, $seq) = split /\s*#\s*/, $params;
26 my @names = split /\s*,\s*/, $names;
28 for my $i (0 .. $#names) {
29 my $name = $names[$i];
30 if ($name =~ /^\s*([^\s\(]+)\s*(\([^\)]*\))\s*$/) {
38 fail "@names: unable to get expected values: $@";
45 s/^\s*//, s/\s*$// for $seq;
46 @seq = split /\s*,\s*/, $seq;
47 die "calls and seq length mismatch" unless @seq == $calls;
49 @seq = ($names[0]) x $calls;
53 for my $i (0 .. $#names) {
54 my $name = $names[$i];
55 my $proto = $protos[$i] // '';
57 use Sub::Op::LexicalSub $name => sub $proto {
59 my \$exp = shift \@exp;
60 is_deeply \\\@_, \$exp, '$name: arguments are correct';
61 my \$seq = shift \@seq;
62 is \$seq, '$name', '$name: sequence is correct';
67 $test .= "{\n$code\n}\n";
68 for my $name (@names) {
69 $test .= <<" CHECK_VIVID"
71 no warnings 'uninitialized'; # Test::Builder can't get the file name
72 ok !exists &main::${name}, '$name: not stubbed';
73 ok !defined &main::${name}, '$name: body not defined';
74 is *main::${name}\{CODE\}, undef, '$name: empty symbol table entry';
83 fail "@names: unable to evaluate test case: $@";
87 is $called, $calls, "@names: the hook was called the right number of times";
88 if ($called < $calls) {
89 fail, fail for $called + 1 .. $calls;
96 use Sub::Op::LexicalSub foo => sub (&) { $_[0]->() };
97 foo { pass 'block called'; };
104 use Sub::Op::LexicalSub foo => sub (&@) { my $cb = shift; goto &$cb };
105 foo { is_deeply \@_, [ ], 'block called without arguments' };
106 foo { is_deeply \@_, [ 1 ], 'block called without 1 argument' } 1;
107 foo { is_deeply \@_, [ 2, 3 ], 'block called without 2 argument' } 2, 3;
129 my @stuff = (foo 3, 4);
135 foo($) # () # [ scalar @array ]
137 my @stuff = (foo 5, 6);
139 @stuff = (foo 9, 10);
141 foo($), bar($$) # () # [ 5 ], [ 7, 8 ], [ 9 ] # foo, bar, foo
145 foo(\@) # () # [ \@array ]
150 foo(\[@%]) # () # [ \@array ], [ \%hash ]
155 foo(\[@%]$) # () # [ \@array, 13 ], [ \%hash, 14 ]
162 foo(\[@%];$) # () # [ \@array ], [ \@array, 15 ], [ \%hash ], [ \%hash, 16 ]