XPath compiler support for id() in predicates
This commit is contained in:
parent
49196c285f
commit
c026244f6e
|
@ -790,7 +790,7 @@ module Oga
|
|||
node.is_a?(XML::Element).if_true do
|
||||
attr_var.assign(node.attribute(id_str_var)).followed_by do
|
||||
attr_var.and(ids_var.include?(attr_var.value))
|
||||
.if_true { matched << node }
|
||||
.if_true { block_given? ? yield : matched << node }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,16 +9,37 @@ describe Oga::XPath::Compiler do
|
|||
@a2 = @document.children[0].children[1]
|
||||
end
|
||||
|
||||
it 'returns a node set containing the nodes with ID "a1"' do
|
||||
evaluate_xpath(@document, 'id("a1")').should == node_set(@a1)
|
||||
describe 'at the top level' do
|
||||
describe 'using a string' do
|
||||
it 'returns a NodeSet' do
|
||||
evaluate_xpath(@document, 'id("a1")').should == node_set(@a1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'using a space separated string' do
|
||||
it 'returns a NodeSet' do
|
||||
evaluate_xpath(@document, 'id("a1 a2")').should == node_set(@a1, @a2)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'using a path' do
|
||||
it 'returns a NodeSet' do
|
||||
evaluate_xpath(@document, 'id(root/a[2])').should == node_set(@a1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns a node set containing the nodes with ID "a1" or "a2"' do
|
||||
evaluate_xpath(@document, 'id("a1 a2")').should == node_set(@a1, @a2)
|
||||
end
|
||||
describe 'in a predicate' do
|
||||
describe 'using a string' do
|
||||
it 'matches nodes when a non-empty NodeSet is returned' do
|
||||
evaluate_xpath(@document, 'root/a[id("a1")]')
|
||||
.should == node_set(@a1, @a2)
|
||||
end
|
||||
|
||||
it 'returns a node set containing the nodes with an ID based on a path' do
|
||||
evaluate_xpath(@document, 'id(root/a[2])').should == node_set(@a1)
|
||||
it 'does not match nodes when an empty NodeSet is returned' do
|
||||
evaluate_xpath(@document, 'root/a[id("foo")]').should == node_set
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue