1 require 'abstract_unit'
3 class NodeTest
< Test
::Unit::TestCase
6 def initialize(matched
, value
)
21 @node = HTML
::Node.new("parent")
22 @node.children
.concat
[MockNode
.new(false,1), MockNode
.new(true,"two"), MockNode
.new(false,:three)]
26 assert
!@node.match("foo")
34 assert_equal
"1twothree", @node.to_s
38 assert_equal
"two", @node.find('blah').to_s
42 s
= "<b foo='hello'' bar='baz'>"
43 assert_raise(RuntimeError
) { HTML
::Node.parse(nil,0,0,s
) }
46 def test_parse_relaxed
47 s
= "<b foo='hello'' bar='baz'>"
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")
54 def test_to_s_with_boolean_attrs
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
62 def test_parse_with_unclosed_tag
63 s
= "<span onmouseover='bang'"
65 assert_nothing_raised
{ node
= HTML
::Node.parse(nil,0,0,s
,false) }
66 assert node
.attributes
.has_key
?("onmouseover")
69 def test_parse_with_valid_cdata_section
70 s
= "<![CDATA[<span>contents</span>]]>"
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
77 def test_parse_strict_with_unterminated_cdata_section
78 s
= "<![CDATA[neverending..."
79 assert_raise(RuntimeError
) { HTML
::Node.parse(nil,0,0,s
) }
82 def test_parse_relaxed_with_unterminated_cdata_section
83 s
= "<![CDATA[neverending..."
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