Apply node() type tests to the document too.

When running XPath queries such as "self::node()" the result should be a set
containing the document itself. This in turn fixes expressions such as
descendant-or-self::node()/a.
This commit is contained in:
Yorick Peterse 2014-11-04 23:41:45 +01:00
parent 1f3b4cb2fb
commit 602f2fe8bb
2 changed files with 15 additions and 1 deletions

View File

@ -550,7 +550,9 @@ module Oga
nodes = XML::NodeSet.new
context.each do |node|
nodes << node if node.is_a?(XML::Node)
if node.is_a?(XML::Node) or node.is_a?(XML::Document)
nodes << node
end
end
return nodes

View File

@ -74,5 +74,17 @@ describe Oga::XPath::Evaluator do
@set[0].should == @document.children[0].children[1]
end
end
context 'matching the document itself' do
before do
@set = @evaluator.evaluate('self::node()')
end
it_behaves_like :node_set, :length => 1
example 'return the document itself' do
@set[0].is_a?(Oga::XML::Document).should == true
end
end
end
end