Revamped compiler "preceding-sibling" specs
This commit is contained in:
parent
84a9315b24
commit
6b2874c507
|
@ -387,14 +387,16 @@ module Oga
|
||||||
.else { parent.assign(self.nil) }
|
.else { parent.assign(self.nil) }
|
||||||
end
|
end
|
||||||
.followed_by do
|
.followed_by do
|
||||||
root.each_node.add_block(doc_node) do
|
document_or_node(root).if_true do
|
||||||
doc_node.eq(input)
|
root.each_node.add_block(doc_node) do
|
||||||
.if_true { self.break }
|
doc_node.eq(input)
|
||||||
.followed_by do
|
.if_true { self.break }
|
||||||
doc_node.parent.eq(parent).if_true do
|
.followed_by do
|
||||||
process(ast, doc_node).if_true { yield doc_node }
|
doc_node.parent.eq(parent).if_true do
|
||||||
|
process(ast, doc_node).if_true { yield doc_node }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Compiler do
|
describe Oga::XPath::Compiler do
|
||||||
describe 'preceding-sibling axis' do
|
before do
|
||||||
before do
|
@document = parse(<<-EOF.strip.gsub(/^\s+|\n/m, ''))
|
||||||
@document = parse(<<-EOF.strip.gsub(/\s+/m, ''))
|
<root foo="bar">
|
||||||
<root>
|
|
||||||
<foo>
|
<foo>
|
||||||
</foo>
|
</foo>
|
||||||
<bar>
|
<bar>
|
||||||
|
@ -12,25 +11,48 @@ describe Oga::XPath::Compiler do
|
||||||
<baz></baz>
|
<baz></baz>
|
||||||
</bar>
|
</bar>
|
||||||
</root>
|
</root>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@foo1 = @document.children[0].children[0]
|
@foo1 = @document.children[0].children[0]
|
||||||
@foo2 = @document.children[0].children[1].children[0]
|
@foo2 = @document.children[0].children[1].children[0]
|
||||||
@bar1 = @document.children[0].children[1]
|
@bar1 = @document.children[0].children[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to a document' do
|
||||||
|
describe 'preceding-sibling::*' do
|
||||||
|
it 'returns an empty NodeSet' do
|
||||||
|
evaluate_xpath(@document).should == node_set
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing preceding siblings of root/bar' do
|
describe 'root/bar/preceding-sibling::foo' do
|
||||||
evaluate_xpath(@document, 'root/bar/preceding-sibling::foo')
|
it 'returns a NodeSet' do
|
||||||
.should == node_set(@foo1)
|
evaluate_xpath(@document).should == node_set(@foo1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing preceding siblings of root/bar/baz' do
|
describe 'root/bar/baz/preceding-sibling::foo' do
|
||||||
evaluate_xpath(@document, 'root/bar/baz/preceding-sibling::foo')
|
it 'returns a NodeSet' do
|
||||||
.should == node_set(@foo2)
|
evaluate_xpath(@document).should == node_set(@foo2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns a node set containing preceding siblings relative to root/bar' do
|
describe 'relative to an element' do
|
||||||
evaluate_xpath(@bar1, 'preceding-sibling::foo').should == node_set(@foo1)
|
describe 'preceding-sibling::foo' do
|
||||||
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@bar1).should == node_set(@foo1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to an attribute' do
|
||||||
|
describe 'preceding-sibling::*' do
|
||||||
|
it 'returns an empty NodeSet' do
|
||||||
|
root = @document.children[0]
|
||||||
|
|
||||||
|
evaluate_xpath(root.attribute('foo')).should == node_set
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue