require "test/unit"
require "HTML/AutoTag"
class TestTagAttrs < Test::Unit::TestCase
def test_simple
auto = HTML::AutoTag.new()
assert_equal(
'
',
auto.tag( 'tag' => 'p', 'attr' => { 'class' => 'paragraph' } ),
'empty paragraph tag correct'
)
assert_equal(
'0
',
auto.tag( 'tag' => 'p', 'attr' => { 'class' => 'paragraph' }, 'cdata' => 0 ),
'paragraph tag correct'
)
assert_equal(
'0',
auto.tag( 'tag' => 'colgroup', 'attr' => { 'span' => 3 }, 'cdata' => 0 ),
'paragraph tag correct'
)
end
def test_one_nested
auto = HTML::AutoTag.new()
data = %w{ one two three }
attr = { 'style' => { 'color' => %w{ red green } } }
html = auto.tag(
'tag' => 'ol',
'attr' => { 'reversed' => 'reversed' },
'cdata' => data.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
)
assert_equal(
'- one
- two
- three
',
html,
'one nested level tags correct'
)
end
def test_two_nested
auto = HTML::AutoTag.new()
data = %w{ one two three }
tr_attr = { 'class' => %w{ odd even } }
td_attr1 = { 'style' => { 'color' => %w{ red green } } }
td_attr2 = { 'style' => { 'color' => %w{ green blue } } }
html = auto.tag(
'tag' => 'table',
'attr' => { 'class' => 'spreadsheet' },
'cdata' => Array[
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => data.map{ |d| { 'tag' => 'th', 'attr' => td_attr1, 'cdata' => d } }
},
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => data.map{ |d| { 'tag' => 'td', 'attr' => td_attr2, 'cdata' => d } }
},
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => data.map{ |d| { 'tag' => 'td', 'attr' => td_attr1, 'cdata' => d } }
},
]
)
assert_equal(
'one | two | three |
---|
one | two | three |
one | two | three |
',
html,
'two nested level tags correct'
)
tr_attr = { 'class' => %w{ odd even } }
html = auto.tag(
'tag' => 'table',
'attr' => { 'class' => 'spreadsheet' },
'cdata' => Array[
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => {
'tag' => 'th',
'attr' => { 'style' => { 'color' => %w{ red green } } },
'cdata' => data,
},
},
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => {
'tag' => 'td',
'attr' => { 'style' => { 'color' => %w{ green blue } } },
'cdata' => data,
},
},
{
'tag' => 'tr',
'attr' => tr_attr,
'cdata' => {
'tag' => 'td',
'attr' => { 'style' => { 'color' => %w{ red green } } },
'cdata' => data,
},
},
]
)
assert_equal(
'one | two | three |
---|
one | two | three |
one | two | three |
',
html,
'two nested level tags correct - inlined attrs'
)
end
end