Support for the XPath "self" axis.

This commit is contained in:
Yorick Peterse 2014-08-05 21:10:12 +02:00
parent 669ad25000
commit 26d4bdc5b1
2 changed files with 47 additions and 0 deletions

View File

@ -381,6 +381,23 @@ module Oga
return nodes
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
# nodes.

View File

@ -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