Rewrote CSS evaluator paths spec.

This commit is contained in:
Yorick Peterse 2014-11-09 23:51:23 +01:00
parent fb1927a7c7
commit 1f855dc982
1 changed files with 21 additions and 90 deletions

View File

@ -1,111 +1,42 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'paths' do
before do before do
@document = parse('<a xmlns:ns1="x"><b></b><b></b><ns1:c></ns1:c></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
context 'regular paths' do example 'return a node set containing the root node' do
before do evaluate_css(@document, 'a').should == node_set(@a1)
@set = evaluate_css(@document, 'a')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing nested nodes' do
evaluate_css(@document, 'a b').should == node_set(@b1, @b2)
example 'include the <a> node' do
@set[0].should == @document.children[0]
end
end end
context 'nested paths' do example 'return a node set containing namespaced nodes' do
before do evaluate_css(@document, 'a ns1|c').should == node_set(@c1)
@set = evaluate_css(@document, 'a b')
end end
it_behaves_like :node_set, :length => 2 example 'return a node set containing wildcard nodes' do
evaluate_css(@document, 'a *').should == node_set(@b1, @b2, @c1)
example 'include the first <b> node' do
@set[0].should == @document.children[0].children[0]
end end
example 'include the second <b> node' do example 'return a node set containing nodes with namespace wildcards' do
@set[1].should == @document.children[0].children[1] evaluate_css(@document, 'a *|c')
end
end end
context 'paths with namespaces' do example 'return a node set containing nodes with a namespace name and name wildcard' do
before do evaluate_css(@document, 'a ns1|*').should == node_set(@c1)
@set = evaluate_css(@document, 'a ns1|c')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing nodes using full wildcards' do
evaluate_css(@document, 'a *|*').should == node_set(@b1, @b2, @c1)
example 'include the <n1:c> node' do
@set[0].should == @document.children[0].children[2]
end
end
context 'paths with name wildcards' do
before do
@set = evaluate_css(@document, 'a *')
end
it_behaves_like :node_set, :length => 3
example 'include the first <b> node' do
@set[0].should == @document.children[0].children[0]
end
example 'include the second <b> node' do
@set[1].should == @document.children[0].children[1]
end
example 'include the second <ns1:c> node' do
@set[2].should == @document.children[0].children[2]
end
end
context 'paths with namespace wildcards' do
before do
@set = evaluate_css(@document, 'a *|c')
end
it_behaves_like :node_set, :length => 1
example 'include the <ns1:c> node' do
@set[0].should == @document.children[0].children[2]
end
end
context 'paths with namespaces and name wildcards' do
before do
@set = evaluate_css(@document, 'a ns1|*')
end
it_behaves_like :node_set, :length => 1
example 'include the <ns1:c> node' do
@set[0].should == @document.children[0].children[2]
end
end
context 'paths with full wildcards' do
before do
@set = evaluate_css(@document, 'a *|*')
end
it_behaves_like :node_set, :length => 3
example 'include the first <b> node' do
@set[0].should == @document.children[0].children[0]
end
example 'include the second <b> node' do
@set[1].should == @document.children[0].children[1]
end
example 'include the second <ns1:c> node' do
@set[2].should == @document.children[0].children[2]
end end
end end
end end