From 37b4676a0b65649748d9001d7c3f52ec6d2bbf9b Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 12 Aug 2009 18:05:56 +0200 Subject: added lots of attributes now most PPI classes export their attributes; there is also some protection against exceptions in accessors --- t/03-advanced.t | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 t/03-advanced.t (limited to 't/03-advanced.t') diff --git a/t/03-advanced.t b/t/03-advanced.t new file mode 100644 index 0000000..4f46757 --- /dev/null +++ b/t/03-advanced.t @@ -0,0 +1,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'); +} -- cgit v1.2.3