CSS eval specs for various pseudo classes.

This includes the following pseudos:

* :empty
* :first-child
* :first-of-type
* :last-child
* :last-of-type
This commit is contained in:
Yorick Peterse 2014-11-13 10:10:16 +01:00
parent 19e9834583
commit 3237617bf5
5 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':empty pseudo class' do
before do
@document = parse('<root><a></a><b>foo</b></root>')
@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

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':first-child pseudo class' do
before do
@document = parse('<root><a /><b /></root>')
@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

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':first-of-type pseudo class' do
before do
@document = parse('<root><a /><b /></root>')
@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 <b> node' do
evaluate_css(@document, 'root b:first-of-type').should == node_set(@b1)
end
end
end

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':last-child pseudo class' do
before do
@document = parse('<root><a /><b /></root>')
@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

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':last-of-type pseudo class' do
before do
@document = parse('<root><a /><b /><a /></root>')
@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 <a> node' do
evaluate_css(@document, 'root a:last-of-type').should == node_set(@a2)
end
end
end