Support for the XPath "self" axis.
This commit is contained in:
parent
669ad25000
commit
26d4bdc5b1
|
|
@ -381,6 +381,23 @@ module Oga
|
||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Evaluates the `self` axis.
|
||||||
|
#
|
||||||
|
# @param [Oga::XPath::Node] ast_node
|
||||||
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
# @return [Oga::XML::NodeSet]
|
||||||
|
#
|
||||||
|
def on_axis_self(ast_node, context)
|
||||||
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
|
context.each do |context_node|
|
||||||
|
nodes << context_node if node_matches?(context_node, ast_node)
|
||||||
|
end
|
||||||
|
|
||||||
|
return nodes
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns a node set containing all the child nodes of the given set of
|
# Returns a node set containing all the child nodes of the given set of
|
||||||
# nodes.
|
# nodes.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Evaluator do
|
||||||
|
context 'self axis' do
|
||||||
|
before do
|
||||||
|
@document = parse('<a></a>')
|
||||||
|
@evaluator = described_class.new(@document)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'matching the context node itself' do
|
||||||
|
before do
|
||||||
|
@set = @evaluator.evaluate('a/self::a')
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like :node_set, :length => 1
|
||||||
|
|
||||||
|
example 'return the <a> node' do
|
||||||
|
@set[0].should == @document.children[0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'matching non existing nodes' do
|
||||||
|
before do
|
||||||
|
@set = @evaluator.evaluate('a/self::b')
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like :empty_node_set
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue