From 08bc23905e3baca02f556d840216f363d87d91da Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 4 Sep 2015 15:08:26 +0200 Subject: [PATCH] Specs for lexing CSS operators with whitespace --- spec/oga/css/lexer/operators_spec.rb | 55 +++++++++++++++++++++------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/spec/oga/css/lexer/operators_spec.rb b/spec/oga/css/lexer/operators_spec.rb index 9ed9ca7..6e37e21 100644 --- a/spec/oga/css/lexer/operators_spec.rb +++ b/spec/oga/css/lexer/operators_spec.rb @@ -3,60 +3,87 @@ require 'spec_helper' describe Oga::CSS::Lexer do describe 'operators' do it 'lexes the = operator' do - lex_css('[=]').should == [ + lex_css('[foo="bar"]').should == [ [:T_LBRACK, nil], + [:T_IDENT, 'foo'], [:T_EQ, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil] ] end it 'lexes the ~= operator' do - lex_css('[~=]').should == [ + lex_css('[foo~="bar"]').should == [ [:T_LBRACK, nil], + [:T_IDENT, 'foo'], [:T_SPACE_IN, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil] ] end it 'lexes the ^= operator' do - lex_css('[^=]').should == [ + lex_css('[foo^="bar"]').should == [ [:T_LBRACK, nil], + [:T_IDENT, 'foo'], [:T_STARTS_WITH, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil] ] end it 'lexes the $= operator' do - lex_css('[$=]').should == [ + lex_css('[foo$="bar"]').should == [ [:T_LBRACK, nil], + [:T_IDENT, 'foo'], [:T_ENDS_WITH, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil], ] end it 'lexes the *= operator' do - lex_css('[*=]').should == [ - [:T_LBRACK, nil], - [:T_IN, nil], - [:T_RBRACK, nil] - ] - end - - it 'lexes an identifier followed by the *= operator' do - lex_css('[foo *=]').should == [ + lex_css('[foo*="bar"]').should == [ [:T_LBRACK, nil], [:T_IDENT, 'foo'], [:T_IN, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil] ] end it 'lexes the |= operator' do - lex_css('[|=]').should == [ + lex_css('[foo|="bar"]').should == [ [:T_LBRACK, nil], + [:T_IDENT, 'foo'], [:T_HYPHEN_IN, nil], + [:T_STRING, 'bar'], [:T_RBRACK, nil] ] end + + it 'lexes the = operator surrounded by whitespace' do + lex_css('[foo = "bar"]').should == lex_css('[foo="bar"]') + end + + it 'lexes the ~= operator surrounded by whitespace' do + lex_css('[foo ~= "bar"]').should == lex_css('[foo~="bar"]') + end + + it 'lexes the ^= operator surrounded by whitespace' do + lex_css('[foo ^= "bar"]').should == lex_css('[foo^="bar"]') + end + + it 'lexes the $= operator surrounded by whitespace' do + lex_css('[foo $= "bar"]').should == lex_css('[foo$="bar"]') + end + + it 'lexes the *= operator surrounded by whitespace' do + lex_css('[foo *= "bar"]').should == lex_css('[foo*="bar"]') + end + + it 'lexes the |= operator surrounded by whitespace' do + lex_css('[foo |= "bar"]').should == lex_css('[foo|="bar"]') + end end end