test/workbook/worksheet/tc_worksheet.rb in axlsx-1.0.16 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-1.0.17

- old
+ new

@@ -26,11 +26,17 @@ end def test_index assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws)) end - + + def test_dimension + @ws.add_row [1, 2, 3] + @ws.add_row [4, 5, 6] + assert_equal @ws.dimension, "A1:C2" + end + def test_referencing @ws.add_row [1, 2, 3] @ws.add_row [4, 5, 6] range = @ws["A1:C2"] assert_equal(range.size, 6) @@ -128,22 +134,33 @@ big = @ws.workbook.styles.add_style(:sz=>10) @ws.add_row ["chasing windmills", "penut"], :style=>small assert(@ws.auto_fit_data.size == 2, "a data item for each column") - assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") + assert_equal(@ws.auto_fit_data[0], {:sz => 2, :longest => "chasing windmills", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") @ws.add_row ["mule"], :style=>big - assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") + assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") end def test_auto_width assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size") assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fish"}) < @ws.send(:auto_width, {:sz=>12, :longest=>"fish"}), "larger fonts produce longer with with same string") + assert_equal(@ws.send(:auto_width, {:sz=>11, :longest => "This is a really long string", :fixed=>0.2}), 0.2, "fixed rules!") + end + def test_set_column_width + @ws.add_row ["chasing windmills", "penut"] + assert_equal(@ws.auto_fit_data[0][:fixed], nil, 'no fixed by default') + @ws.column_widths nil, 0.5 + assert_equal(@ws.auto_fit_data[1][:fixed], 0.5, 'eat my width') + assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths 2, 7, nil } + assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 } + assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" } end + def test_merge_cells assert(@ws.merged_cells.is_a?(Array)) assert_equal(@ws.merged_cells.size, 0) @ws.add_row [1,2,3]