1 require 'abstract_unit'
3 class TokenizerTest
< Test
::Unit::TestCase
16 def test_tag_simple_open
22 def test_tag_simple_self_closing
28 def test_tag_simple_closing
33 def test_tag_with_single_quoted_attribute
34 tokenize %
{<tag a
='hello'>x
}
35 assert_next %
{<tag a
='hello'>}
38 def test_tag_with_single_quoted_attribute_with_escape
39 tokenize %
{<tag a
='hello\\''>x}
40 assert_next %{<tag a='hello\\''>}
43 def test_tag_with_double_quoted_attribute
44 tokenize %{<tag a="hello">x}
45 assert_next %{<tag a="hello">}
48 def test_tag_with_double_quoted_attribute_with_escape
49 tokenize %{<tag a="hello\\"">x}
50 assert_next %{<tag a="hello\\"">}
53 def test_tag_with_unquoted_attribute
54 tokenize %{<tag a=hello>x}
55 assert_next %{<tag a=hello>}
58 def test_tag_with_lt_char_in_attribute
59 tokenize %{<tag a="x < y">x}
60 assert_next %{<tag a="x < y">}
63 def test_tag_with_gt_char_in_attribute
64 tokenize %{<tag a="x > y">x}
65 assert_next %{<tag a="x > y">}
69 tokenize %{<!DOCTYPE "blah" "blah" "blah">\n <html>}
70 assert_next %{<!DOCTYPE "blah" "blah" "blah">}
76 tokenize %{<![CDATA[<br>]]>}
77 assert_next %{<![CDATA[<br>]]>}
81 def test_unterminated_cdata_tag
82 tokenize %{<content:encoded><![CDATA[ neverending...}
83 assert_next %{<content:encoded>}
84 assert_next %{<![CDATA[ neverending...}
88 def test_less_than_with_space
89 tokenize %{original < hello > world}
90 assert_next %{original }
91 assert_next %{< hello > world}
94 def test_less_than_without_matching_greater_than
95 tokenize %{hello <span onmouseover="gotcha"\n<b>foo</b>\nbar</span>}
97 assert_next %{<span onmouseover="gotcha"\n}
102 assert_next %{</span>}
106 def test_unterminated_comment
107 tokenize %{hello <!-- neverending...}
108 assert_next %{hello }
109 assert_next %{<!-- neverending...}
116 @tokenizer = HTML::Tokenizer.new(text)
119 def assert_next(expected, message=nil)
120 token = @tokenizer.next
121 assert_equal expected, token, message
124 def assert_sequence(*expected)
125 assert_next expected.shift until expected.empty?
128 def assert_end(message=nil)
129 assert_nil @tokenizer.next, message