diff options
Diffstat (limited to 'test/workbook/worksheet/tc_row.rb')
| -rw-r--r-- | test/workbook/worksheet/tc_row.rb | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index cf8fa7c3..cd805315 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -1,4 +1,4 @@ -require 'tc_helper.rb' +require 'tc_helper' class TestRow < Test::Unit::TestCase def setup @@ -8,14 +8,15 @@ class TestRow < Test::Unit::TestCase end def test_initialize - assert(@row.cells.empty?, "no cells by default") + assert_empty(@row.cells, "no cells by default") assert_equal(@row.worksheet, @ws, "has a reference to the worksheet") assert_nil(@row.height, "height defaults to nil") - assert([email protected]_height, "no custom height by default") + refute(@row.custom_height, "no custom height by default") end def test_initialize_with_fixed_height row = @ws.add_row([1, 2, 3, 4, 5], :height => 40) + assert_equal(40, row.height) assert(row.custom_height) end @@ -23,13 +24,15 @@ class TestRow < Test::Unit::TestCase def test_style r = @ws.add_row([1, 2, 3, 4, 5]) r.style = 1 - r.cells.each { |c| assert_equal(c.style, 1) } + + r.cells.each { |c| assert_equal(1, c.style) } end def test_color r = @ws.add_row([1, 2, 3, 4, 5]) r.color = "FF00FF00" - r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") } + + r.cells.each { |c| assert_equal("FF00FF00", c.color.rgb) } end def test_index @@ -38,45 +41,50 @@ class TestRow < Test::Unit::TestCase def test_add_cell c = @row.add_cell(1) + assert_equal(@row.cells.last, c) end def test_add_cell_autowidth_info cell = @row.add_cell("this is the cell of cells") width = cell.send(:autowidth) + assert_equal(@ws.column_info.last.width, width) end def test_array_to_cells r = @ws.add_row [1, 2, 3], :style => 1, :types => [:integer, :string, :float] - assert_equal(r.cells.size, 3) + + assert_equal(3, r.cells.size) r.cells.each do |c| - assert_equal(c.style, 1) + assert_equal(1, c.style) end r = @ws.add_row [1, 2, 3], :style => [1] - assert_equal(r.cells.first.style, 1, "only apply style to cells with at the same index of of the style array") - assert_equal(r.cells.last.style, 0, "only apply style to cells with at the same index of of the style array") + + assert_equal(1, r.cells.first.style, "only apply style to cells with at the same index of of the style array") + assert_equal(0, r.cells.last.style, "only apply style to cells with at the same index of of the style array") end def test_array_to_cells_with_escape_formulas row = ['=HYPERLINK("http://www.example.com", "CSV Payload")', '=Bar'] @ws.add_row row, escape_formulas: true - assert_equal @ws.rows.last.cells[0].escape_formulas, true - assert_equal @ws.rows.last.cells[1].escape_formulas, true + assert(@ws.rows.last.cells[0].escape_formulas) + assert(@ws.rows.last.cells[1].escape_formulas) end def test_array_to_cells_with_escape_formulas_as_an_array row = ['=HYPERLINK("http://www.example.com", "CSV Payload")', '+Foo', '-Bar'] @ws.add_row row, escape_formulas: [true, false, true] - assert_equal @ws.rows.last.cells.first.escape_formulas, true - assert_equal @ws.rows.last.cells[1].escape_formulas, false - assert_equal @ws.rows.last.cells[2].escape_formulas, true + assert(@ws.rows.last.cells.first.escape_formulas) + refute(@ws.rows.last.cells[1].escape_formulas) + assert(@ws.rows.last.cells[2].escape_formulas) end def test_custom_height @row.height = 20 + assert(@row.custom_height) end @@ -89,19 +97,19 @@ class TestRow < Test::Unit::TestCase def test_ph assert_raise(ArgumentError) { @row.ph = -3 } assert_nothing_raised { @row.ph = true } - assert_equal(true, @row.ph) + assert(@row.ph) end def test_hidden assert_raise(ArgumentError) { @row.hidden = -3 } assert_nothing_raised { @row.hidden = true } - assert_equal(true, @row.hidden) + assert(@row.hidden) end def test_collapsed assert_raise(ArgumentError) { @row.collapsed = -3 } assert_nothing_raised { @row.collapsed = true } - assert_equal(true, @row.collapsed) + assert(@row.collapsed) end def test_outlineLevel @@ -112,6 +120,7 @@ class TestRow < Test::Unit::TestCase def test_to_xml_without_custom_height doc = Nokogiri::XML.parse(@row.to_xml_string(0)) + assert_equal(0, doc.xpath(".//row[@ht]").size) assert_equal(0, doc.xpath(".//row[@customHeight]").size) end @@ -123,14 +132,16 @@ class TestRow < Test::Unit::TestCase @row.collapsed = true @row.hidden = true r_s_xml = Nokogiri::XML(@row.to_xml_string(0, '')) - assert_equal(r_s_xml.xpath(".//row[@r=1]").size, 1) + + assert_equal(1, r_s_xml.xpath(".//row[@r=1]").size) end def test_to_xml_string_with_custom_height @row.add_cell 1 @row.height = 20 r_s_xml = Nokogiri::XML(@row.to_xml_string(0, '')) - assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size, 1) + + assert_equal(1, r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size) end def test_offsets @@ -157,11 +168,13 @@ class TestRow < Test::Unit::TestCase def test_escape_formulas @ws.escape_formulas = false @row = @ws.add_row + assert_false @row.add_cell('').escape_formulas assert_false @row.add_cell('', escape_formulas: false).escape_formulas assert @row.add_cell('', escape_formulas: true).escape_formulas @row = Axlsx::Row.new(@ws) + assert_false @row.add_cell('').escape_formulas @ws.escape_formulas = true @@ -172,12 +185,15 @@ class TestRow < Test::Unit::TestCase assert @row.add_cell('', escape_formulas: true).escape_formulas @row.escape_formulas = false + assert_equal [false, false, false], @row.cells.map(&:escape_formulas) @row.escape_formulas = true + assert_equal [true, true, true], @row.cells.map(&:escape_formulas) @row.escape_formulas = [false, true, false] + assert_equal [false, true, false], @row.cells.map(&:escape_formulas) end end |
