Support for the XPath concat() function.
This commit is contained in:
parent
431a253000
commit
b688c6dc1b
|
@ -786,8 +786,29 @@ module Oga
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Processes an `(int)` node. This method simply returns the value as a
|
# Processes the `concat()` function call.
|
||||||
# Float.
|
#
|
||||||
|
# This function call converts its arguments to strings and concatenates
|
||||||
|
# them. In case of node sets the text of the set is used.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
# @param [Oga::XPath::Node] first
|
||||||
|
# @param [Oga::XPath::Node] second
|
||||||
|
# @param [Array<Oga::XPath::Node>] rest
|
||||||
|
#
|
||||||
|
def on_call_concat(context, first, second, *rest)
|
||||||
|
args = [first, second] + rest
|
||||||
|
retval = ''
|
||||||
|
|
||||||
|
args.each do |arg|
|
||||||
|
retval << on_call_string(context, arg)
|
||||||
|
end
|
||||||
|
|
||||||
|
return retval
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Processes an `(int)` node.
|
||||||
#
|
#
|
||||||
# @param [Oga::XPath::Node] ast_node
|
# @param [Oga::XPath::Node] ast_node
|
||||||
# @param [Oga::XML::NodeSet] context
|
# @param [Oga::XML::NodeSet] context
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Evaluator do
|
||||||
|
context 'concat() function' do
|
||||||
|
before do
|
||||||
|
@document = parse('<root><a>foo</a><b>bar</b></root>')
|
||||||
|
@evaluator = described_class.new(@document)
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'concatenate two strings' do
|
||||||
|
@evaluator.evaluate('concat("foo", "bar")').should == 'foobar'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'concatenate two integers' do
|
||||||
|
@evaluator.evaluate('concat(10, 20)').should == '1020'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'concatenate two floats' do
|
||||||
|
@evaluator.evaluate('concat(10.5, 20.5)').should == '10.520.5'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'concatenate two node sets' do
|
||||||
|
@evaluator.evaluate('concat(root/a, root/b)').should == 'foobar'
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'concatenate a node set and a string' do
|
||||||
|
@evaluator.evaluate('concat(root/a, "baz")').should == 'foobaz'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue