Revamp child axis compiler specs

This commit is contained in:
Yorick Peterse 2015-08-27 09:30:53 +02:00
parent ed31b9f1d3
commit 8f341b40d6
1 changed files with 31 additions and 11 deletions

View File

@ -1,24 +1,44 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'child axis' do
before do
@document = parse('<a><b></b></a>')
before do
@document = parse('<a><b></b></a>')
@a1 = @document.children[0]
@b1 = @a1.children[0]
@a1 = @document.children[0]
@b1 = @a1.children[0]
end
describe 'relative to a document' do
describe 'child::a' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@a1)
end
end
it 'returns a node set containing a direct child node' do
evaluate_xpath(@document, 'child::a').should == node_set(@a1)
describe 'child::a/child::b' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@b1)
end
end
end
describe 'relative to an element' do
describe 'child::a' do
it 'returns an empty NodeSet' do
evaluate_xpath(@a1).should == node_set
end
end
it 'returns a node set containing a nested child node' do
evaluate_xpath(@document, 'child::a/child::b').should == node_set(@b1)
describe 'child::b' do
it 'returns a NodeSet' do
evaluate_xpath(@a1).should == node_set(@b1)
end
end
it 'returns an empty node set for non existing child nodes' do
evaluate_xpath(@document, 'child::x').should == node_set
describe 'child::x' do
it 'returns an empty NodeSet' do
evaluate_xpath(@a1).should == node_set
end
end
end
end