diff --git a/spec/oga/css/evaluator/operators_spec.rb b/spec/oga/css/evaluator/operators_spec.rb new file mode 100644 index 0000000..459673f --- /dev/null +++ b/spec/oga/css/evaluator/operators_spec.rb @@ -0,0 +1,101 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context 'operators' do + context '= operator' do + before do + @document = parse('') + 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('') + + evaluate_css(document, 'x[a ~= "2"]').should == document.children + end + + example 'return a node set containing nodes with single attribute values' do + document = parse('') + + evaluate_css(document, 'x[a ~= "1"]').should == document.children + end + + example 'return an empty node set for non matching attributes' do + document = parse('') + + evaluate_css(document, 'x[a ~= "4"]').should == node_set + end + end + + context '^= operator' do + before do + @document = parse('') + 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('') + 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('') + 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('') + + evaluate_css(document, 'x[a |= "foo"]').should == document.children + end + + example 'return a node set containing nodes with single attribute values' do + document = parse('') + + evaluate_css(document, 'x[a |= "foo"]').should == document.children + end + + example 'return an empty node set for non matching attributes' do + document = parse('') + + evaluate_css(document, 'x[a |= "foo"]').should == node_set + end + end + end +end diff --git a/spec/oga/css/evaluator/predicates_spec.rb b/spec/oga/css/evaluator/predicates_spec.rb new file mode 100644 index 0000000..b6bf477 --- /dev/null +++ b/spec/oga/css/evaluator/predicates_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +context 'CSS selector evaluation' do + context 'predicates' do + before do + @document = parse('') + + @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