Fixed eval specs of :first-of-type & :last-of-type
This commit is contained in:
parent
b0b572a584
commit
8f3553f8f1
|
@ -4,24 +4,22 @@ describe 'CSS selector evaluation' do
|
|||
context ':first-of-type pseudo class' do
|
||||
before do
|
||||
@document = parse(<<-EOF)
|
||||
<dl>
|
||||
<dt>foo</dt>
|
||||
<dd>
|
||||
<dl>
|
||||
<dt>bar</dt>
|
||||
<dd>baz</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
</dl>
|
||||
<root>
|
||||
<a id="1" />
|
||||
<a id="2">
|
||||
<a id="3" />
|
||||
<a id="4" />
|
||||
</a>
|
||||
</root>
|
||||
EOF
|
||||
|
||||
@dt1 = @document.at_xpath('dl/dt')
|
||||
@dt2 = @document.at_xpath('dl/dd/dl/dt')
|
||||
@a1 = @document.at_xpath('root/a[1]')
|
||||
@a3 = @document.at_xpath('root/a[2]/a[2]')
|
||||
end
|
||||
|
||||
example 'return a node set containing all <dt> nodes' do
|
||||
evaluate_css(@document, 'dl dt:first-of-type')
|
||||
.should == node_set(@dt1, @dt2)
|
||||
example 'return a node set containing all first <a> nodes' do
|
||||
evaluate_css(@document, 'root a:first-of-type')
|
||||
.should == node_set(@a1, @a3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,22 +3,23 @@ require 'spec_helper'
|
|||
describe 'CSS selector evaluation' do
|
||||
context ':last-of-type pseudo class' do
|
||||
before do
|
||||
@document = parse('<root><a /><b /><a /></root>')
|
||||
@document = parse(<<-EOF)
|
||||
<root>
|
||||
<a id="1" />
|
||||
<a id="2">
|
||||
<a id="3" />
|
||||
<a id="4" />
|
||||
</a>
|
||||
</root>
|
||||
EOF
|
||||
|
||||
@b1 = @document.children[0].children[1]
|
||||
@a2 = @document.children[0].children[2]
|
||||
@a2 = @document.at_xpath('root/a[2]')
|
||||
@a4 = @document.at_xpath('root/a[2]/a[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)
|
||||
example 'return a node set containing all last <a> nodes' do
|
||||
evaluate_css(@document, 'root a:last-of-type')
|
||||
.should == node_set(@a2, @a4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue