require "test/unit" require "HTML/AutoTag" class TestTag < Test::Unit::TestCase def test_init auto = HTML::AutoTag.new assert_equal( 0, 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' => 1, 'indent' => ' ' ) assert_equal( 1, 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( '
', auto.tag( 'tag' => 'hr' ), "empty tag correct" ) end def test_nonempty auto = HTML::AutoTag.new assert_equal( '

0

', auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( '
  1. 1
', auto.tag( 'tag' => 'ol', 'cdata' => { 'tag' => 'li', 'cdata' => 1 } ), "ol tag correct" ) assert_equal( '
  1. 1
  2. 2
', auto.tag( 'tag' => 'ol', 'cdata' => [{ 'tag' => 'li', 'cdata' => 1 }, { 'tag' => 'li', 'cdata' => 2 }] ), "ol tag correct" ) end def test_indent auto = HTML::AutoTag.new( 'indent' => ' ' ) assert_equal( "

0

\n", auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( "
    \n
  1. 1
  2. \n
\n", auto.tag( 'tag' => 'ol', 'cdata' => { 'tag' => 'li', 'cdata' => 1 } ), "ol tag correct" ) assert_equal( "
    \n
  1. 1
  2. \n
  3. 2
  4. \n
\n", auto.tag( 'tag' => 'ol', 'cdata' => [{ 'tag' => 'li', 'cdata' => 1 }, { 'tag' => 'li', 'cdata' => 2 }] ), "ol tag correct" ) end def test_level auto = HTML::AutoTag.new( 'indent' => ' ', 'level' => 3 ) assert_equal( "

0

\n", auto.tag( 'tag' => 'p', 'cdata' => 0 ), "paragraph tag correct" ) assert_equal( "
    \n
  1. 1
  2. \n
\n", auto.tag( 'tag' => 'ol', 'cdata' => { 'tag' => 'li', 'cdata' => 1 } ), "ol tag correct" ) assert_equal( "
    \n
  1. 1
  2. \n
  3. 2
  4. \n
\n", auto.tag( 'tag' => 'ol', 'cdata' => [{ 'tag' => 'li', 'cdata' => 1 }, { 'tag' => 'li', 'cdata' => 2 }] ), "ol tag correct" ) end def test_encodes auto = HTML::AutoTag.new( 'encodes' => 1 ) assert_equal( '

<0>

', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "paragraph tag correct" ) end end