Revamp namespace compiler specs

This commit is contained in:
Yorick Peterse 2015-08-28 15:58:42 +02:00
parent a1e7d2d07f
commit d0177633f8
1 changed files with 41 additions and 14 deletions

View File

@ -1,29 +1,56 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'namespace axis' do
before do
@document = parse('<root xmlns:x="x"><foo xmlns:y="y"></foo></root>')
before do
@document = parse('<root xmlns:x="x" foo="bar"><foo xmlns:y="y"></foo></root>')
@ns_x = @document.children[0].namespaces['x']
@ns_y = @document.children[0].children[0].namespaces['y']
@ns_x = @document.children[0].namespaces['x']
@ns_y = @document.children[0].children[0].namespaces['y']
end
describe 'relative to a document' do
describe 'namespace::*' do
it 'returns an empty NodeSet' do
evaluate_xpath(@document).should == node_set
end
end
it 'returns an empty node set for the document' do
evaluate_xpath(@document, 'namespace::*').should == node_set
describe 'root/namespace::x' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@ns_x)
end
end
it 'returns a node set containing the namespaces for root' do
evaluate_xpath(@document, 'root/namespace::x').should == node_set(@ns_x)
describe 'root/foo/namespace::*' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@ns_y, @ns_x)
end
end
it 'returns a node set containing the namespaces for root/foo' do
evaluate_xpath(@document, 'root/foo/namespace::*')
.should == node_set(@ns_y, @ns_x)
describe 'root/namespace::*' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@ns_x)
end
end
end
it 'returns a node set containing the namespaces for root using a wildcard' do
evaluate_xpath(@document, 'root/namespace::*').should == node_set(@ns_x)
describe 'relative to an element' do
describe 'namespace::x' do
it 'returns a NodeSet' do
root = @document.children[0]
evaluate_xpath(root).should == node_set(@ns_x)
end
end
end
describe 'relative to an attribute' do
describe 'namespace::x' do
it 'returns an empty NodeSet' do
root = @document.children[0]
evaluate_xpath(root.attribute('foo')).should == node_set
end
end
end
end