Froze rails gems
[depot.git] / vendor / rails / actionpack / test / controller / html-scanner / node_test.rb
1 require 'abstract_unit'
2
3 class NodeTest < Test::Unit::TestCase
4
5 class MockNode
6 def initialize(matched, value)
7 @matched = matched
8 @value = value
9 end
10
11 def find(conditions)
12 @matched && self
13 end
14
15 def to_s
16 @value.to_s
17 end
18 end
19
20 def setup
21 @node = HTML::Node.new("parent")
22 @node.children.concat [MockNode.new(false,1), MockNode.new(true,"two"), MockNode.new(false,:three)]
23 end
24
25 def test_match
26 assert !@node.match("foo")
27 end
28
29 def test_tag
30 assert !@node.tag?
31 end
32
33 def test_to_s
34 assert_equal "1twothree", @node.to_s
35 end
36
37 def test_find
38 assert_equal "two", @node.find('blah').to_s
39 end
40
41 def test_parse_strict
42 s = "<b foo='hello'' bar='baz'>"
43 assert_raise(RuntimeError) { HTML::Node.parse(nil,0,0,s) }
44 end
45
46 def test_parse_relaxed
47 s = "<b foo='hello'' bar='baz'>"
48 node = nil
49 assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
50 assert node.attributes.has_key?("foo")
51 assert !node.attributes.has_key?("bar")
52 end
53
54 def test_to_s_with_boolean_attrs
55 s = "<b foo bar>"
56 node = HTML::Node.parse(nil,0,0,s)
57 assert node.attributes.has_key?("foo")
58 assert node.attributes.has_key?("bar")
59 assert "<b foo bar>", node.to_s
60 end
61
62 def test_parse_with_unclosed_tag
63 s = "<span onmouseover='bang'"
64 node = nil
65 assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
66 assert node.attributes.has_key?("onmouseover")
67 end
68
69 def test_parse_with_valid_cdata_section
70 s = "<![CDATA[<span>contents</span>]]>"
71 node = nil
72 assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
73 assert_kind_of HTML::CDATA, node
74 assert_equal '<span>contents</span>', node.content
75 end
76
77 def test_parse_strict_with_unterminated_cdata_section
78 s = "<![CDATA[neverending..."
79 assert_raise(RuntimeError) { HTML::Node.parse(nil,0,0,s) }
80 end
81
82 def test_parse_relaxed_with_unterminated_cdata_section
83 s = "<![CDATA[neverending..."
84 node = nil
85 assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
86 assert_kind_of HTML::CDATA, node
87 assert_equal 'neverending...', node.content
88 end
89 end