t/12-encodes.rb in Spreadsheet-HTML-0.0.7 vs t/12-encodes.rb in Spreadsheet-HTML-0.0.8
- old
+ new
@@ -7,33 +7,40 @@
data = Array[
%w(header1 header2 header3),
Array[ '<foo1>', '&bar1', '"baz1' ],
Array[ '<foo2>', '&bar2', '"baz2' ],
+ Array[ '', '0', '' ],
]
gen = Spreadsheet::HTML.new( 'data' => data )
assert_equal(
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr></table>',
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td> </td><td>0</td><td> </td></tr></table>',
gen.generate(),
"nothing encoded by default"
)
assert_equal(
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr></table>',
- gen.generate( 'encodes' => nil ),
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td> </td><td>0</td><td> </td></tr></table>',
+ gen.generate( 'encode' => 1 ),
"default encoding works"
)
assert_equal(
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr></table>',
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td> </td><td>0</td><td> </td></tr></table>',
gen.generate( 'encodes' => '&' ),
"only requested char is encoded"
)
assert_equal(
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr></table>',
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td> </td><td>0</td><td> </td></tr></table>',
+ gen.generate( 'encodes' => '0' ),
+ "zero as requested char is encoded"
+ )
+
+ assert_equal(
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td> </td><td>0</td><td> </td></tr></table>',
gen.generate( 'encodes' => 'a&"' ),
"requested chars are encoded"
)
end