Lexer/parser specs for CSS axes without whitespace

This commit is contained in:
Yorick Peterse 2015-09-04 15:13:38 +02:00
parent 08bc23905e
commit c713f6250f
3 changed files with 27 additions and 9 deletions

View File

@ -182,12 +182,9 @@ module Oga
op_in = '*=';
op_hyphen_in = '|=';
# Whitespace preceding these tokens is _not_ matched to make the parser
# rules more consistent. As such input such as " > x" will result in
# tokens [T_SPACE, T_GREATER, T_IDENT].
op_greater = '>' whitespace*;
op_plus = '+' whitespace*;
op_tilde = '~' whitespace*;
op_greater = whitespace* '>' whitespace*;
op_plus = whitespace* '+' whitespace*;
op_tilde = whitespace* '~' whitespace*;
# Numbers
#

View File

@ -13,12 +13,15 @@ describe Oga::CSS::Lexer do
it 'lexes the expression "x > y"' do
lex_css('x > y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],
[:T_GREATER, nil],
[:T_IDENT, 'y']
]
end
it 'lexes the expression "x>y"' do
lex_css('x>y').should == lex_css('x > y')
end
it 'lexes the + axis' do
lex_css('+').should == [[:T_PLUS, nil]]
end
@ -30,12 +33,15 @@ describe Oga::CSS::Lexer do
it 'lexes the expression "x + y"' do
lex_css('x + y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],
[:T_PLUS, nil],
[:T_IDENT, 'y']
]
end
it 'lexes the expression "x+y"' do
lex_css('x+y').should == lex_css('x + y')
end
it 'lexes the ~ axis' do
lex_css('~').should == [[:T_TILDE, nil]]
end
@ -47,10 +53,13 @@ describe Oga::CSS::Lexer do
it 'lexes the expression "x ~ y"' do
lex_css('x ~ y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],
[:T_TILDE, nil],
[:T_IDENT, 'y']
]
end
it 'lexes the expression "x~y"' do
lex_css('x~y').should == lex_css('x ~ y')
end
end
end

View File

@ -6,6 +6,10 @@ describe Oga::CSS::Parser do
parse_css('x > y').should == parse_xpath('descendant::x/y')
end
it 'parses the > axis without whitespace' do
parse_css('x>y').should == parse_css('x > y')
end
it 'parses the > axis called on another > axis' do
parse_css('a > b > c').should == parse_xpath('descendant::a/b/c')
end
@ -28,6 +32,10 @@ describe Oga::CSS::Parser do
)
end
it 'parses the + axis without whitespace' do
parse_css('x+y').should == parse_css('x + y')
end
it 'parses the + axis with an identifier only at the right-hand side' do
parse_css('+ y').should == parse_xpath(
'following-sibling::*[1]/self::y'
@ -47,6 +55,10 @@ describe Oga::CSS::Parser do
)
end
it 'parses the ~ axis without whitespace' do
parse_css('x~y').should == parse_css('x ~ y')
end
it 'parses the ~ axis followed by another node test' do
parse_css('x ~ y z').should == parse_xpath(
'descendant::x/following-sibling::y/descendant::z'