From 7e1910fc97ac3849d32fc8749862e8bf51ae8dbe Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 27 Jun 2009 13:56:17 +0200 Subject: non-working test, PPIx::XPath is quite broken --- t/07-class-xpath.t | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 t/07-class-xpath.t diff --git a/t/07-class-xpath.t b/t/07-class-xpath.t new file mode 100644 index 0000000..891ddff --- /dev/null +++ b/t/07-class-xpath.t @@ -0,0 +1,53 @@ +#!perl +package main; +use Test::Most 'die'; +BEGIN { + eval 'use PPIx::XPath'; + plan skip_all => 'PPIx::XPath needed for this test' if $@; +} + +package CXpEngine; { +use PPIx::XPath; +sub new { bless {},shift } +sub findnodes { + my ($self,$expr,$node)=@_; + return PPIx::XPath->new($node)->match($expr); +} +} + +package PPITransform;{ + use Tree::Transform::XSLTish ':engine'; + use strict; + use warnings; + + engine_class 'CXpEngine'; + + default_rules; + + tree_rule match => '//Statement::Sub', action => sub { + return $_[0]->it->name.'('.$_[0]->it->prototype.')'; + }; + +} + +package main; +use strict; +use warnings; +use PPI; +plan tests=>1; + +{ +my $doc=PPI::Document->new(\<<'EOP'); +sub gino($%) {} +sub pino {} + +gino(\&pino,{1=>2}); +EOP + +my $x=PPIx::XPath->new($doc); +diag "$_\n" for $x->match('//Statement::Sub'); + +my $trans=PPITransform->new(); +my @results=$trans->transform($doc); +is_deeply \@results,['gino($%)','pino'],'PPI example'; +} -- cgit v1.2.3 From 16541cf3bbf59460b1e0839bc18f08b3c75dd1ed Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 28 Jun 2009 09:17:07 +0200 Subject: still broken --- t/07-class-xpath.t | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/t/07-class-xpath.t b/t/07-class-xpath.t index 891ddff..9aa8040 100644 --- a/t/07-class-xpath.t +++ b/t/07-class-xpath.t @@ -13,6 +13,10 @@ sub findnodes { my ($self,$expr,$node)=@_; return PPIx::XPath->new($node)->match($expr); } + +sub PPI::Document::parent { + return $_[0]; +} } package PPITransform;{ @@ -22,9 +26,17 @@ package PPITransform;{ engine_class 'CXpEngine'; - default_rules; + #default_rules; + tree_rule match => '/', priority => 0, action => sub { + print '# root'; + $_[0]->apply_rules + }; + tree_rule match => '*', priority => 0, action => sub { + print '# ',$_[0]->it->xpath; + $_[0]->apply_rules + }; - tree_rule match => '//Statement::Sub', action => sub { + tree_rule match => 'Statement::Sub', action => sub { return $_[0]->it->name.'('.$_[0]->it->prototype.')'; }; @@ -34,6 +46,8 @@ package main; use strict; use warnings; use PPI; +use Devel::TraceCalls; + plan tests=>1; { @@ -48,6 +62,13 @@ my $x=PPIx::XPath->new($doc); diag "$_\n" for $x->match('//Statement::Sub'); my $trans=PPITransform->new(); +#trace_calls { +# Package => 'PPIx::XPath', +# Class => 'PPI::Node', +# ShowStack => 1, +# CaptureAll => 1, +#}; + my @results=$trans->transform($doc); is_deeply \@results,['gino($%)','pino'],'PPI example'; } -- cgit v1.2.3 From 446265157644e77d08b7df515815c7f3cdc2d481 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 28 Jun 2009 11:31:00 +0200 Subject: won't use PPIx::Class 1.x, it's too broken we'll try to have PPIx::Class 2.x accepted by the author --- t/07-class-xpath.t | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/t/07-class-xpath.t b/t/07-class-xpath.t index 9aa8040..7702993 100644 --- a/t/07-class-xpath.t +++ b/t/07-class-xpath.t @@ -2,42 +2,19 @@ package main; use Test::Most 'die'; BEGIN { - eval 'use PPIx::XPath'; - plan skip_all => 'PPIx::XPath needed for this test' if $@; -} - -package CXpEngine; { -use PPIx::XPath; -sub new { bless {},shift } -sub findnodes { - my ($self,$expr,$node)=@_; - return PPIx::XPath->new($node)->match($expr); -} - -sub PPI::Document::parent { - return $_[0]; -} + eval 'use PPIx::XPath 2.00'; + plan skip_all => 'PPIx::XPath 2.00 needed for this test' if $@; } package PPITransform;{ - use Tree::Transform::XSLTish ':engine'; + use Tree::Transform::XSLTish; use strict; use warnings; - engine_class 'CXpEngine'; + default_rules; - #default_rules; - tree_rule match => '/', priority => 0, action => sub { - print '# root'; - $_[0]->apply_rules - }; - tree_rule match => '*', priority => 0, action => sub { - print '# ',$_[0]->it->xpath; - $_[0]->apply_rules - }; - - tree_rule match => 'Statement::Sub', action => sub { - return $_[0]->it->name.'('.$_[0]->it->prototype.')'; + tree_rule match => 'Statement-Sub', action => sub { + return $_[0]->it->name.$_[0]->it->prototype; }; } @@ -46,7 +23,6 @@ package main; use strict; use warnings; use PPI; -use Devel::TraceCalls; plan tests=>1; @@ -58,16 +34,7 @@ sub pino {} gino(\&pino,{1=>2}); EOP -my $x=PPIx::XPath->new($doc); -diag "$_\n" for $x->match('//Statement::Sub'); - my $trans=PPITransform->new(); -#trace_calls { -# Package => 'PPIx::XPath', -# Class => 'PPI::Node', -# ShowStack => 1, -# CaptureAll => 1, -#}; my @results=$trans->transform($doc); is_deeply \@results,['gino($%)','pino'],'PPI example'; -- cgit v1.2.3 From bafdd1bf402e0970facd7fdb29438596621dcd52 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 28 Jun 2009 11:32:05 +0200 Subject: rename, since we're not actually using Class::XPath --- t/07-class-xpath.t | 41 ----------------------------------------- t/07-ppix-class.t | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 t/07-class-xpath.t create mode 100644 t/07-ppix-class.t diff --git a/t/07-class-xpath.t b/t/07-class-xpath.t deleted file mode 100644 index 7702993..0000000 --- a/t/07-class-xpath.t +++ /dev/null @@ -1,41 +0,0 @@ -#!perl -package main; -use Test::Most 'die'; -BEGIN { - eval 'use PPIx::XPath 2.00'; - plan skip_all => 'PPIx::XPath 2.00 needed for this test' if $@; -} - -package PPITransform;{ - use Tree::Transform::XSLTish; - use strict; - use warnings; - - default_rules; - - tree_rule match => 'Statement-Sub', action => sub { - return $_[0]->it->name.$_[0]->it->prototype; - }; - -} - -package main; -use strict; -use warnings; -use PPI; - -plan tests=>1; - -{ -my $doc=PPI::Document->new(\<<'EOP'); -sub gino($%) {} -sub pino {} - -gino(\&pino,{1=>2}); -EOP - -my $trans=PPITransform->new(); - -my @results=$trans->transform($doc); -is_deeply \@results,['gino($%)','pino'],'PPI example'; -} diff --git a/t/07-ppix-class.t b/t/07-ppix-class.t new file mode 100644 index 0000000..7702993 --- /dev/null +++ b/t/07-ppix-class.t @@ -0,0 +1,41 @@ +#!perl +package main; +use Test::Most 'die'; +BEGIN { + eval 'use PPIx::XPath 2.00'; + plan skip_all => 'PPIx::XPath 2.00 needed for this test' if $@; +} + +package PPITransform;{ + use Tree::Transform::XSLTish; + use strict; + use warnings; + + default_rules; + + tree_rule match => 'Statement-Sub', action => sub { + return $_[0]->it->name.$_[0]->it->prototype; + }; + +} + +package main; +use strict; +use warnings; +use PPI; + +plan tests=>1; + +{ +my $doc=PPI::Document->new(\<<'EOP'); +sub gino($%) {} +sub pino {} + +gino(\&pino,{1=>2}); +EOP + +my $trans=PPITransform->new(); + +my @results=$trans->transform($doc); +is_deeply \@results,['gino($%)','pino'],'PPI example'; +} -- cgit v1.2.3