Rewrote XPath evaluator wildcards spec.
This commit is contained in:
parent
ceed3a6046
commit
5f13cc9d73
|
@ -1,82 +1,30 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
before do
|
context 'wildcard paths' 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
|
|
||||||
before 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
|
end
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 3
|
example 'evaluate a wildcard path' do
|
||||||
|
evaluate_xpath(@document, 'a/*').should == @a1.children
|
||||||
example 'include the first <b> node' do
|
|
||||||
@set[0].name.should == 'b'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'include the second <b> node' do
|
example 'evaluate a path using a namespace wildcard' do
|
||||||
@set[1].name.should == 'b'
|
evaluate_xpath(@document, 'a/*:b').should == node_set(@b1, @b2)
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'include the <ns1:c> node' do
|
example 'evaluate a path using a namespace and a name wildcard' do
|
||||||
@set[2].name.should == 'c'
|
evaluate_xpath(@document, 'a/ns1:*').should == node_set(@c1)
|
||||||
@set[2].namespace.name.should == 'ns1'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'namespace wildcards' do
|
|
||||||
before do
|
|
||||||
@set = @evaluator.evaluate('a/*:b')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 2
|
example 'evaluate a containing a namespace wildcard and a name wildcard' do
|
||||||
|
evaluate_xpath(@document, 'a/*:*').should == @a1.children
|
||||||
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'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue