From f6319ed0c7507b1bba1f1f02a1f73fda9808b2f7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 4 Nov 2014 23:25:44 +0100 Subject: [PATCH] Added failing descendant-or-self XPath specs. These currently fail due to the child:: selector not working entirely as it should be. Consider the following XML: And the following XPath: descendant-or-self::node()/a In Nokogiri/libxml this will return a node set containing the node. In Oga however this will return an empty node set. This will require some further investigation to see what exactly is going on, and in particular what is the correct behaviour. --- .../evaluator/axes/descendant_or_self_spec.rb | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb b/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb index 081c988..5b9f8ca 100644 --- a/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb +++ b/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb @@ -40,6 +40,32 @@ describe Oga::XPath::Evaluator do end end + context 'chained descendants' do + before do + @set = @evaluator.evaluate( + 'descendant-or-self::a/descendant-or-self::*' + ) + end + + it_behaves_like :node_set, :length => 4 + + example 'return the node' do + @set[0].should == @first_a + end + + example 'return the first node' do + @set[1].should == @first_b + end + + example 'return the second node' do + @set[2].should == @second_b + end + + example 'return the node' do + @set[3].should == @first_c + end + end + context 'nested descendants with a matching predicate' do before do @set = @evaluator.evaluate('descendant-or-self::c[@class="x"]') @@ -139,5 +165,37 @@ describe Oga::XPath::Evaluator do @set[0].should == @first_c end end + + context 'descendants of descendants usign the short form' do + before do + @set = @evaluator.evaluate('//a//*') + end + + it_behaves_like :node_set, :length => 3 + + example 'return the first node' do + @set[0].should == @first_b + end + + example 'return the second node' do + @set[1].should == @second_b + end + + example 'return the node' do + @set[2].should == @first_c + end + end + + context 'children of descendants using the short form' do + before do + @set = @evaluator.evaluate('//a/b') + end + + it_behaves_like :node_set, :length => 1 + + example 'return the first node' do + @set[0].should == @first_b + end + end end end