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:

    <a><b><b><c class="x"></c></b></b></a>

And the following XPath:

    descendant-or-self::node()/a

In Nokogiri/libxml this will return a node set containing the <a> 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.
This commit is contained in:
Yorick Peterse 2014-11-04 23:25:44 +01:00
parent 83e6138f2f
commit f6319ed0c7
1 changed files with 58 additions and 0 deletions

View File

@ -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 <a> node' do
@set[0].should == @first_a
end
example 'return the first <b> node' do
@set[1].should == @first_b
end
example 'return the second <b> node' do
@set[2].should == @second_b
end
example 'return the <c> 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 <b> node' do
@set[0].should == @first_b
end
example 'return the second <b> node' do
@set[1].should == @second_b
end
example 'return the <c> 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 <b> node' do
@set[0].should == @first_b
end
end
end
end