1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/perl
# Unit testing for PPI::Statement::Variable
use lib 't/lib';
use PPI::Test::pragmas;
use Test::More tests => 18 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
use PPI ();
use Helper 'safe_new';
VARIABLES: {
# Test the things we assert to work in the synopsis
my $Document = safe_new \<<'END_PERL';
package Bar;
my $foo = 1;
my ( $foo, $bar) = (1, 2);
our $foo = 1;
local $foo;
local $foo = 1;
LABEL: my $foo = 1;
# As well as those basics, lets also try some harder ones
local($foo = $bar->$bar(), $bar);
END_PERL
# There should be 6 statement objects
my $ST = $Document->find('Statement::Variable');
is( ref($ST), 'ARRAY', 'Found statements' );
is( scalar(@$ST), 7, 'Found 7 ::Variable objects' );
foreach my $Var ( @$ST ) {
isa_ok( $Var, 'PPI::Statement::Variable' );
}
is_deeply( [ $ST->[0]->variables ], [ '$foo' ], '1: Found $foo' );
is_deeply( [ $ST->[1]->variables ], [ '$foo', '$bar' ], '2: Found $foo and $bar' );
is_deeply( [ $ST->[2]->variables ], [ '$foo' ], '3: Found $foo' );
is_deeply( [ $ST->[3]->variables ], [ '$foo' ], '4: Found $foo' );
is_deeply( [ $ST->[4]->variables ], [ '$foo' ], '5: Found $foo' );
is_deeply( [ $ST->[5]->variables ], [ '$foo' ], '6: Found $foo' );
is_deeply( [ $ST->[6]->variables ], [ '$foo', '$bar' ], '7: Found $foo and $bar' );
}
|