Broke up lexer specs into separate files.

This commit is contained in:
Yorick Peterse 2014-02-27 20:55:29 +01:00
parent 2c82f88f6c
commit cdaa14a28e
5 changed files with 89 additions and 77 deletions

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe Oga::Lexer do
context 'cdata tags' do
example 'lex a cdata tag' do
lex('<![CDATA[foo]]>').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

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe Oga::Lexer do
context 'comments' do
example 'lex a comment' do
lex('<!-- foo -->').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

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe Oga::Lexer do
context 'doctypes' do
example 'lex the HTML5 doctype' do
lex('<!DOCTYPE html>').should == [
[:T_DOCTYPE, '<!DOCTYPE html>', 1, 1]
]
end
example 'lex a random doctype' do
lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
[:T_DOCTYPE, '<!DOCTYPE HTML PUBLIC "foobar" "baz">', 1, 1]
]
end
end
end

View File

@ -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

View File

@ -1,36 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Oga::Lexer do 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 context 'tags' do
example 'lex an opening tag' do example 'lex an opening tag' do
lex('<p>').should == [ lex('<p>').should == [
@ -99,51 +69,4 @@ describe Oga::Lexer do
] ]
end end
end end
context 'comments' do
example 'lex a comment' do
lex('<!-- foo -->').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('<![CDATA[foo]]>').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('<!DOCTYPE html>').should == [
[:T_DOCTYPE, '<!DOCTYPE html>', 1, 1]
]
end
example 'lex a random doctype' do
lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
[:T_DOCTYPE, '<!DOCTYPE HTML PUBLIC "foobar" "baz">', 1, 1]
]
end
end
end end