Revamped compiler specs for "parent"
This commit is contained in:
parent
07658dadb1
commit
84a9315b24
|
@ -237,7 +237,7 @@ module Oga
|
||||||
node = node_literal
|
node = node_literal
|
||||||
parent = unique_literal(:parent)
|
parent = unique_literal(:parent)
|
||||||
|
|
||||||
input.is_a?(XML::Node).if_true do
|
attribute_or_node(input).if_true do
|
||||||
parent.assign(input.parent).followed_by do
|
parent.assign(input.parent).followed_by do
|
||||||
process(ast, parent).if_true { yield parent }
|
process(ast, parent).if_true { yield parent }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,54 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Compiler do
|
describe Oga::XPath::Compiler do
|
||||||
describe 'parent axis' do
|
before do
|
||||||
before do
|
@document = parse('<a foo="bar"><b></b></a>')
|
||||||
@document = parse('<a><b></b></a>')
|
|
||||||
|
|
||||||
@a1 = @document.children[0]
|
@a1 = @document.children[0]
|
||||||
|
@b1 = @a1.children[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to a document' do
|
||||||
|
describe 'parent::a' do
|
||||||
|
it 'returns an empty NodeSet' do
|
||||||
|
evaluate_xpath(@document).should == node_set
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an empty node set for non existing parents' do
|
describe 'a/b/parent::a' do
|
||||||
evaluate_xpath(@document, 'parent::a').should == node_set
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@document).should == node_set(@a1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing parents of a node' do
|
describe 'a/b/..' do
|
||||||
evaluate_xpath(@document, 'a/b/parent::a').should == node_set(@a1)
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@document).should == node_set(@a1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns a node set containing parents of a node using the short form' do
|
describe 'relative to an element' do
|
||||||
evaluate_xpath(@document, 'a/b/..').should == node_set(@a1)
|
describe 'parent::a' do
|
||||||
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@b1).should == node_set(@a1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to the root element' do
|
||||||
|
describe 'parent::*' do
|
||||||
|
it 'returns an empty NodeSet' do
|
||||||
|
evaluate_xpath(@a1).should == node_set
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to an attribute' do
|
||||||
|
describe 'parent::a' do
|
||||||
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@a1.attribute('foo')).should == node_set(@a1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue