XPath compiler support for "ancestor"
This commit is contained in:
parent
f96b30fb1f
commit
4f03bf19c1
|
@ -192,6 +192,21 @@ module Oga
|
||||||
self_test.followed_by(ancestors_test)
|
self_test.followed_by(ancestors_test)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Processes the `ancestor` axis.
|
||||||
|
#
|
||||||
|
# @param [AST::Node] ast
|
||||||
|
# @param [Oga::Ruby::Node] input
|
||||||
|
# @return [Oga::Ruby::Node]
|
||||||
|
#
|
||||||
|
def on_axis_ancestor(ast, input, &block)
|
||||||
|
parent = literal('parent')
|
||||||
|
|
||||||
|
input.each_ancestor.add_block(parent) do
|
||||||
|
process(ast, parent, &block).if_true { yield parent }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Processes a node test predicate.
|
# Processes a node test predicate.
|
||||||
#
|
#
|
||||||
|
|
|
@ -22,6 +22,10 @@ describe Oga::XPath::Compiler do
|
||||||
evaluate_xpath(@c1, 'ancestor::*[1]').should == node_set(@b1)
|
evaluate_xpath(@c1, 'ancestor::*[1]').should == node_set(@b1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns a node set containing all ancestors' do
|
||||||
|
evaluate_xpath(@c1, 'ancestor::*').should == node_set(@b1, @a1)
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns an empty node set for non existing ancestors' do
|
it 'returns an empty node set for non existing ancestors' do
|
||||||
evaluate_xpath(@c1, 'ancestor::c').should == node_set
|
evaluate_xpath(@c1, 'ancestor::c').should == node_set
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue