From 6e18287a1dd692c63e4961f4f960171499a311d4 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 7 Oct 2014 19:01:04 +0200 Subject: [PATCH] Initial specs for parsing CSS IDs/classes. --- spec/oga/css/parser/classes_spec.rb | 21 +++++++++++++++++++++ spec/oga/css/parser/ids_spec.rb | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 spec/oga/css/parser/classes_spec.rb create mode 100644 spec/oga/css/parser/ids_spec.rb diff --git a/spec/oga/css/parser/classes_spec.rb b/spec/oga/css/parser/classes_spec.rb new file mode 100644 index 0000000..f726df1 --- /dev/null +++ b/spec/oga/css/parser/classes_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context 'classes' do + example 'parse a class selector' do + parse_css('.foo').should == s(:class, 'foo') + end + + example 'parse a selector for an element with a class' do + parse_css('foo.bar').should == s(:class, 'bar', s(:test, nil, 'foo')) + end + + example 'parse a selector using multiple classes' do + parse_css('.foo.bar').should == s(:class, 'bar', s(:class, 'foo')) + end + + example 'parse a selector using a class and an ID' do + parse_css('#foo.bar').should == s(:class, 'bar', s(:id, 'foo')) + end + end +end diff --git a/spec/oga/css/parser/ids_spec.rb b/spec/oga/css/parser/ids_spec.rb new file mode 100644 index 0000000..a783a14 --- /dev/null +++ b/spec/oga/css/parser/ids_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context 'IDs' do + example 'parse an ID selector' do + parse_css('#foo').should == s(:id, 'foo') + end + + example 'parse a selector for an element with an ID' do + parse_css('foo#bar').should == s(:id, 'bar', s(:test, nil, 'foo')) + end + + example 'parse a selector using an ID and a class' do + parse_css('.foo#bar').should == s(:id, 'bar', s(:class, 'foo')) + end + end +end