Revamp compiler "following" specs
This commit is contained in:
parent
824c897467
commit
a1e7d2d07f
|
@ -308,6 +308,7 @@ module Oga
|
||||||
.else { root.assign(orig_input) }
|
.else { root.assign(orig_input) }
|
||||||
.followed_by(check.assign(self.false))
|
.followed_by(check.assign(self.false))
|
||||||
.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 do
|
.if_true do
|
||||||
|
@ -323,6 +324,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
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Compiler do
|
describe Oga::XPath::Compiler do
|
||||||
describe 'following axis' do
|
|
||||||
before do
|
before do
|
||||||
# Strip whitespace so it's easier to retrieve/compare elements.
|
# Strip whitespace so it's easier to retrieve/compare elements.
|
||||||
@document = parse(<<-EOF.strip.gsub(/\s+/m, ''))
|
@document = parse(<<-EOF.strip.gsub(/^\s+|\n/m, ''))
|
||||||
<root>
|
<root foo="bar">
|
||||||
<foo>
|
<foo>
|
||||||
<bar></bar>
|
<bar></bar>
|
||||||
<baz>
|
<baz>
|
||||||
|
@ -22,25 +21,43 @@ describe Oga::XPath::Compiler do
|
||||||
@baz3 = @document.children[0].children[1]
|
@baz3 = @document.children[0].children[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'relative to a document' do
|
||||||
# This should return an empty set since the document doesn't have any
|
# This should return an empty set since the document doesn't have any
|
||||||
# following nodes.
|
# following nodes.
|
||||||
it 'returns an empty node set for the sibling of a document' do
|
describe 'following::foo' do
|
||||||
evaluate_xpath(@document, 'following::foo').should == node_set
|
it 'returns an empty NodeSet' do
|
||||||
|
evaluate_xpath(@document).should == node_set
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing the following nodes of root/foo' do
|
describe 'root/foo/following::baz' do
|
||||||
evaluate_xpath(@document, 'root/foo/following::baz')
|
it 'returns a NodeSet' do
|
||||||
.should == node_set(@baz3)
|
evaluate_xpath(@document).should == node_set(@baz3)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing the following nodes of root/foo/bar' do
|
describe 'root/foo/bar/following::baz' do
|
||||||
evaluate_xpath(@document, 'root/foo/bar/following::baz')
|
it 'returns a NodeSet' do
|
||||||
.should == node_set(@baz1, @baz2, @baz3)
|
evaluate_xpath(@document).should == node_set(@baz1, @baz2, @baz3)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a node set containing the siblings relative to root/foo/bar' do
|
describe 'relative to an element' do
|
||||||
evaluate_xpath(@bar1, 'following::baz')
|
describe 'following::baz' do
|
||||||
.should == node_set(@baz1, @baz2, @baz3)
|
it 'returns a NodeSet' do
|
||||||
|
evaluate_xpath(@bar1).should == node_set(@baz1, @baz2, @baz3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'relative to an attribute' do
|
||||||
|
describe 'following::foo' 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