From bb8b328f5eb237e172883d0da30cfa1b083ffba7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 30 Aug 2015 18:26:52 +0200 Subject: [PATCH] Revamp compiler specs for regular paths --- spec/oga/xpath/compiler/paths_spec.rb | 68 +++++++++++++++++---------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/spec/oga/xpath/compiler/paths_spec.rb b/spec/oga/xpath/compiler/paths_spec.rb index 2718bcb..1d3c197 100644 --- a/spec/oga/xpath/compiler/paths_spec.rb +++ b/spec/oga/xpath/compiler/paths_spec.rb @@ -1,47 +1,65 @@ require 'spec_helper' describe Oga::XPath::Compiler do - describe 'paths' do - before do - @document = parse('Foo') + before do + @document = parse('Foo') - @a1 = @document.children[0] - @b1 = @a1.children[1] - @b2 = @a1.children[2] + @a1 = @document.children[0] + @b1 = @a1.children[1] + @b2 = @a1.children[2] + end + + describe 'relative to a document' do + describe '/a' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@a1) + end end - it 'evaluates an absolute path' do - evaluate_xpath(@document, '/a').should == node_set(@a1) + describe '/' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@document) + end end - it 'evaluates an absolute path relative to a sub node' do - b_node = @document.children[0].children[0] - - evaluate_xpath(b_node, '/a').should == node_set(@a1) + describe 'a' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@a1) + end end - it 'evaluates the root selector' do - evaluate_xpath(@document, '/').should == node_set(@document) + describe 'x/a' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set + end end - it 'evaluates a relative path' do - evaluate_xpath(@document, 'a').should == node_set(@a1) + describe '/a/b' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@b1, @b2) + end end - it 'evaluates a relative path that returns an empty node set' do - evaluate_xpath(@document, 'x/a').should == node_set + describe '/x/a' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set + end end - it 'evaluates a nested absolute path' do - evaluate_xpath(@document, '/a/b').should == node_set(@b1, @b2) + describe 'a/ns1:c' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@a1.children[-1]) + end end + end - it 'evaluates an absolute path that returns an empty node set' do - evaluate_xpath(@document, '/x/a').should == node_set - end + describe 'relative to an element' do + describe '/a' do + it 'returns a NodeSet' do + b_node = @document.children[0].children[0] - it 'evaluates a namespaced path' do - evaluate_xpath(@document, 'a/ns1:c').should == node_set(@a1.children[-1]) + evaluate_xpath(b_node, '/a').should == node_set(@a1) + end end end end