require "test/unit"
require "Spreadsheet/HTML"
class Test_Tgroups < Test::Unit::TestCase
def test_orientations
data = Array[
%w(header1 header2 header3 header4),
%w(foo1 bar1 baz1 qux1),
%w(foo2 bar2 baz2 qux2),
%w(foo3 bar3 baz3 qux3),
%w(foo4 bar4 baz4 qux4)
]
gen = Spreadsheet::HTML.new( 'data' => data, 'tgroups' => 2 )
assert_equal(
'
header1 | header2 | header3 | header4 |
---|
foo4 | bar4 | baz4 | qux4 |
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
',
gen.generate(),
"tgroup tags present from generate()"
)
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo4 | bar4 | baz4 | qux4 |
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
',
gen.north(),
"tgroup tags present from north()"
)
assert_equal(
'header1 | foo1 | foo2 | foo3 | foo4 |
---|
header2 | bar1 | bar2 | bar3 | bar4 |
---|
header3 | baz1 | baz2 | baz3 | baz4 |
---|
header4 | qux1 | qux2 | qux3 | qux4 |
---|
',
gen.landscape(),
"tgroup tags never present from landscape()"
)
assert_equal(
'header1 | foo1 | foo2 | foo3 | foo4 |
---|
header2 | bar1 | bar2 | bar3 | bar4 |
---|
header3 | baz1 | baz2 | baz3 | baz4 |
---|
header4 | qux1 | qux2 | qux3 | qux4 |
---|
',
gen.west(),
"tgroup tags never present from west()"
)
assert_equal(
'foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
header1 | header2 | header3 | header4 |
---|
',
gen.south(),
"tgroup tags never present from south()"
)
assert_equal(
'foo1 | foo2 | foo3 | foo4 | header1 |
---|
bar1 | bar2 | bar3 | bar4 | header2 |
---|
baz1 | baz2 | baz3 | baz4 | header3 |
---|
qux1 | qux2 | qux3 | qux4 | header4 |
---|
',
gen.east(),
"tgroup tags never present from east()"
)
end
def test_ommisions
data = Array[
%w(header1 header2 header3 header4),
%w(foo1 bar1 baz1 qux1),
%w(foo2 bar2 baz2 qux2),
%w(foo3 bar3 baz3 qux3),
%w(foo4 bar4 baz4 qux4)
]
gen = Spreadsheet::HTML.new( 'data' => data, 'tgroups' => 2 )
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'tgroups' => 1 ),
"tfoot ommited when tgroups is 1"
)
assert_equal(
'header1 | header2 | header3 | header4 |
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'matrix' => 1, 'tgroups' => 1 ),
"thead and tfoot ommited for matrix when tgroups is 1"
)
assert_equal(
'header1 | header2 | header3 | header4 |
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'matrix' => 1, 'tgroups' => 2 ),
"thead and tfoot ommited for matrix when tgroups is 2"
)
end
def test_attrs
data = Array[
%w(header1 header2 header3 header4),
%w(foo1 bar1 baz1 qux1),
%w(foo2 bar2 baz2 qux2),
%w(foo3 bar3 baz3 qux3),
%w(foo4 bar4 baz4 qux4)
]
gen = Spreadsheet::HTML.new( 'data' => data, 'tgroups' => 2 )
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'tgroups' => 0, 'tr' => { 'class' => %w{ odd even } } ),
"styles applying to tr impact all rows when thead 0"
)
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'tgroups' => 1, 'tr' => { 'class' => %w{ odd even } } ),
"styles applying to tr do not impact thead when thead 1"
)
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo4 | bar4 | baz4 | qux4 |
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
',
gen.generate( 'tgroups' => 2, 'tr' => { 'class' => %w{ odd even } } ),
"styles applying to tr do not impact thead and tfoot when thead 1"
)
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
foo4 | bar4 | baz4 | qux4 |
',
gen.generate( 'tgroups' => 1, 'tr' => { 'class' => %w{ odd even } }, 'thead.tr' => { 'class' => "thead" } ),
"thead.tr impacts thead rows"
)
assert_equal(
'header1 | header2 | header3 | header4 |
---|
foo1 | bar1 | baz1 | qux1 |
foo2 | bar2 | baz2 | qux2 |
foo3 | bar3 | baz3 | qux3 |
',
gen.generate( 'tgroups' => 2, 'tr' => { 'class' => %w{ odd even } }, 'tfoot.tr' => { 'class' => "tfoot" } ),
"tfoot.tr impacts thead rows"
)
end
end