summaryrefslogtreecommitdiff
path: root/t/03-advanced.t
blob: 4f46757d5d0456ce91d2e4db4d34196a25e5c500 (plain)
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
#!perl 
use Test::Most tests=>6,'die';
use strict;
use warnings;
use PPI;
use PPIx::XPath;
use Tree::XPathEngine;
 
my $x=PPI::Document->new(\<<'EOF');
sub foo { print "bar" }
 
sub baz { print "boo"; foo() };
 
baz();
EOF
 
my $e=Tree::XPathEngine->new();
 
#explain('the doc: ',$x); 
 
{
my @subdefs = $e->findnodes('/Statement-Sub',$x);
is_deeply([sort map {$_->name} @subdefs],[qw(baz foo)],'Got the two sub');
}
{
my ($subdef) = $e->findnodes('/Statement-Sub[@name="foo"]',$x);
is($subdef->name,'foo','Got the sub by name');
}
 
{
my ($string,@rest) = $e->findnodes('/Statement-Sub[@name="foo"]//Statement[Token-Word="print"]/Token-Quote-Double',$x);
is($string->string,'bar','Got the string');
is(scalar(@rest),0,'and nothing more');
}
 
{
my ($call,@rest) = $e->findnodes('/Statement-Sub//Statement[Token-Word and Structure-List[count(*)=0]]',$x);
is("$call",'foo()','Got the call');
is(scalar(@rest),0,'and nothing more');
}