diff --git a/spec/oga/parser/lexer/cdata_spec.rb b/spec/oga/parser/lexer/cdata_spec.rb new file mode 100644 index 0000000..5244211 --- /dev/null +++ b/spec/oga/parser/lexer/cdata_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Oga::Lexer do + context 'cdata tags' do + example 'lex a cdata tag' do + lex('').should == [ + [:T_SMALLER, '<', 1, 1], + [:T_BANG, '!', 1, 2], + [:T_LBRACKET, '[', 1, 3], + [:T_TEXT, 'CDATA', 1, 4], + [:T_LBRACKET, '[', 1, 9], + [:T_TEXT, 'foo', 1, 10], + [:T_RBRACKET, ']', 1, 13], + [:T_RBRACKET, ']', 1, 14], + [:T_GREATER, '>', 1, 15], + ] + end + end +end diff --git a/spec/oga/parser/lexer/comments_spec.rb b/spec/oga/parser/lexer/comments_spec.rb new file mode 100644 index 0000000..537f8e5 --- /dev/null +++ b/spec/oga/parser/lexer/comments_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Oga::Lexer do + context 'comments' do + example 'lex a comment' do + lex('').should == [ + [:T_SMALLER, '<', 1, 1], + [:T_BANG, '!', 1, 2], + [:T_DASH, '-', 1, 3], + [:T_DASH, '-', 1, 4], + [:T_SPACE, ' ', 1, 5], + [:T_TEXT, 'foo', 1, 6], + [:T_SPACE, ' ', 1, 9], + [:T_DASH, '-', 1, 10], + [:T_DASH, '-', 1, 11], + [:T_GREATER, '>', 1, 12] + ] + end + end +end diff --git a/spec/oga/parser/lexer/doctype_spec.rb b/spec/oga/parser/lexer/doctype_spec.rb new file mode 100644 index 0000000..7e430ad --- /dev/null +++ b/spec/oga/parser/lexer/doctype_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Oga::Lexer do + context 'doctypes' do + example 'lex the HTML5 doctype' do + lex('').should == [ + [:T_DOCTYPE, '', 1, 1] + ] + end + + example 'lex a random doctype' do + lex('').should == [ + [:T_DOCTYPE, '', 1, 1] + ] + end + end +end diff --git a/spec/oga/parser/lexer/general_spec.rb b/spec/oga/parser/lexer/general_spec.rb new file mode 100644 index 0000000..035bf9b --- /dev/null +++ b/spec/oga/parser/lexer/general_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe Oga::Lexer do + context 'regular text' do + example 'lex regular text' do + lex('hello').should == [[:T_TEXT, 'hello', 1, 1]] + end + end + + context 'whitespace' do + example 'lex regular whitespace' do + lex(' ').should == [[:T_SPACE, ' ', 1, 1]] + end + + example 'lex a newline' do + lex("\n").should == [[:T_NEWLINE, "\n", 1, 1]] + end + + example 'advance column numbers for spaces' do + lex(' ').should == [ + [:T_SPACE, ' ', 1, 1], + [:T_SPACE, ' ', 1, 2] + ] + end + + example 'advance line numbers for newlines' do + lex("\n ").should == [ + [:T_NEWLINE, "\n", 1, 1], + [:T_SPACE, ' ', 2, 1] + ] + end + end +end diff --git a/spec/oga/lexer_spec.rb b/spec/oga/parser/lexer/tags_spec.rb similarity index 50% rename from spec/oga/lexer_spec.rb rename to spec/oga/parser/lexer/tags_spec.rb index 9c0ed68..51453fe 100644 --- a/spec/oga/lexer_spec.rb +++ b/spec/oga/parser/lexer/tags_spec.rb @@ -1,36 +1,6 @@ require 'spec_helper' describe Oga::Lexer do - context 'regular text' do - example 'lex regular text' do - lex('hello').should == [[:T_TEXT, 'hello', 1, 1]] - end - end - - context 'whitespace' do - example 'lex regular whitespace' do - lex(' ').should == [[:T_SPACE, ' ', 1, 1]] - end - - example 'lex a newline' do - lex("\n").should == [[:T_NEWLINE, "\n", 1, 1]] - end - - example 'advance column numbers for spaces' do - lex(' ').should == [ - [:T_SPACE, ' ', 1, 1], - [:T_SPACE, ' ', 1, 2] - ] - end - - example 'advance line numbers for newlines' do - lex("\n ").should == [ - [:T_NEWLINE, "\n", 1, 1], - [:T_SPACE, ' ', 2, 1] - ] - end - end - context 'tags' do example 'lex an opening tag' do lex('
').should == [ @@ -99,51 +69,4 @@ describe Oga::Lexer do ] end end - - context 'comments' do - example 'lex a comment' do - lex('').should == [ - [:T_SMALLER, '<', 1, 1], - [:T_BANG, '!', 1, 2], - [:T_DASH, '-', 1, 3], - [:T_DASH, '-', 1, 4], - [:T_SPACE, ' ', 1, 5], - [:T_TEXT, 'foo', 1, 6], - [:T_SPACE, ' ', 1, 9], - [:T_DASH, '-', 1, 10], - [:T_DASH, '-', 1, 11], - [:T_GREATER, '>', 1, 12] - ] - end - end - - context 'cdata tags' do - example 'lex a cdata tag' do - lex('').should == [ - [:T_SMALLER, '<', 1, 1], - [:T_BANG, '!', 1, 2], - [:T_LBRACKET, '[', 1, 3], - [:T_TEXT, 'CDATA', 1, 4], - [:T_LBRACKET, '[', 1, 9], - [:T_TEXT, 'foo', 1, 10], - [:T_RBRACKET, ']', 1, 13], - [:T_RBRACKET, ']', 1, 14], - [:T_GREATER, '>', 1, 15], - ] - end - end - - context 'doctypes' do - example 'lex the HTML5 doctype' do - lex('').should == [ - [:T_DOCTYPE, '', 1, 1] - ] - end - - example 'lex a random doctype' do - lex('').should == [ - [:T_DOCTYPE, '', 1, 1] - ] - end - end end