Rewrote XPath compiler predicate specs
This commit is contained in:
parent
6f6151fd52
commit
7fdf8d7460
|
@ -3,23 +3,30 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Compiler do
|
describe Oga::XPath::Compiler do
|
||||||
describe 'predicates' do
|
describe 'predicates' do
|
||||||
before do
|
before do
|
||||||
@document = parse(<<-EOF)
|
@document = parse('<root><a>10</a><a><b>20</a></a></root>')
|
||||||
<root>
|
|
||||||
<a>10</a>
|
|
||||||
<b>
|
|
||||||
<a>20</a>
|
|
||||||
<a>30</3>
|
|
||||||
</b>
|
|
||||||
</root>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
@a1 = @document.at_xpath('root/a[1]')
|
root = @document.children[0]
|
||||||
@a2 = @document.at_xpath('root/b/a[1]')
|
|
||||||
|
@a1 = root.children[0]
|
||||||
|
@a2 = root.children[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing all first <a> nodes' do
|
describe 'using an integer as an index' do
|
||||||
evaluate_xpath(@document, 'descendant-or-self::node()/a[1]')
|
it 'returns a NodeSet containing the first <a> node' do
|
||||||
.should == node_set(@a1, @a2)
|
evaluate_xpath(@document, 'root/a[1]').should == node_set(@a1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'using a float as an index' do
|
||||||
|
it 'returns a NodeSet containing the first <a> node' do
|
||||||
|
evaluate_xpath(@document, 'root/a[1.5]').should == node_set(@a1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'using a node test' do
|
||||||
|
it 'returns a NodeSet containing all <a> nodes with <b> child nodes' do
|
||||||
|
evaluate_xpath(@document, 'root/a[b]').should == node_set(@a2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue