Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / html-scanner / tokenizer_test.rb
1 require 'abstract_unit'
2
3 class TokenizerTest < Test::Unit::TestCase
4
5 def test_blank
6 tokenize ""
7 assert_end
8 end
9
10 def test_space
11 tokenize " "
12 assert_next " "
13 assert_end
14 end
15
16 def test_tag_simple_open
17 tokenize "<tag>"
18 assert_next "<tag>"
19 assert_end
20 end
21
22 def test_tag_simple_self_closing
23 tokenize "<tag />"
24 assert_next "<tag />"
25 assert_end
26 end
27
28 def test_tag_simple_closing
29 tokenize "</tag>"
30 assert_next "</tag>"
31 end
32
33 def test_tag_with_single_quoted_attribute
34 tokenize %{<tag a='hello'>x}
35 assert_next %{<tag a='hello'>}
36 end
37
38 def test_tag_with_single_quoted_attribute_with_escape
39 tokenize %{<tag a='hello\\''>x}
40 assert_next %{<tag a='hello\\''>}
41 end
42
43 def test_tag_with_double_quoted_attribute
44 tokenize %{<tag a="hello">x}
45 assert_next %{<tag a="hello">}
46 end
47
48 def test_tag_with_double_quoted_attribute_with_escape
49 tokenize %{<tag a="hello\\"">x}
50 assert_next %{<tag a="hello\\"">}
51 end
52
53 def test_tag_with_unquoted_attribute
54 tokenize %{<tag a=hello>x}
55 assert_next %{<tag a=hello>}
56 end
57
58 def test_tag_with_lt_char_in_attribute
59 tokenize %{<tag a="x < y">x}
60 assert_next %{<tag a="x < y">}
61 end
62
63 def test_tag_with_gt_char_in_attribute
64 tokenize %{<tag a="x > y">x}
65 assert_next %{<tag a="x > y">}
66 end
67
68 def test_doctype_tag
69 tokenize %{<!DOCTYPE "blah" "blah" "blah">\n <html>}
70 assert_next %{<!DOCTYPE "blah" "blah" "blah">}
71 assert_next %{\n }
72 assert_next %{<html>}
73 end
74
75 def test_cdata_tag
76 tokenize %{<![CDATA[<br>]]>}
77 assert_next %{<![CDATA[<br>]]>}
78 assert_end
79 end
80
81 def test_unterminated_cdata_tag
82 tokenize %{<content:encoded><![CDATA[ neverending...}
83 assert_next %{<content:encoded>}
84 assert_next %{<![CDATA[ neverending...}
85 assert_end
86 end
87
88 def test_less_than_with_space
89 tokenize %{original < hello > world}
90 assert_next %{original }
91 assert_next %{< hello > world}
92 end
93
94 def test_less_than_without_matching_greater_than
95 tokenize %{hello <span onmouseover="gotcha"\n<b>foo</b>\nbar</span>}
96 assert_next %{hello }
97 assert_next %{<span onmouseover="gotcha"\n}
98 assert_next %{<b>}
99 assert_next %{foo}
100 assert_next %{</b>}
101 assert_next %{\nbar}
102 assert_next %{</span>}
103 assert_end
104 end
105
106 def test_unterminated_comment
107 tokenize %{hello <!-- neverending...}
108 assert_next %{hello }
109 assert_next %{<!-- neverending...}
110 assert_end
111 end
112
113 private
114
115 def tokenize(text)
116 @tokenizer = HTML::Tokenizer.new(text)
117 end
118
119 def assert_next(expected, message=nil)
120 token = @tokenizer.next
121 assert_equal expected, token, message
122 end
123
124 def assert_sequence(*expected)
125 assert_next expected.shift until expected.empty?
126 end
127
128 def assert_end(message=nil)
129 assert_nil @tokenizer.next, message
130 end
131 end