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:
Yorick Peterse 2014-07-12 00:22:18 +02:00
parent d6aec6aa16
commit 56982dd543
2 changed files with 22 additions and 0 deletions

View File

@ -61,6 +61,8 @@ module Oga
if test != last_node and !@stack.empty?
swap_context
elsif @stack.empty?
break
end
end
end

View File

@ -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')