diff --git a/spec/oga/css/evaluator/pseudo_classes/empty_spec.rb b/spec/oga/css/evaluator/pseudo_classes/empty_spec.rb new file mode 100644 index 0000000..a41010e --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/empty_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':empty pseudo class' do + before do + @document = parse('foo') + + @a1 = @document.children[0].children[0] + @b1 = @document.children[0].children[1] + end + + example 'return a node set containing empty nodes' do + evaluate_css(@document, 'root :empty').should == node_set(@a1) + end + + example 'return a node set containing empty nodes with a node test' do + evaluate_css(@document, 'root a:empty').should == node_set(@a1) + end + + example 'return an empty node set containing non empty nodes' do + evaluate_css(@document, 'root b:empty').should == node_set + end + end +end diff --git a/spec/oga/css/evaluator/pseudo_classes/first_child_spec.rb b/spec/oga/css/evaluator/pseudo_classes/first_child_spec.rb new file mode 100644 index 0000000..1909861 --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/first_child_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':first-child pseudo class' do + before do + @document = parse('') + + @a1 = @document.children[0].children[0] + @b1 = @document.children[0].children[1] + end + + example 'return a node set containing the first child node' do + evaluate_css(@document, 'root :first-child').should == node_set(@a1) + end + + example 'return a node set containing the first child node with a node test' do + evaluate_css(@document, 'root a:first-child').should == node_set(@a1) + end + + example 'return an empty node set for non first-child nodes' do + evaluate_css(@document, 'root b:first-child').should == node_set + end + end +end diff --git a/spec/oga/css/evaluator/pseudo_classes/first_of_type_spec.rb b/spec/oga/css/evaluator/pseudo_classes/first_of_type_spec.rb new file mode 100644 index 0000000..8315926 --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/first_of_type_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':first-of-type pseudo class' do + before do + @document = parse('') + + @a1 = @document.children[0].children[0] + @b1 = @document.children[0].children[1] + end + + example 'return a node set containing the first node' do + evaluate_css(@document, 'root :first-of-type').should == node_set(@a1) + end + + example 'return a node set containing the first node with a node test' do + evaluate_css(@document, 'root a:first-of-type').should == node_set(@a1) + end + + example 'return a node set containing the first node' do + evaluate_css(@document, 'root b:first-of-type').should == node_set(@b1) + end + end +end diff --git a/spec/oga/css/evaluator/pseudo_classes/last_child_spec.rb b/spec/oga/css/evaluator/pseudo_classes/last_child_spec.rb new file mode 100644 index 0000000..7ffe1cf --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/last_child_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':last-child pseudo class' do + before do + @document = parse('') + + @a1 = @document.children[0].children[0] + @b1 = @document.children[0].children[1] + end + + example 'return a node set containing the last child node' do + evaluate_css(@document, 'root :last-child').should == node_set(@b1) + end + + example 'return a node set containing the last child node with a node test' do + evaluate_css(@document, 'root b:last-child').should == node_set(@b1) + end + + example 'return an empty node set for non last-child nodes' do + evaluate_css(@document, 'root a:last-child').should == node_set + end + end +end diff --git a/spec/oga/css/evaluator/pseudo_classes/last_of_type_spec.rb b/spec/oga/css/evaluator/pseudo_classes/last_of_type_spec.rb new file mode 100644 index 0000000..8aa0034 --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/last_of_type_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':last-of-type pseudo class' do + before do + @document = parse('') + + @b1 = @document.children[0].children[1] + @a2 = @document.children[0].children[2] + end + + example 'return a node set containing the last node' do + evaluate_css(@document, 'root :last-of-type').should == node_set(@a2) + end + + example 'return a node set containing the last node with a node test' do + evaluate_css(@document, 'root b:last-of-type').should == node_set(@b1) + end + + example 'return a node set containing the last node' do + evaluate_css(@document, 'root a:last-of-type').should == node_set(@a2) + end + end +end