Support for the XPath comment() test.
This commit is contained in:
parent
4e8cca258c
commit
ccd95d69d8
|
@ -474,6 +474,23 @@ module Oga
|
||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Processes the `comment()` type test. This matches only comment nodes.
|
||||||
|
#
|
||||||
|
# @param [Oga::XPath::Node] ast_node
|
||||||
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
# @return [Oga::XML::NodeSet]
|
||||||
|
#
|
||||||
|
def on_type_test_comment(ast_node, context)
|
||||||
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
|
context.each do |node|
|
||||||
|
nodes << node if node.is_a?(XML::Comment)
|
||||||
|
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,42 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Evaluator do
|
||||||
|
context 'comment() tests' do
|
||||||
|
before do
|
||||||
|
@document = parse('<a><!--foo--><b><!--bar--></b></a>')
|
||||||
|
@evaluator = described_class.new(@document)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'matching text nodes' do
|
||||||
|
before do
|
||||||
|
@set = @evaluator.evaluate('a/comment()')
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like :node_set, :length => 1
|
||||||
|
|
||||||
|
example 'return a Comment instance' do
|
||||||
|
@set[0].is_a?(Oga::XML::Comment).should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return the "foo" comment node' do
|
||||||
|
@set[0].text.should == 'foo'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'matching nested text nodes' do
|
||||||
|
before do
|
||||||
|
@set = @evaluator.evaluate('a/b/comment()')
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like :node_set, :length => 1
|
||||||
|
|
||||||
|
example 'return a Comment instance' do
|
||||||
|
@set[0].is_a?(Oga::XML::Comment).should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return the "bar" comment node' do
|
||||||
|
@set[0].text.should == 'bar'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue