require "test/unit" require "HTML/AutoTag" class TestTag < Test::Unit::TestCase def test_init auto = HTML::AutoTag.new assert_equal( '', auto.encodes, "no args encodes correct" ) assert_equal( '', auto.indent, "no args indent correct" ) assert_equal( 0, auto.level, "no args level correct" ) assert_equal( 0, auto.sorted, "no args sorted correct" ) assert_equal( '', auto.newline, "no args newline correct" ) auto = HTML::AutoTag.new( 'encodes' => nil, 'indent' => ' ' ) assert_equal( nil, auto.encodes, "encodes set correct" ) assert_equal( ' ', auto.indent, "indent set correct" ) assert_equal( "\n", auto.newline, "newline set correct" ) end def test_empty auto = HTML::AutoTag.new assert_equal( '
0
', auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( '0
\n", auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( "0
\n", auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( "<0>
', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "specific encodes work" ) auto = HTML::AutoTag.new( 'encodes' => nil ) assert_equal( '<"0'&>
', auto.tag( 'tag' => 'p', 'cdata' => '<"0\'&>' ), "default encodes work" ) auto = HTML::AutoTag.new( 'encodes' => 0 ) assert_equal( '<0>
', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "zero only encode work" ) auto = HTML::AutoTag.new assert_equal( '<0>
', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "no encoding works" ) end end