Added substring-after() spec for a predicate

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

View File

@ -4,27 +4,38 @@ describe Oga::XPath::Compiler do
describe 'substring-after() function' do describe 'substring-after() 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
it 'returns the substring of the 1st string after the 2nd string' do describe 'at the top-level' do
evaluate_xpath(@document, 'substring-after("a-b-c", "-")').should == 'b-c' 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 end
it 'returns an empty string if the 2nd string is not present' do describe 'in a predicate' do
evaluate_xpath(@document, 'substring-after("a-b-c", "x")').should == '' it 'returns a NodeSet containing all matching nodes' do
end evaluate_xpath(@document, 'root/a[substring-after("foo-bar", "-")]')
.should == node_set(@a1)
it 'returns the substring of the 1st node set after the 2nd string' do end
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
end end
end end