Fail early when processing (test) nodes.
If a certain segment yields no nodes the on_path() method should not process any following segments.
This commit is contained in:
parent
d6aec6aa16
commit
56982dd543
|
@ -61,6 +61,8 @@ module Oga
|
|||
|
||||
if test != last_node and !@stack.empty?
|
||||
swap_context
|
||||
elsif @stack.empty?
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,16 @@ describe Oga::XPath::Evaluator do
|
|||
end
|
||||
end
|
||||
|
||||
context 'invalid absolute paths' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('/x/a')
|
||||
end
|
||||
|
||||
example 'return an empty NodeSet' do
|
||||
@set.empty?.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context 'relative paths' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('a')
|
||||
|
@ -42,6 +52,16 @@ describe Oga::XPath::Evaluator do
|
|||
end
|
||||
end
|
||||
|
||||
context 'invalid relative paths' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('x/a')
|
||||
end
|
||||
|
||||
example 'return an empty NodeSet' do
|
||||
@set.empty?.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context 'nested paths' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('/a/b')
|
||||
|
|
Loading…
Reference in New Issue