Release commit for 1.003001
[p5sagit/Eval-WithLexicals.git] / t / simple.t
CommitLineData
6f914695 1use strictures 1;
2use Test::More;
3use Eval::WithLexicals;
4
5my $eval = Eval::WithLexicals->new;
6
7is_deeply(
8 [ $eval->eval('my $x; $x++; $x;') ],
9 [ 1 ],
10 'Basic eval ok'
11);
12
13is_deeply(
14 $eval->lexicals, { '$x' => \1 },
15 'Lexical stored ok'
16);
17
18is_deeply(
19 [ $eval->eval('$x+1') ],
20 [ 2 ],
21 'Use lexical ok'
22);
23
24is_deeply(
25 [ $eval->eval('{ my $x = 0 }; $x') ],
26 [ 1 ],
27 'Inner scope plus lexical ok'
28);
29
40d8277f 30is_deeply(
31 [ $eval->eval('{ my $y = 0 }; $x') ],
32 [ 1 ],
33 'Inner scope and other lexical ok'
34);
35
4d546654 36is_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
44is_deeply(
45 [ $eval->eval('$y->(2)') ],
46 [ 3 ],
47 'Sub created ok'
48);
49
6f914695 50done_testing;