From c713f6250f2a32841e6af07bfca54f89f93843a9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 4 Sep 2015 15:13:38 +0200 Subject: [PATCH] Lexer/parser specs for CSS axes without whitespace --- lib/oga/css/lexer.rl | 9 +++------ spec/oga/css/lexer/axes_spec.rb | 15 ++++++++++++--- spec/oga/css/parser/axes_spec.rb | 12 ++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/oga/css/lexer.rl b/lib/oga/css/lexer.rl index a9416e2..3ef0a45 100644 --- a/lib/oga/css/lexer.rl +++ b/lib/oga/css/lexer.rl @@ -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 # diff --git a/spec/oga/css/lexer/axes_spec.rb b/spec/oga/css/lexer/axes_spec.rb index 7833a99..0471b62 100644 --- a/spec/oga/css/lexer/axes_spec.rb +++ b/spec/oga/css/lexer/axes_spec.rb @@ -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 diff --git a/spec/oga/css/parser/axes_spec.rb b/spec/oga/css/parser/axes_spec.rb index dd84b55..d09cbfd 100644 --- a/spec/oga/css/parser/axes_spec.rb +++ b/spec/oga/css/parser/axes_spec.rb @@ -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'