-
Notifications
You must be signed in to change notification settings - Fork 8
/
08-getallvariabledeclarations.t
45 lines (34 loc) · 1.04 KB
/
08-getallvariabledeclarations.t
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
43
44
45
#!/usr/bin/perl
# Test for RT #63107: Finding declared variables fragile and misses loop variables
# Courtesy of Ovid++
use strict;
use warnings;
use Test::Most 'no_plan';
use PPI;
use PPIx::EditorTools;
diag "PPI version is $PPI::VERSION";
my $code = <<'END_OF_CODE';
use warnings;
foreach my $arg (@ARGV) {
print $arg;
}
END_OF_CODE
# Test finding variable declaration when on the variable
my $declarations;
lives_ok {
$declarations = PPIx::EditorTools::get_all_variable_declarations( PPI::Document->new( \$code ) );
}
'We should be able to find variable declarations';
explain $declarations;
ok exists $declarations->{lexical}{'$arg'}, '... and we should be able to find loop variables';
$code = <<'END_OF_CODE';
foreach my $arg (@ARGV) {
print $arg;
}
END_OF_CODE
lives_ok {
$declarations = PPIx::EditorTools::get_all_variable_declarations( PPI::Document->new( \$code ) );
}
'We should be able to find variable declarations';
explain $declarations;
ok exists $declarations->{lexical}{'$arg'}, '... and we should be able to find loop variables';