From c874ceabb9f5baa04f9d116e6c6c395a6f060ebf Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 13 Nov 2014 23:54:47 +0100 Subject: [PATCH] CSS evaluator specs for :nth-last-child --- .../pseudo_classes/nth_last_child_spec.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 spec/oga/css/evaluator/pseudo_classes/nth_last_child_spec.rb diff --git a/spec/oga/css/evaluator/pseudo_classes/nth_last_child_spec.rb b/spec/oga/css/evaluator/pseudo_classes/nth_last_child_spec.rb new file mode 100644 index 0000000..86bf26b --- /dev/null +++ b/spec/oga/css/evaluator/pseudo_classes/nth_last_child_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'CSS selector evaluation' do + context ':nth-last-child pseudo class' do + before do + @document = parse('') + + @root = @document.children[0] + @a1 = @root.children[0] + @a2 = @root.children[1] + @a3 = @root.children[2] + @a4 = @root.children[3] + end + + example 'return a node set containing the last child node' do + evaluate_css(@document, 'root :nth-last-child(1)').should == node_set(@a4) + end + + example 'return a node set containing even nodes' do + evaluate_css(@document, 'root :nth-last-child(even)') + .should == node_set(@a1, @a3) + end + + example 'return a node set containing odd nodes' do + evaluate_css(@document, 'root :nth-last-child(odd)') + .should == node_set(@a2, @a4) + end + + example 'return a node set containing every 2 nodes starting at node 3' do + evaluate_css(@document, 'root :nth-last-child(2n+2)') + .should == node_set(@a1, @a3) + end + + example 'return a node set containing all nodes' do + evaluate_css(@document, 'root :nth-last-child(n)') + .should == @root.children + end + + example 'return a node set containing the first two nodes' do + evaluate_css(@document, 'root :nth-last-child(-n+2)') + .should == node_set(@a3, @a4) + end + + example 'return a node set containing all nodes starting at node 2' do + evaluate_css(@document, 'root :nth-last-child(n+2)') + .should == node_set(@a1, @a2, @a3) + end + end +end