summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2009-08-12 18:05:56 +0200
committerdakkar <dakkar@thenautilus.net>2009-08-12 18:05:56 +0200
commit37b4676a0b65649748d9001d7c3f52ec6d2bbf9b (patch)
tree8ae81a42e3066bff2928fb8eab60fec625c60c51 /t
parentadded back-compatibility (diff)
downloadPPIx-XPath-37b4676a0b65649748d9001d7c3f52ec6d2bbf9b.tar.gz
PPIx-XPath-37b4676a0b65649748d9001d7c3f52ec6d2bbf9b.tar.bz2
PPIx-XPath-37b4676a0b65649748d9001d7c3f52ec6d2bbf9b.zip
added lots of attributes
now most PPI classes export their attributes; there is also some protection against exceptions in accessors
Diffstat (limited to 't')
-rw-r--r--t/03-advanced.t40
1 files changed, 40 insertions, 0 deletions
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');
+}