require "test/unit" require "Spreadsheet/HTML" class Test_Encodes < Test::Unit::TestCase def test_encodes data = Array[ %w(header1 header2 header3), Array[ '', '&bar1', '"baz1' ], Array[ '', '&bar2', '"baz2' ], Array[ '', '0', '' ], ] gen = Spreadsheet::HTML.new( 'data' => data ) assert_equal( '
header1header2header3
&bar1"baz1
&bar2"baz2
 0 
', gen.generate(), "nothing encoded by default" ) assert_equal( '
header1header2header3
<foo1>&bar1"baz1
<foo2>&bar2"baz2
 0 
', gen.generate( 'encode' => 1 ), "default encoding works" ) assert_equal( '
header1header2header3
&bar1"baz1
&bar2"baz2
 0 
', gen.generate( 'encodes' => '&' ), "only requested char is encoded" ) assert_equal( '
header1header2header3
&bar1"baz1
&bar2"baz2
 0 
', gen.generate( 'encodes' => '0' ), "zero as requested char is encoded" ) assert_equal( '
header1header2header3
&bar1"baz1
&bar2"baz2
 0 
', gen.generate( 'encodes' => 'a&"' ), "requested chars are encoded" ) end end