From 625b9eeffd4d12a29b55ab0f6f9c913eb12552d0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 7 Oct 2014 22:06:45 +0200 Subject: [PATCH] Lexing of CSS axes with surrounding whitespace. --- lib/oga/css/lexer.rl | 6 +++--- spec/oga/css/lexer/axes_spec.rb | 29 ++++++++++++++++++++++++++++ spec/oga/css/lexer/operators_spec.rb | 12 ------------ 3 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 spec/oga/css/lexer/axes_spec.rb diff --git a/lib/oga/css/lexer.rl b/lib/oga/css/lexer.rl index e7f4353..79b19c7 100644 --- a/lib/oga/css/lexer.rl +++ b/lib/oga/css/lexer.rl @@ -183,9 +183,9 @@ module Oga op_ends_with = '$='; op_in = '*='; op_hyphen_in = '|='; - op_child = '>'; - op_fol_direct = '+'; - op_fol = '~'; + op_child = whitespace* '>' whitespace*; + op_fol_direct = whitespace* '+' whitespace*; + op_fol = whitespace* '~' whitespace*; # Numbers # diff --git a/spec/oga/css/lexer/axes_spec.rb b/spec/oga/css/lexer/axes_spec.rb new file mode 100644 index 0000000..9043aff --- /dev/null +++ b/spec/oga/css/lexer/axes_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Oga::CSS::Lexer do + context 'axes' do + example 'lex the > axis' do + lex_css('>').should == [[:T_CHILD, nil]] + end + + example 'lex the > axis with surrounding whitespace' do + lex_css('>').should == [[:T_CHILD, nil]] + end + + example 'lex the + axis' do + lex_css('+').should == [[:T_FOLLOWING_DIRECT, nil]] + end + + example 'lex the + axis with surrounding whitespace' do + lex_css(' + ').should == [[:T_FOLLOWING_DIRECT, nil]] + end + + example 'lex the ~ axis' do + lex_css('~').should == [[:T_FOLLOWING, nil]] + end + + example 'lex the ~ axis with surrounding whitespace' do + lex_css(' ~ ').should == [[:T_FOLLOWING, nil]] + end + end +end diff --git a/spec/oga/css/lexer/operators_spec.rb b/spec/oga/css/lexer/operators_spec.rb index 493aba6..1bc053e 100644 --- a/spec/oga/css/lexer/operators_spec.rb +++ b/spec/oga/css/lexer/operators_spec.rb @@ -33,17 +33,5 @@ describe Oga::CSS::Lexer do example 'lex the |= operator' do lex_css('|=').should == [[:T_HYPHEN_IN, nil]] end - - example 'lex the > operator' do - lex_css('>').should == [[:T_CHILD, nil]] - end - - example 'lex the + operator' do - lex_css('+').should == [[:T_FOLLOWING_DIRECT, nil]] - end - - example 'lex the ~ operator' do - lex_css('~').should == [[:T_FOLLOWING, nil]] - end end end