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