Skip to content

Commit

Permalink
Specs for lexing CSS operators with whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorick Peterse committed Sep 4, 2015
1 parent 5f037c7 commit 08bc239
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions spec/oga/css/lexer/operators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,87 @@
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

0 comments on commit 08bc239

Please sign in to comment.