Added spec for inline JS + comments.

This commit is contained in:
Yorick Peterse 2014-09-03 00:26:24 +02:00
parent 07617a9c47
commit 868df603ab
1 changed files with 14 additions and 12 deletions

View File

@ -3,23 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
context 'lexing inline Javascript' do context 'lexing inline Javascript' do
before do before do
@javascript = <<-EOF.strip @javascript = 'if ( number < 10 ) { }'
(function()
{
if ( some_number < 10 )
{
console.log('Hello');
}
})();
EOF
end end
example 'lex inline Javascript' do example 'lex inline Javascript' do
lex("<script>\n#{@javascript}\n</script>").should == [ lex("<script>#{@javascript}</script>").should == [
[:T_ELEM_START, nil, 1], [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, "\n#{@javascript}\n", 1], [:T_TEXT, @javascript, 1],
[:T_ELEM_END, nil, 9] [:T_ELEM_END, nil, 1]
]
end
example 'lex inline Javascript containing an XML comment' do
lex("<script>#{@javascript}<!--foo--></script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1],
[:T_ELEM_END, nil, 1],
[:T_COMMENT, 'foo', 1]
] ]
end end
end end