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( '
header1header2header3header4
foo4bar4baz4qux4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
', gen.generate(), "tgroup tags present from generate()" ) assert_equal( '
header1header2header3header4
foo4bar4baz4qux4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
', gen.north(), "tgroup tags present from north()" ) assert_equal( '
header1foo1foo2foo3foo4
header2bar1bar2bar3bar4
header3baz1baz2baz3baz4
header4qux1qux2qux3qux4
', gen.landscape(), "tgroup tags never present from landscape()" ) assert_equal( '
header1foo1foo2foo3foo4
header2bar1bar2bar3bar4
header3baz1baz2baz3baz4
header4qux1qux2qux3qux4
', gen.west(), "tgroup tags never present from west()" ) assert_equal( '
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
header1header2header3header4
', gen.south(), "tgroup tags never present from south()" ) assert_equal( '
foo1foo2foo3foo4header1
bar1bar2bar3bar4header2
baz1baz2baz3baz4header3
qux1qux2qux3qux4header4
', 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( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', gen.generate( 'tgroups' => 1 ), "tfoot ommited when tgroups is 1" ) assert_equal( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', gen.generate( 'matrix' => 1, 'tgroups' => 1 ), "thead and tfoot ommited for matrix when tgroups is 1" ) assert_equal( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', 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( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', gen.generate( 'tgroups' => 0, 'tr' => { 'class' => %w{ odd even } } ), "styles applying to tr impact all rows when thead 0" ) assert_equal( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', gen.generate( 'tgroups' => 1, 'tr' => { 'class' => %w{ odd even } } ), "styles applying to tr do not impact thead when thead 1" ) assert_equal( '
header1header2header3header4
foo4bar4baz4qux4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
', gen.generate( 'tgroups' => 2, 'tr' => { 'class' => %w{ odd even } } ), "styles applying to tr do not impact thead and tfoot when thead 1" ) assert_equal( '
header1header2header3header4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
foo4bar4baz4qux4
', gen.generate( 'tgroups' => 1, 'tr' => { 'class' => %w{ odd even } }, 'thead.tr' => { 'class' => "thead" } ), "thead.tr impacts thead rows" ) assert_equal( '
header1header2header3header4
foo4bar4baz4qux4
foo1bar1baz1qux1
foo2bar2baz2qux2
foo3bar3baz3qux3
', gen.generate( 'tgroups' => 2, 'tr' => { 'class' => %w{ odd even } }, 'tfoot.tr' => { 'class' => "tfoot" } ), "tfoot.tr impacts thead rows" ) end end