Added substring-before() spec for a predicate

This commit is contained in:
Yorick Peterse 2015-08-18 15:14:26 +02:00
parent 32dba554d7
commit b60ed03bb4
1 changed files with 28 additions and 17 deletions

View File

@ -4,8 +4,11 @@ describe Oga::XPath::Compiler do
describe 'substring-before() function' do describe 'substring-before() function' do
before do before do
@document = parse('<root><a>-</a><b>a-b-c</b></root>') @document = parse('<root><a>-</a><b>a-b-c</b></root>')
@a1 = @document.children[0].children[0]
end end
describe 'at the top-level' do
it 'returns the substring of the 1st string before the 2nd string' do it 'returns the substring of the 1st string before the 2nd string' do
evaluate_xpath(@document, 'substring-before("a-b-c", "-")').should == 'a' evaluate_xpath(@document, 'substring-before("a-b-c", "-")').should == 'a'
end end
@ -27,4 +30,12 @@ describe Oga::XPath::Compiler do
evaluate_xpath(@document, 'substring-before("", "")').should == '' evaluate_xpath(@document, 'substring-before("", "")').should == ''
end end
end end
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 end