Support for parsing CSS operators.

This commit is contained in:
Yorick Peterse committed 2014-10-05 10:06:58 +02:00
1 parent e03cd42735
commit 8fef62fca0
5 files changed
+153 -2

No files matched your search

+4
View File
@@ -22,6 +22,10 @@ describe Oga::CSS::Lexer do
lex_css('*=').should == [[:T_IN, nil]]
end
example 'lex an identifier followed by the *= operator' do
lex_css('foo *=').should == [[:T_IDENT, 'foo'], [:T_IN, nil]]
end
example 'lex the |= operator' do
lex_css('|=').should == [[:T_HYPHEN_IN, nil]]
end
+13
View File
@@ -0,0 +1,13 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'strings' do
example 'lex a single quoted string' do
lex_css("'foo'").should == [[:T_STRING, 'foo']]
end
example 'lex a double quoted string' do
lex_css('"foo"').should == [[:T_STRING, 'foo']]
end
end
end
+83
View File
@@ -0,0 +1,83 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'operators' do
example 'parse the = operator' do
parse_css('x[a="b"]').should == s(
:test,
nil,
'x',
s(:eq, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the ~= operator' do
parse_css('x[a~="b"]').should == s(
:test,
nil,
'x',
s(:space_in, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the ^= operator' do
parse_css('x[a^="b"]').should == s(
:test,
nil,
'x',
s(:starts_with, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the $= operator' do
parse_css('x[a$="b"]').should == s(
:test,
nil,
'x',
s(:ends_with, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the *= operator' do
parse_css('x[a*="b"]').should == s(
:test,
nil,
'x',
s(:in, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the |= operator' do
parse_css('x[a|="b"]').should == s(
:test,
nil,
'x',
s(:hyphen_in, s(:test, nil, 'a'), s(:string, 'b'))
)
end
example 'parse the > operator' do
parse_css('x > y').should == s(
:child,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the + operator' do
parse_css('x + y').should == s(
:following_direct,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
example 'parse the ~ operator' do
parse_css('x ~ y').should == s(
:following,
s(:test, nil, 'x'),
s(:test, nil, 'y')
)
end
end
end