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

View File

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