Rewrote XPath evaluator wildcards spec.

This commit is contained in:
Yorick Peterse 2014-11-09 18:56:49 +01:00
parent ceed3a6046
commit 5f13cc9d73
1 changed files with 15 additions and 67 deletions

View File

@ -1,82 +1,30 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
before do
@document = parse('<a xmlns:ns1="x"><b></b><b></b><ns1:c></ns1:c></a>')
@evaluator = described_class.new(@document)
end
context 'full wildcards' do
context 'wildcard paths' do
before do
@set = @evaluator.evaluate('a/*')
@document = parse('<a xmlns:ns1="x"><b></b><b></b><ns1:c></ns1:c></a>')
@a1 = @document.children[0]
@b1 = @a1.children[0]
@b2 = @a1.children[1]
@c1 = @a1.children[2]
end
it_behaves_like :node_set, :length => 3
example 'include the first <b> node' do
@set[0].name.should == 'b'
example 'evaluate a wildcard path' do
evaluate_xpath(@document, 'a/*').should == @a1.children
end
example 'include the second <b> node' do
@set[1].name.should == 'b'
example 'evaluate a path using a namespace wildcard' do
evaluate_xpath(@document, 'a/*:b').should == node_set(@b1, @b2)
end
example 'include the <ns1:c> node' do
@set[2].name.should == 'c'
@set[2].namespace.name.should == 'ns1'
end
end
context 'namespace wildcards' do
before do
@set = @evaluator.evaluate('a/*:b')
example 'evaluate a path using a namespace and a name wildcard' do
evaluate_xpath(@document, 'a/ns1:*').should == node_set(@c1)
end
it_behaves_like :node_set, :length => 2
example 'include the first <b> node' do
@set[0].name.should == 'b'
end
example 'include the second <b> node' do
@set[1].name.should == 'b'
end
example 'ensure the nodes are the individual <b> nodes' do
@set[0].should_not == @set[1]
end
end
context 'name wildcards' do
before do
@set = @evaluator.evaluate('a/ns1:*')
end
it_behaves_like :node_set, :length => 1
example 'include the correct <c> node' do
@set[0].name.should == 'c'
@set[0].namespace.name.should == 'ns1'
end
end
context 'name and namespace wildcards' do
before do
@set = @evaluator.evaluate('a/*:*')
end
it_behaves_like :node_set, :length => 3
example 'include the first <b> node' do
@set[0].name.should == 'b'
end
example 'include the second <b> node' do
@set[1].name.should == 'b'
end
example 'include the <c> node' do
@set[2].name.should == 'c'
example 'evaluate a containing a namespace wildcard and a name wildcard' do
evaluate_xpath(@document, 'a/*:*').should == @a1.children
end
end
end