Fixed parsing of nth-child(n) and nth-child(-n)

This commit is contained in:
Yorick Peterse 2014-10-30 00:24:31 +01:00
parent 87f6b9c723
commit 0e6aefb727
2 changed files with 7 additions and 13 deletions

View File

@ -272,7 +272,7 @@ rule
nth
: T_NTH { s(:nth, s(:int, 1)) }
| T_MINUS T_NTH { s(:nth) }
| T_MINUS T_NTH { s(:nth, s(:int, 1)) }
| integer T_NTH { s(:nth, val[0]) }
| integer T_NTH integer { s(:nth, val[0], val[2]) }
;
@ -384,7 +384,7 @@ end
s(:eq, s(:mod, s(:sub, before_count, offset), s(:int, 2)), s(:int, 0))
)
else
node = s(:mod, before_count, step)
node = s(:eq, s(:mod, before_count, step), s(:int, 0))
end
end

View File

@ -34,7 +34,7 @@ describe Oga::CSS::Parser do
example 'parse the x:nth-child(even) pseudo class' do
parse_css('x:nth-child(even)').should == parse_xpath(
'descendant-or-self::x[(count(preceding-sibling::*) + 1) mod 2]'
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 2) = 0]'
)
end
@ -46,20 +46,14 @@ describe Oga::CSS::Parser do
end
example 'parse the x:nth-child(n) pseudo class' do
parse_css('x:nth-child(n)').should == s(
:pseudo,
s(:test, nil, 'x'),
'nth-child',
s(:nth)
parse_css('x:nth-child(n)').should == parse_xpath(
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-child(-n) pseudo class' do
parse_css('x:nth-child(-n)').should == s(
:pseudo,
s(:test, nil, 'x'),
'nth-child',
s(:nth)
parse_css('x:nth-child(-n)').should == parse_xpath(
'descendant-or-self::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
)
end