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