XPath evaluation for name/namespace wildcards.
This commit is contained in:
parent
ed45058983
commit
8fbc582547
|
@ -74,8 +74,8 @@ module Oga
|
|||
name_matches = xml_node.name == name || name == '*'
|
||||
ns_matches = false
|
||||
|
||||
if ns and (xml_node.namespace == ns or ns == '*')
|
||||
ns_matches = true
|
||||
if ns
|
||||
ns_matches = xml_node.namespace == ns || ns == '*'
|
||||
|
||||
# If there's no namespace given but the name matches we'll also mark
|
||||
# the namespace as matching.
|
||||
|
|
|
@ -28,4 +28,41 @@ describe Oga::XPath::Evaluator do
|
|||
@set[2].namespace.should == 'ns1'
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue