Support lexing or carriage returns

Fixes #89.
This commit is contained in:
Yorick Peterse 2015-04-03 00:46:37 +02:00
parent 602e231840
commit 0800654c96
3 changed files with 18 additions and 2 deletions

View File

@ -46,7 +46,7 @@
# stack.
#
newline = '\n' | '\r\n';
newline = '\r\n' | '\n' | '\r';
action count_newlines {
if ( fc == '\n' ) lines++;

View File

@ -41,6 +41,14 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 2]
]
end
it 'lexes an element with a carriage return in the open tag' do
lex("<p\r></p>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 2]
]
end
end
describe 'elements with attributes' do

View File

@ -10,10 +10,18 @@ describe Oga::XML::Lexer do
lex(' ').should == [[:T_TEXT, ' ', 1]]
end
it 'lexes a newline' do
it 'lexes a Unix newline' do
lex("\n").should == [[:T_TEXT, "\n", 1]]
end
it 'lexes a Windows newline' do
lex("\r\n").should == [[:T_TEXT, "\r\n", 1]]
end
it 'lexes a carriage return' do
lex("\r").should == [[:T_TEXT, "\r", 1]]
end
it 'lexes text followed by a newline' do
lex("foo\n").should == [[:T_TEXT, "foo\n", 1]]
end