XPath "self" axis inside predicates.
The "self" axis should use the current context node when inside a predicate.
This commit is contained in:
parent
71f2b42074
commit
2b96d65103
|
@ -490,8 +490,12 @@ module Oga
|
||||||
def on_axis_self(ast_node, context)
|
def on_axis_self(ast_node, context)
|
||||||
nodes = XML::NodeSet.new
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
context.each do |context_node|
|
if current_node
|
||||||
nodes << context_node if node_matches?(context_node, ast_node)
|
nodes << current_node if node_matches?(current_node, ast_node)
|
||||||
|
else
|
||||||
|
context.each do |context_node|
|
||||||
|
nodes << context_node if node_matches?(context_node, ast_node)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'self axis' do
|
context 'self axis' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<a></a>')
|
@document = parse('<a><b>foo</b><b>bar</b></a>')
|
||||||
@evaluator = described_class.new(@document)
|
@evaluator = described_class.new(@document)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,5 +38,17 @@ describe Oga::XPath::Evaluator do
|
||||||
@set[0].should == @document.children[0]
|
@set[0].should == @document.children[0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'matching nodes inside predicates' do
|
||||||
|
before do
|
||||||
|
@set = @evaluator.evaluate('a/b[.="foo"]')
|
||||||
|
end
|
||||||
|
|
||||||
|
it_behaves_like :node_set, :length => 1
|
||||||
|
|
||||||
|
example 'return the first <b> node' do
|
||||||
|
@set[0].should == @document.children[0].children[0]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue