XPath evaluation for name/namespace wildcards.

This commit is contained in:
Yorick Peterse 2014-07-09 22:09:20 +02:00
parent ed45058983
commit 8fbc582547
2 changed files with 39 additions and 2 deletions

View File

@ -74,8 +74,8 @@ module Oga
name_matches = xml_node.name == name || name == '*' name_matches = xml_node.name == name || name == '*'
ns_matches = false ns_matches = false
if ns and (xml_node.namespace == ns or ns == '*') if ns
ns_matches = true ns_matches = xml_node.namespace == ns || ns == '*'
# If there's no namespace given but the name matches we'll also mark # If there's no namespace given but the name matches we'll also mark
# the namespace as matching. # the namespace as matching.

View File

@ -28,4 +28,41 @@ describe Oga::XPath::Evaluator do
@set[2].namespace.should == 'ns1' @set[2].namespace.should == 'ns1'
end end
end end
context 'namespace wildcards' do
before do
@set = @evaluator.evaluate('a/*:b')
end
example 'return the right amount of rows' do
@set.length.should == 2
end
example 'include the first <b> node' do
@set[0].name.should == 'b'
end
example 'include the second <b> node' do
@set[1].name.should == 'b'
end
example 'ensure the nodes are the individual <b> nodes' do
@set[0].should_not == @set[1]
end
end
context 'name wildcards' do
before do
@set = @evaluator.evaluate('a/ns1:*')
end
example 'return the right amount of rows' do
@set.length.should == 1
end
example 'include the correct <c> node' do
@set[0].name.should == 'c'
@set[0].namespace.should == 'ns1'
end
end
end end