Revamped compiler "preceding-sibling" specs

This commit is contained in:
Yorick Peterse 2015-08-28 16:30:26 +02:00
parent 84a9315b24
commit 6b2874c507
2 changed files with 47 additions and 23 deletions

View File

@ -387,6 +387,7 @@ module Oga
.else { parent.assign(self.nil) }
end
.followed_by do
document_or_node(root).if_true do
root.each_node.add_block(doc_node) do
doc_node.eq(input)
.if_true { self.break }
@ -398,6 +399,7 @@ module Oga
end
end
end
end
# @param [AST::Node] ast
# @param [Oga::Ruby::Node] input

View File

@ -1,10 +1,9 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'preceding-sibling axis' do
before do
@document = parse(<<-EOF.strip.gsub(/\s+/m, ''))
<root>
@document = parse(<<-EOF.strip.gsub(/^\s+|\n/m, ''))
<root foo="bar">
<foo>
</foo>
<bar>
@ -19,18 +18,41 @@ describe Oga::XPath::Compiler do
@bar1 = @document.children[0].children[1]
end
it 'returns a node set containing preceding siblings of root/bar' do
evaluate_xpath(@document, 'root/bar/preceding-sibling::foo')
.should == node_set(@foo1)
describe 'relative to a document' do
describe 'preceding-sibling::*' do
it 'returns an empty NodeSet' do
evaluate_xpath(@document).should == node_set
end
end
it 'returns a node set containing preceding siblings of root/bar/baz' do
evaluate_xpath(@document, 'root/bar/baz/preceding-sibling::foo')
.should == node_set(@foo2)
describe 'root/bar/preceding-sibling::foo' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@foo1)
end
end
it 'returns a node set containing preceding siblings relative to root/bar' do
evaluate_xpath(@bar1, 'preceding-sibling::foo').should == node_set(@foo1)
describe 'root/bar/baz/preceding-sibling::foo' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@foo2)
end
end
end
describe 'relative to an element' do
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