Commit | Line | Data |
6f914695 |
1 | use strictures 1; |
2 | use Test::More; |
3 | use Eval::WithLexicals; |
4 | |
5 | my $eval = Eval::WithLexicals->new; |
6 | |
7 | is_deeply( |
8 | [ $eval->eval('my $x; $x++; $x;') ], |
9 | [ 1 ], |
10 | 'Basic eval ok' |
11 | ); |
12 | |
13 | is_deeply( |
14 | $eval->lexicals, { '$x' => \1 }, |
15 | 'Lexical stored ok' |
16 | ); |
17 | |
18 | is_deeply( |
19 | [ $eval->eval('$x+1') ], |
20 | [ 2 ], |
21 | 'Use lexical ok' |
22 | ); |
23 | |
24 | is_deeply( |
25 | [ $eval->eval('{ my $x = 0 }; $x') ], |
26 | [ 1 ], |
27 | 'Inner scope plus lexical ok' |
28 | ); |
29 | |
40d8277f |
30 | is_deeply( |
31 | [ $eval->eval('{ my $y = 0 }; $x') ], |
32 | [ 1 ], |
33 | 'Inner scope and other lexical ok' |
34 | ); |
35 | |
4d546654 |
36 | is_deeply( |
37 | [ keys %{$eval->lexicals} ], |
38 | [ '$x' ], |
39 | 'No capture of invisible $y' |
40 | ); |
41 | |
4a3d69ab |
42 | $eval->eval('my $y = sub { $_[0]+1 }'); |
43 | |
44 | is_deeply( |
45 | [ $eval->eval('$y->(2)') ], |
46 | [ 3 ], |
47 | 'Sub created ok' |
48 | ); |
49 | |
6f914695 |
50 | done_testing; |