Specs for lexing CSS operators with whitespace

This commit is contained in:
Yorick Peterse 2015-09-04 15:08:26 +02:00
parent 5f037c76cc
commit 08bc23905e
1 changed files with 41 additions and 14 deletions

View File

@ -3,60 +3,87 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'operators' do describe 'operators' do
it 'lexes the = operator' do it 'lexes the = operator' do
lex_css('[=]').should == [ lex_css('[foo="bar"]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'],
[:T_EQ, nil], [:T_EQ, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ]
end end
it 'lexes the ~= operator' do it 'lexes the ~= operator' do
lex_css('[~=]').should == [ lex_css('[foo~="bar"]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'],
[:T_SPACE_IN, nil], [:T_SPACE_IN, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ]
end end
it 'lexes the ^= operator' do it 'lexes the ^= operator' do
lex_css('[^=]').should == [ lex_css('[foo^="bar"]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'],
[:T_STARTS_WITH, nil], [:T_STARTS_WITH, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ]
end end
it 'lexes the $= operator' do it 'lexes the $= operator' do
lex_css('[$=]').should == [ lex_css('[foo$="bar"]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'],
[:T_ENDS_WITH, nil], [:T_ENDS_WITH, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil], [:T_RBRACK, nil],
] ]
end end
it 'lexes the *= operator' do it 'lexes the *= operator' do
lex_css('[*=]').should == [ lex_css('[foo*="bar"]').should == [
[:T_LBRACK, nil],
[:T_IN, nil],
[:T_RBRACK, nil]
]
end
it 'lexes an identifier followed by the *= operator' do
lex_css('[foo *=]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_IN, nil], [:T_IN, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ]
end end
it 'lexes the |= operator' do it 'lexes the |= operator' do
lex_css('[|=]').should == [ lex_css('[foo|="bar"]').should == [
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'],
[:T_HYPHEN_IN, nil], [:T_HYPHEN_IN, nil],
[:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ]
end 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
end end