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:
parent
1f3b4cb2fb
commit
602f2fe8bb
|
@ -550,7 +550,9 @@ module Oga
|
||||||
nodes = XML::NodeSet.new
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
context.each do |node|
|
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
|
end
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
|
@ -74,5 +74,17 @@ describe Oga::XPath::Evaluator do
|
||||||
@set[0].should == @document.children[0].children[1]
|
@set[0].should == @document.children[0].children[1]
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue