From 5f13cc9d73d8ff6805017a23d04a95b0238acaa8 Mon Sep 17 00:00:00 2001 From: Yorick Peterse <yorickpeterse@gmail.com> Date: Sun, 9 Nov 2014 18:56:49 +0100 Subject: [PATCH] Rewrote XPath evaluator wildcards spec. --- spec/oga/xpath/evaluator/wildcard_spec.rb | 82 +++++------------------ 1 file changed, 15 insertions(+), 67 deletions(-) diff --git a/spec/oga/xpath/evaluator/wildcard_spec.rb b/spec/oga/xpath/evaluator/wildcard_spec.rb index c468f67..8e90232 100644 --- a/spec/oga/xpath/evaluator/wildcard_spec.rb +++ b/spec/oga/xpath/evaluator/wildcard_spec.rb @@ -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