Updated part of the CSS axis specs.

This commit is contained in:
Yorick Peterse 2014-10-20 19:07:06 +02:00
parent 21c27bf48e
commit e2b4f51e64
1 changed files with 12 additions and 30 deletions

View File

@ -3,34 +3,22 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'axes' do context 'axes' do
example 'parse the > axis' do example 'parse the > axis' do
parse_css('x > y').should == s( parse_css('x > y').should == parse_xpath('descendant-or-self::x/y')
:child,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end end
example 'parse the > axis called on another > axis' do example 'parse the > axis called on another > axis' do
parse_css('a > b > c').should == s( parse_css('a > b > c').should == parse_xpath('descendant-or-self::a/b/c')
:child,
s(:child, s(:test, nil, 'a'), s(:test, nil, 'b')),
s(:test, nil, 'c')
)
end end
example 'parse an > axis followed by an element with an ID' do example 'parse an > axis followed by an element with an ID' do
parse_css('x > foo#bar').should == s( parse_css('x > foo#bar').should == parse_xpath(
:child, 'descendant-or-self::x/foo[@id="bar"]'
s(:test, nil, 'x'),
s(:id, s(:test, nil, 'foo'), 'bar')
) )
end end
example 'parse an > axis followed by an element with a class' do example 'parse an > axis followed by an element with a class' do
parse_css('x > foo.bar').should == s( parse_css('x > foo.bar').should == parse_xpath(
:child, 'descendant-or-self::x/foo[contains(concat(" ", @class, " "), "bar")]'
s(:test, nil, 'x'),
s(:class, s(:test, nil, 'foo'), 'bar')
) )
end end
@ -51,26 +39,20 @@ describe Oga::CSS::Parser do
end end
example 'parse the ~ axis' do example 'parse the ~ axis' do
parse_css('x ~ y').should == s( parse_css('x ~ y').should == parse_xpath(
:following, 'descendant-or-self::x/following-sibling::y'
s(:test, nil, 'x'),
s(:test, nil, 'y')
) )
end end
example 'parse the ~ axis followed by another node test' do example 'parse the ~ axis followed by another node test' do
parse_css('x ~ y z').should == s( parse_css('x ~ y z').should == parse_xpath(
:path, 'descendant-or-self::x/following-sibling::y/z'
s(:following, s(:test, nil, 'x'), s(:test, nil, 'y')),
s(:test, nil, 'z')
) )
end end
example 'parse the ~ axis called on another ~ axis' do example 'parse the ~ axis called on another ~ axis' do
parse_css('a ~ b ~ c').should == s( parse_css('a ~ b ~ c').should == parse_xpath(
:following, 'descendant-or-self::a/following-sibling::b/following-sibling::c'
s(:following, s(:test, nil, 'a'), s(:test, nil, 'b')),
s(:test, nil, 'c')
) )
end end