Merged on_element_start with on_element_name
This makes it easier to automatically insert preceding tokens when starting a new element as we now have access to the name. Previously on_element_start would be invoked first which doesn't receive an argument.
This commit is contained in:
parent
853d804f34
commit
8135074a62
|
@ -113,7 +113,6 @@ VALUE oga_xml_lexer_advance(VALUE self, VALUE data_block)
|
|||
ID id_on_element_name = rb_intern("on_element_name");
|
||||
ID id_on_element_ns = rb_intern("on_element_ns");
|
||||
ID id_on_element_open_end = rb_intern("on_element_open_end");
|
||||
ID id_on_element_start = rb_intern("on_element_start");
|
||||
ID id_on_proc_ins_end = rb_intern("on_proc_ins_end");
|
||||
ID id_on_proc_ins_name = rb_intern("on_proc_ins_name");
|
||||
ID id_on_proc_ins_start = rb_intern("on_proc_ins_start");
|
||||
|
|
|
@ -121,7 +121,6 @@ public class Lexer extends RubyObject
|
|||
String id_on_element_name = "on_element_name";
|
||||
String id_on_element_ns = "on_element_ns";
|
||||
String id_on_element_open_end = "on_element_open_end";
|
||||
String id_on_element_start = "on_element_start";
|
||||
String id_on_proc_ins_end = "on_proc_ins_end";
|
||||
String id_on_proc_ins_name = "on_proc_ins_name";
|
||||
String id_on_proc_ins_start = "on_proc_ins_start";
|
||||
|
|
|
@ -367,7 +367,6 @@
|
|||
element_end = '</' identifier (':' identifier)* '>';
|
||||
|
||||
action start_element {
|
||||
callback_simple(id_on_element_start);
|
||||
fhold;
|
||||
fnext element_name;
|
||||
}
|
||||
|
|
|
@ -337,13 +337,6 @@ module Oga
|
|||
add_token(:T_XML_DECL_END)
|
||||
end
|
||||
|
||||
##
|
||||
# Called on the start of an element.
|
||||
#
|
||||
def on_element_start
|
||||
add_token(:T_ELEM_START)
|
||||
end
|
||||
|
||||
##
|
||||
# Called on the start of a processing instruction.
|
||||
#
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
%terminals T_DOCTYPE_INLINE;
|
||||
%terminals T_COMMENT_START T_COMMENT_BODY T_COMMENT_END;
|
||||
%terminals T_CDATA_START T_CDATA_BODY T_CDATA_END;
|
||||
%terminals T_ELEM_START T_ELEM_NAME T_ELEM_NS T_ELEM_END T_ATTR T_ATTR_NS;
|
||||
%terminals T_ELEM_NAME T_ELEM_NS T_ELEM_END T_ATTR T_ATTR_NS;
|
||||
%terminals T_XML_DECL_START T_XML_DECL_END;
|
||||
%terminals T_PROC_INS_START T_PROC_INS_NAME T_PROC_INS_BODY T_PROC_INS_END;
|
||||
|
||||
|
@ -136,9 +136,9 @@ element_name_ns
|
|||
;
|
||||
|
||||
element_start
|
||||
= T_ELEM_START element_name_ns attributes
|
||||
= element_name_ns attributes
|
||||
{
|
||||
on_element(val[1][0], val[1][1], val[2])
|
||||
on_element(val[0][0], val[0][1], val[1])
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -37,12 +37,10 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes two CDATA tags following each other' do
|
||||
lex('<a><![CDATA[foo]]><b><![CDATA[bar]]></b></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_CDATA_START, nil, 1],
|
||||
[:T_CDATA_BODY, 'foo', 1],
|
||||
[:T_CDATA_END, nil, 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'b', 1],
|
||||
[:T_CDATA_START, nil, 1],
|
||||
[:T_CDATA_BODY, 'bar', 1],
|
||||
|
|
|
@ -59,7 +59,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an element followed by a comment' do
|
||||
lex('<p></p><!---->').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_COMMENT_START, nil, 1],
|
||||
|
@ -69,12 +68,10 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes two comments following each other' do
|
||||
lex('<a><!--foo--><b><!--bar--></b></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_COMMENT_START, nil, 1],
|
||||
[:T_COMMENT_BODY, 'foo', 1],
|
||||
[:T_COMMENT_END, nil, 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'b', 1],
|
||||
[:T_COMMENT_START, nil, 1],
|
||||
[:T_COMMENT_BODY, 'bar', 1],
|
||||
|
|
|
@ -20,17 +20,14 @@ describe Oga::XML::Lexer do
|
|||
[:T_TEXT, "\n", 1],
|
||||
|
||||
# <html>
|
||||
[:T_ELEM_START, nil, 2],
|
||||
[:T_ELEM_NAME, 'html', 2],
|
||||
[:T_TEXT, "\n", 2],
|
||||
|
||||
# <head>
|
||||
[:T_ELEM_START, nil, 3],
|
||||
[:T_ELEM_NAME, 'head', 3],
|
||||
[:T_TEXT, "\n", 3],
|
||||
|
||||
# <title>Title</title>
|
||||
[:T_ELEM_START, nil, 4],
|
||||
[:T_ELEM_NAME, 'title', 4],
|
||||
[:T_TEXT, 'Title', 4],
|
||||
[:T_ELEM_END, nil, 4],
|
||||
|
@ -41,7 +38,6 @@ describe Oga::XML::Lexer do
|
|||
[:T_TEXT, "\n", 5],
|
||||
|
||||
# <body></body>
|
||||
[:T_ELEM_START, nil, 6],
|
||||
[:T_ELEM_NAME, 'body', 6],
|
||||
[:T_ELEM_END, nil, 6],
|
||||
[:T_TEXT, "\n", 6],
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'elements' do
|
||||
it 'lexes an opening element' do
|
||||
lex('<p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -12,7 +11,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an opening element with a stray double quote' do
|
||||
lex('<p">').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -20,7 +18,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an opening element with a stray double quoted string' do
|
||||
lex('<p"">').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -28,7 +25,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an opening an closing element' do
|
||||
lex('<p></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -36,7 +32,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an opening an closing element with a stray double quote' do
|
||||
lex('<p"></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -44,7 +39,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an opening an closing element with a stray double quoted string' do
|
||||
lex('<p""></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -52,7 +46,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element with text inside it' do
|
||||
lex('<p>Hello</p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_TEXT, 'Hello', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -62,7 +55,6 @@ describe Oga::XML::Lexer do
|
|||
it 'lexes text followed by a paragraph element' do
|
||||
lex('Foo<p>').should == [
|
||||
[:T_TEXT, 'Foo', 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -70,7 +62,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an element with a newline in the open tag' do
|
||||
lex("<p\n></p>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
]
|
||||
|
@ -78,7 +69,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
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]
|
||||
]
|
||||
|
@ -88,7 +78,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'elements with attributes' do
|
||||
it 'lexes an element with an attribute without a value' do
|
||||
lex('<p foo></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -97,7 +86,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an element with an empty attribute followed by a stray double quote' do
|
||||
lex('<p foo"></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -106,7 +94,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an element with an attribute with an empty value' do
|
||||
lex('<p foo=""></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -117,7 +104,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute value followed by a stray double quote' do
|
||||
lex('<p foo="""></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -128,7 +114,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute value followed by a stray single quote' do
|
||||
lex('<p foo=""\'></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'foo', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -139,7 +124,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element with attributes' do
|
||||
lex('<p class="foo">Hello</p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -152,7 +136,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element with a newline in an attribute' do
|
||||
lex("<p class=\"\nfoo\">Hello</p>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -165,7 +148,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element with single quoted attributes' do
|
||||
lex("<p class='foo'></p>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -177,7 +159,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element with a namespaced attribute' do
|
||||
lex('<p foo:bar="baz"></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR_NS, 'foo', 1],
|
||||
[:T_ATTR, 'bar', 1],
|
||||
|
@ -192,9 +173,7 @@ describe Oga::XML::Lexer do
|
|||
describe 'nested elements' do
|
||||
it 'lexes a nested element' do
|
||||
lex('<p><a></a></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -203,10 +182,8 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes nested elements and text nodes' do
|
||||
lex('<p>Foo<a>bar</a>baz</p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_TEXT, 'Foo', 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_TEXT, 'bar', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
|
@ -219,7 +196,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'void elements' do
|
||||
it 'lexes a void element' do
|
||||
lex('<br />').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -227,7 +203,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element with an attribute' do
|
||||
lex('<br class="foo" />').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -240,7 +215,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'without a space before the closing tag' do
|
||||
it 'lexes a void element' do
|
||||
lex('<br/>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -248,7 +222,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element with an attribute' do
|
||||
lex('<br class="foo"/>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -263,7 +236,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'elements with namespaces' do
|
||||
it 'lexes an element with namespaces' do
|
||||
lex('<foo:p></p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NS, 'foo', 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -272,7 +244,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an element with a start and end namespace' do
|
||||
lex('<foo:p></foo:p>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NS, 'foo', 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
|
|
@ -11,7 +11,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a paragraph element' do
|
||||
lex(@enum).should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'HTML attributes' do
|
||||
it 'lexes an attribute with an unquoted value' do
|
||||
lex_html('<a href=foo></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ATTR, 'href', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -16,7 +15,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute with an unquoted value containing a space' do
|
||||
lex_html('<a href=foo bar></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ATTR, 'href', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -29,7 +27,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute with an unquoted value containing an underscore' do
|
||||
lex_html('<a href=foo_bar></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ATTR, 'href', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -41,7 +38,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute with an unquoted value containing a dash' do
|
||||
lex_html('<a href=foo-bar></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ATTR, 'href', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -53,7 +49,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes an attribute with an unquoted value containing a slash' do
|
||||
lex_html('<a href=foo/></a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ATTR, 'href', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'HTML script elements' do
|
||||
it 'treats the content of a script tag as plain text' do
|
||||
lex_html('<script>foo <bar</script>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo ', 1],
|
||||
[:T_TEXT, '<', 1],
|
||||
|
@ -15,7 +14,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'treats style tags inside script tags as text' do
|
||||
lex_html('<script><style></style></script>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, '<', 1],
|
||||
[:T_TEXT, 'style>', 1],
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'HTML style elements' do
|
||||
it 'lexes an empty <style> tag' do
|
||||
lex_html('<style></style>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'style', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -12,7 +11,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'treats the content of a style tag as plain text' do
|
||||
lex_html('<style>foo <bar</style>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'style', 1],
|
||||
[:T_TEXT, 'foo ', 1],
|
||||
[:T_TEXT, '<', 1],
|
||||
|
@ -23,7 +21,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'treats script tags inside style tags as text' do
|
||||
lex_html('<style><script></script></style>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'style', 1],
|
||||
[:T_TEXT, '<', 1],
|
||||
[:T_TEXT, 'script>', 1],
|
||||
|
@ -35,7 +32,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a multi-line <style> tag using a String as the input' do
|
||||
lex_html("<style>foo\nbar</style>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'style', 1],
|
||||
[:T_TEXT, "foo\nbar", 1],
|
||||
[:T_ELEM_END, nil, 2]
|
||||
|
@ -44,7 +40,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a multi-line <style> tag using an IO as the input' do
|
||||
lex_stringio("<style>foo\nbar</style>", :html => true).should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'style', 1],
|
||||
[:T_TEXT, "foo\n", 1],
|
||||
[:T_TEXT, 'bar', 2],
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'HTML void elements' do
|
||||
it 'lexes a void element that omits the closing /' do
|
||||
lex_html('<link>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'link', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -12,7 +11,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a upper case void element' do
|
||||
lex_html('<BR>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, "BR", 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -20,7 +18,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes text after a void element' do
|
||||
lex_html('<link>foo').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'link', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_TEXT, 'foo', 1]
|
||||
|
@ -29,9 +26,7 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element inside another element' do
|
||||
lex_html('<head><link></head>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'head', 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'link', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -40,9 +35,7 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element inside another element with whitespace' do
|
||||
lex_html("<head><link>\n</head>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'head', 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'link', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_TEXT, "\n", 1],
|
||||
|
@ -52,7 +45,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element with an unquoted attribute value' do
|
||||
lex_html('<br class=foo />').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -65,7 +57,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'without a space before the closing tag' do
|
||||
it 'lexes a void element' do
|
||||
lex_html('<br/>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -73,7 +64,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element with an attribute' do
|
||||
lex_html('<br class="foo"/>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_DQUOTE, nil, 1],
|
||||
|
@ -85,7 +75,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes a void element with an unquoted attribute value' do
|
||||
lex_html('<br class=foo/>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'br', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
|
|
@ -8,7 +8,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes inline Javascript' do
|
||||
lex("<script>#{@javascript}</script>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, @javascript, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
@ -17,7 +16,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes 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_COMMENT_START, nil, 1],
|
||||
|
@ -29,7 +27,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes inline Javascript containing a CDATA tag' do
|
||||
lex("<script>#{@javascript}<![CDATA[foo]]></script>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, @javascript, 1],
|
||||
[:T_CDATA_START, nil, 1],
|
||||
|
@ -41,7 +38,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes inline Javascript containing a processing instruction' do
|
||||
lex("<script>#{@javascript}<?foo?></script>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, @javascript, 1],
|
||||
[:T_PROC_INS_START, nil, 1],
|
||||
|
@ -53,10 +49,8 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'lexes inline Javascript containing another element' do
|
||||
lex("<script>#{@javascript}<p></p></script>").should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, @javascript, 1],
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
|
|
|
@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
|
|||
describe 'invalid elements' do
|
||||
it 'adds missing closing tags' do
|
||||
lex('<a>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
@ -16,7 +15,6 @@ describe Oga::XML::Lexer do
|
|||
|
||||
it 'ignores excessive closing tags' do
|
||||
lex('<a></a></b>').should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'a', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
|
|
|
@ -6,7 +6,6 @@ describe Oga::XML::Lexer do
|
|||
io = StringIO.new("<p class='foo'>\nHello</p>")
|
||||
|
||||
lex(io).should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'p', 1],
|
||||
[:T_ATTR, 'class', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -31,7 +30,6 @@ describe Oga::XML::Lexer do
|
|||
lexer = described_class.new(io)
|
||||
|
||||
lexer.lex.should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'foo', 1],
|
||||
[:T_ATTR, 'bar', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
@ -47,7 +45,6 @@ describe Oga::XML::Lexer do
|
|||
lexer = described_class.new(io)
|
||||
|
||||
lexer.lex.should == [
|
||||
[:T_ELEM_START, nil, 1],
|
||||
[:T_ELEM_NAME, 'foo', 1],
|
||||
[:T_ATTR, 'bar', 1],
|
||||
[:T_STRING_SQUOTE, nil, 1],
|
||||
|
|
Loading…
Reference in New Issue