From be05008be9af4f3a2b4c6d3bbd66489dcf31884c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 18 Aug 2015 15:15:14 +0200 Subject: [PATCH] Added substring-after() spec for a predicate --- .../compiler/calls/substring_after_spec.rb | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/spec/oga/xpath/compiler/calls/substring_after_spec.rb b/spec/oga/xpath/compiler/calls/substring_after_spec.rb index 1fdffb6..8492d90 100644 --- a/spec/oga/xpath/compiler/calls/substring_after_spec.rb +++ b/spec/oga/xpath/compiler/calls/substring_after_spec.rb @@ -4,27 +4,38 @@ describe Oga::XPath::Compiler do describe 'substring-after() function' do before do @document = parse('-a-b-c') + + @a1 = @document.children[0].children[0] end - it 'returns the substring of the 1st string after the 2nd string' do - evaluate_xpath(@document, 'substring-after("a-b-c", "-")').should == 'b-c' + describe 'at the top-level' do + it 'returns the substring of the 1st string after the 2nd string' do + evaluate_xpath(@document, 'substring-after("a-b-c", "-")').should == 'b-c' + end + + it 'returns an empty string if the 2nd string is not present' do + evaluate_xpath(@document, 'substring-after("a-b-c", "x")').should == '' + end + + it 'returns the substring of the 1st node set after the 2nd string' do + evaluate_xpath(@document, 'substring-after(root/b, "-")').should == 'b-c' + end + + it 'returns the substring of the 1st node set after the 2nd node set' do + evaluate_xpath(@document, 'substring-after(root/b, root/a)') + .should == 'b-c' + end + + it 'returns an empty string when using two empty strings' do + evaluate_xpath(@document, 'substring-after("", "")').should == '' + end end - it 'returns an empty string if the 2nd string is not present' do - evaluate_xpath(@document, 'substring-after("a-b-c", "x")').should == '' - end - - it 'returns the substring of the 1st node set after the 2nd string' do - evaluate_xpath(@document, 'substring-after(root/b, "-")').should == 'b-c' - end - - it 'returns the substring of the 1st node set after the 2nd node set' do - evaluate_xpath(@document, 'substring-after(root/b, root/a)') - .should == 'b-c' - end - - it 'returns an empty string when using two empty strings' do - evaluate_xpath(@document, 'substring-after("", "")').should == '' + describe 'in a predicate' do + it 'returns a NodeSet containing all matching nodes' do + evaluate_xpath(@document, 'root/a[substring-after("foo-bar", "-")]') + .should == node_set(@a1) + end end end end