CSS evaluator specs for predicates and operators.
This commit is contained in:
parent
d5002010fe
commit
43200238c5
|
@ -0,0 +1,101 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'CSS selector evaluation' do
|
||||
context 'operators' do
|
||||
context '= operator' do
|
||||
before do
|
||||
@document = parse('<x a="b" />')
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
evaluate_css(@document, 'x[a = "b"]').should == @document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attribute values' do
|
||||
evaluate_css(@document, 'x[a = "c"]').should == node_set
|
||||
end
|
||||
end
|
||||
|
||||
context '~= operator' do
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
document = parse('<x a="1 2 3" />')
|
||||
|
||||
evaluate_css(document, 'x[a ~= "2"]').should == document.children
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with single attribute values' do
|
||||
document = parse('<x a="1" />')
|
||||
|
||||
evaluate_css(document, 'x[a ~= "1"]').should == document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attributes' do
|
||||
document = parse('<x a="1 2 3" />')
|
||||
|
||||
evaluate_css(document, 'x[a ~= "4"]').should == node_set
|
||||
end
|
||||
end
|
||||
|
||||
context '^= operator' do
|
||||
before do
|
||||
@document = parse('<x a="foo" />')
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
evaluate_css(@document, 'x[a ^= "fo"]').should == @document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attributes' do
|
||||
evaluate_css(@document, 'x[a ^= "bar"]').should == node_set
|
||||
end
|
||||
end
|
||||
|
||||
context '$= operator' do
|
||||
before do
|
||||
@document = parse('<x a="foo" />')
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
evaluate_css(@document, 'x[a $= "oo"]').should == @document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attributes' do
|
||||
evaluate_css(@document, 'x[a $= "x"]').should == node_set
|
||||
end
|
||||
end
|
||||
|
||||
context '*= operator' do
|
||||
before do
|
||||
@document = parse('<x a="foo" />')
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
evaluate_css(@document, 'x[a *= "o"]').should == @document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attributes' do
|
||||
evaluate_css(@document, 'x[a *= "x"]').should == node_set
|
||||
end
|
||||
end
|
||||
|
||||
context '|= operator' do
|
||||
example 'return a node set containing nodes with matching attributes' do
|
||||
document = parse('<x a="foo-bar" />')
|
||||
|
||||
evaluate_css(document, 'x[a |= "foo"]').should == document.children
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with single attribute values' do
|
||||
document = parse('<x a="foo" />')
|
||||
|
||||
evaluate_css(document, 'x[a |= "foo"]').should == document.children
|
||||
end
|
||||
|
||||
example 'return an empty node set for non matching attributes' do
|
||||
document = parse('<x a="bar" />')
|
||||
|
||||
evaluate_css(document, 'x[a |= "foo"]').should == node_set
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
context 'CSS selector evaluation' do
|
||||
context 'predicates' do
|
||||
before do
|
||||
@document = parse('<root><a class="foo" /></root>')
|
||||
|
||||
@a1 = @document.children[0].children[0]
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with an attribute' do
|
||||
evaluate_css(@document, 'root a[class]').should == node_set(@a1)
|
||||
end
|
||||
|
||||
example 'return a node set containing nodes with a matching attribute value' do
|
||||
evaluate_css(@document, 'root a[class="foo"]').should == node_set(@a1)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue