diff options
| author | Geremia Taglialatela <[email protected]> | 2023-04-13 13:13:34 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-03 16:05:17 +0200 |
| commit | 350f7ae9a04f3d39c099cc54f7c04bf31f385d96 (patch) | |
| tree | e84af2a70d3b18a0b94c784338faf48215c9c8a8 /test/workbook/worksheet | |
| parent | e81036b76e734ab03fac31faafb9732f6b3b2928 (diff) | |
| download | caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.tar.gz caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.zip | |
Add RuboCop Minitest
Diffstat (limited to 'test/workbook/worksheet')
39 files changed, 754 insertions, 498 deletions
diff --git a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb index eb561554..e14591da 100644 --- a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +++ b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb @@ -15,6 +15,7 @@ class TestAutoFilter < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@auto_filter.to_xml_string) + assert(doc.xpath("autoFilter[@ref='#{@auto_filter.range}']")) end @@ -30,8 +31,9 @@ class TestAutoFilter < Test::Unit::TestCase end def test_applya - assert_equal nil, @auto_filter.worksheet.rows.last.hidden + assert_nil @auto_filter.worksheet.rows.last.hidden @auto_filter.apply - assert_equal true, @auto_filter.worksheet.rows.last.hidden + + assert @auto_filter.worksheet.rows.last.hidden end end diff --git a/test/workbook/worksheet/auto_filter/tc_filter_column.rb b/test/workbook/worksheet/auto_filter/tc_filter_column.rb index 88f73e0d..bf92bd44 100644 --- a/test/workbook/worksheet/auto_filter/tc_filter_column.rb +++ b/test/workbook/worksheet/auto_filter/tc_filter_column.rb @@ -27,17 +27,18 @@ class TestFilterColumn < Test::Unit::TestCase filter_column = Axlsx::FilterColumn.new(0, :filters) do |filters| filters.filter_items = [700, 100, 5] end + assert_equal 3, filter_column.filter.filter_items.size assert_equal 700, filter_column.filter.filter_items.first.val assert_equal 5, filter_column.filter.filter_items.last.val end def test_default_show_button - assert_equal true, @filter_column.show_button + assert @filter_column.show_button end def test_default_hidden_button - assert_equal false, @filter_column.hidden_button + refute @filter_column.hidden_button end def test_show_button @@ -63,6 +64,7 @@ class TestFilterColumn < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@filter_column.to_xml_string) + assert doc.xpath("//filterColumn[@colId=#{@filter_column.col_id}]") assert doc.xpath("//filterColumn[@hiddenButton=#{@filter_column.hidden_button}]") assert doc.xpath("//filterColumn[@showButton=#{@filter_column.show_button}]") diff --git a/test/workbook/worksheet/auto_filter/tc_filters.rb b/test/workbook/worksheet/auto_filter/tc_filters.rb index 8e853772..2002d510 100644 --- a/test/workbook/worksheet/auto_filter/tc_filters.rb +++ b/test/workbook/worksheet/auto_filter/tc_filters.rb @@ -8,15 +8,17 @@ class TestFilters < Test::Unit::TestCase end def test_blank - assert_equal true, @filters.blank + assert @filters.blank assert_raise(ArgumentError) { @filters.blank = :only_if_you_want_it } @filters.blank = true - assert_equal true, @filters.blank + + assert @filters.blank end def test_calendar_type assert_raise(ArgumentError) { @filters.calendar_type = 'monkey calendar' } @filters.calendar_type = 'japan' + assert_equal('japan', @filters.calendar_type) end @@ -33,17 +35,20 @@ class TestFilters < Test::Unit::TestCase def test_apply_is_false_for_matching_values keeper = Object.new def keeper.value; 'a'; end - assert_equal false, @filters.apply(keeper) + + refute @filters.apply(keeper) end def test_apply_is_true_for_non_matching_values hidden = Object.new def hidden.value; 'b'; end - assert_equal true, @filters.apply(hidden) + + assert @filters.apply(hidden) end def test_to_xml_string doc = Nokogiri::XML(@filters.to_xml_string) + assert_equal(1, doc.xpath('//filters[@blank=1]').size) end end diff --git a/test/workbook/worksheet/tc_border_creator.rb b/test/workbook/worksheet/tc_border_creator.rb index c9f3df8f..f1418bb4 100644 --- a/test/workbook/worksheet/tc_border_creator.rb +++ b/test/workbook/worksheet/tc_border_creator.rb @@ -11,27 +11,32 @@ class TestBorderCreator < Test::Unit::TestCase @ws.add_row [1, 2, 3] bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"]) + assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES - assert_equal bc.instance_variable_get(:@style), :thin - assert_equal bc.instance_variable_get(:@color), "000000" + assert_equal(:thin, bc.instance_variable_get(:@style)) + assert_equal("000000", bc.instance_variable_get(:@color)) bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:top], style: :thick, color: "ffffff") - assert_equal bc.instance_variable_get(:@edges), [:top] - assert_equal bc.instance_variable_get(:@style), :thick - assert_equal bc.instance_variable_get(:@color), "ffffff" + + assert_equal([:top], bc.instance_variable_get(:@edges)) + assert_equal(:thick, bc.instance_variable_get(:@style)) + assert_equal("ffffff", bc.instance_variable_get(:@color)) end def test_initialize_edges @ws.add_row [1, 2, 3] bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: nil) + assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: :all) + assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: []) - assert_equal bc.instance_variable_get(:@edges), [] + + assert_empty(bc.instance_variable_get(:@edges)) assert_raises(ArgumentError) do bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:foo]) diff --git a/test/workbook/worksheet/tc_break.rb b/test/workbook/worksheet/tc_break.rb index 2c67fed7..de71f591 100644 --- a/test/workbook/worksheet/tc_break.rb +++ b/test/workbook/worksheet/tc_break.rb @@ -27,14 +27,14 @@ class TestBreak < Test::Unit::TestCase end def test_man - assert_equal(true, @break.man) + assert(@break.man) assert_raises ArgumentError do Axlsx::Break.new(:man => -1) end end def test_pt - assert_equal(false, @break.pt) + refute(@break.pt) assert_raises ArgumentError do Axlsx::Break.new(:pt => -1) end @@ -42,6 +42,7 @@ class TestBreak < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@break.to_xml_string) - assert_equal(doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size, 1) + + assert_equal(1, doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size) end end diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 959304c8..9e1ebb0a 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -15,14 +15,15 @@ class TestCell < Test::Unit::TestCase def test_initialize assert_equal(@row.cells.last, @c, "the cell was added to the row") - assert_equal(@c.type, :float, "type option is applied") - assert_equal(@c.style, 1, "style option is applied") - assert_equal(@c.value, 1.0, "type option is applied and value is casted") - assert_equal(@c.escape_formulas, true, "escape formulas option is applied") + assert_equal(:float, @c.type, "type option is applied") + assert_equal(1, @c.style, "style option is applied") + assert_in_delta(@c.value, 1.0, 0.001, "type option is applied and value is casted") + assert(@c.escape_formulas, "escape formulas option is applied") end def test_style_date_data c = Axlsx::Cell.new(@c.row, Time.now) + assert_equal(Axlsx::STYLE_DATE, c.style) end @@ -39,20 +40,21 @@ class TestCell < Test::Unit::TestCase end def test_r - assert_equal(@c.r, "A1", "calculate cell reference") + assert_equal("A1", @c.r, "calculate cell reference") end def test_wide_r - assert_equal(@cAA.r, "AA2", "calculate cell reference") + assert_equal("AA2", @cAA.r, "calculate cell reference") end def test_r_abs - assert_equal(@c.r_abs, "$A$1", "calculate absolute cell reference") - assert_equal(@cAA.r_abs, "$AA$2", "needs to accept multi-digit columns") + assert_equal("$A$1", @c.r_abs, "calculate absolute cell reference") + assert_equal("$AA$2", @cAA.r_abs, "needs to accept multi-digit columns") end def test_name @c.name = 'foo' + assert_equal(1, @ws.workbook.defined_names.size) assert_equal('foo', @ws.workbook.defined_names.last.name) end @@ -60,6 +62,7 @@ class TestCell < Test::Unit::TestCase def test_autowidth style = @c.row.worksheet.workbook.styles.add_style({ :alignment => { :horizontal => :center, :vertical => :center, :wrap_text => true } }) @c.style = style + assert_in_delta(6.6, @c.autowidth, 0.01) end @@ -67,11 +70,13 @@ class TestCell < Test::Unit::TestCase style = @c.row.worksheet.workbook.styles.add_style(b: true) @c.row.worksheet.workbook.bold_font_multiplier = 1.05 @c.style = style + assert_in_delta(6.93, @c.autowidth, 0.01) end def test_autowidth_with_font_scale_divisor @c.row.worksheet.workbook.font_scale_divisor = 11.0 + assert_in_delta(6.0, @c.autowidth, 0.01) end @@ -79,6 +84,7 @@ class TestCell < Test::Unit::TestCase @c.type = :time now = DateTime.now @c.value = now + assert_equal(@c.value, now.to_time) end @@ -86,55 +92,56 @@ class TestCell < Test::Unit::TestCase @c.type = :date now = Time.now @c.value = now + assert_equal(@c.value, now.to_date) end def test_style assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style = @c.row.worksheet.workbook.styles.cellXfs.size } assert_nothing_raised("must allow valid style index changes") { @c.style = 1 } - assert_equal(@c.style, 1) + assert_equal(1, @c.style) end def test_type assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array } assert_nothing_raised("type can be changed") { @c.type = :string } - assert_equal(@c.value, "1.0", "changing type casts the value") + assert_equal("1.0", @c.value, "changing type casts the value") assert_equal(:float, @row.add_cell(1.0 / (10**7)).type, 'properly identify exponential floats as float type') - assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time') - assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date') - assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean') + assert_equal(:time, @row.add_cell(Time.now).type, 'time should be time') + assert_equal(:date, @row.add_cell(Date.today).type, 'date should be date') + assert_equal(:boolean, @row.add_cell(true).type, 'boolean should be boolean') end def test_value assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array } assert_nothing_raised("type can be changed") { @c.type = :string } - assert_equal(@c.value, "1.0", "changing type casts the value") + assert_equal("1.0", @c.value, "changing type casts the value") end def test_col_ref # TODO: move to axlsx spec - assert_equal(Axlsx.col_ref(0), "A") + assert_equal("A", Axlsx.col_ref(0)) end def test_cell_type_from_value - assert_equal(@c.send(:cell_type_from_value, 1.0), :float) - assert_equal(@c.send(:cell_type_from_value, "1e1"), :float) - assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"), :float) - assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"), :string) - assert_equal(@c.send(:cell_type_from_value, "1e-1"), :float) - assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"), :float) - assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"), :string) - assert_equal(@c.send(:cell_type_from_value, 1), :integer) - assert_equal(@c.send(:cell_type_from_value, Date.today), :date) - assert_equal(@c.send(:cell_type_from_value, Time.now), :time) - assert_equal(@c.send(:cell_type_from_value, []), :string) - assert_equal(@c.send(:cell_type_from_value, "d"), :string) - assert_equal(@c.send(:cell_type_from_value, nil), :string) - assert_equal(@c.send(:cell_type_from_value, -1), :integer) - assert_equal(@c.send(:cell_type_from_value, true), :boolean) - assert_equal(@c.send(:cell_type_from_value, false), :boolean) - assert_equal(@c.send(:cell_type_from_value, 1.0 / (10**6)), :float) - assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext) + assert_equal(:float, @c.send(:cell_type_from_value, 1.0)) + assert_equal(:float, @c.send(:cell_type_from_value, "1e1")) + assert_equal(:float, @c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}")) + assert_equal(:string, @c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}")) + assert_equal(:float, @c.send(:cell_type_from_value, "1e-1")) + assert_equal(:float, @c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}")) + assert_equal(:string, @c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}")) + assert_equal(:integer, @c.send(:cell_type_from_value, 1)) + assert_equal(:date, @c.send(:cell_type_from_value, Date.today)) + assert_equal(:time, @c.send(:cell_type_from_value, Time.now)) + assert_equal(:string, @c.send(:cell_type_from_value, [])) + assert_equal(:string, @c.send(:cell_type_from_value, "d")) + assert_equal(:string, @c.send(:cell_type_from_value, nil)) + assert_equal(:integer, @c.send(:cell_type_from_value, -1)) + assert_equal(:boolean, @c.send(:cell_type_from_value, true)) + assert_equal(:boolean, @c.send(:cell_type_from_value, false)) + assert_equal(:float, @c.send(:cell_type_from_value, 1.0 / (10**6))) + assert_equal(:richtext, @c.send(:cell_type_from_value, Axlsx::RichText.new)) assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00')) end @@ -159,27 +166,35 @@ class TestCell < Test::Unit::TestCase ] number_strings.each do |number_string| - assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string) + assert_equal(:string, @c.send(:cell_type_from_value, mimic_number.new(number_string))) end end def test_cast_value @c.type = :string - assert_equal(@c.send(:cast_value, 1.0), "1.0") + + assert_equal("1.0", @c.send(:cast_value, 1.0)) @c.type = :integer - assert_equal(@c.send(:cast_value, 1.0), 1) + + assert_equal(1, @c.send(:cast_value, 1.0)) @c.type = :float - assert_equal(@c.send(:cast_value, "1.0"), 1.0) + + assert_in_delta(@c.send(:cast_value, "1.0"), 1.0) @c.type = :string - assert_equal(@c.send(:cast_value, nil), nil) + + assert_nil(@c.send(:cast_value, nil)) @c.type = :richtext - assert_equal(@c.send(:cast_value, nil), nil) + + assert_nil(@c.send(:cast_value, nil)) @c.type = :float - assert_equal(@c.send(:cast_value, nil), nil) + + assert_nil(@c.send(:cast_value, nil)) @c.type = :boolean - assert_equal(@c.send(:cast_value, true), 1) - assert_equal(@c.send(:cast_value, false), 0) + + assert_equal(1, @c.send(:cast_value, true)) + assert_equal(0, @c.send(:cast_value, false)) @c.type = :iso_8601 + assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24")) end @@ -193,173 +208,190 @@ class TestCell < Test::Unit::TestCase time = subtime.now @c.type = :time + assert_equal(time, @c.send(:cast_value, time)) end def test_color assert_raise(ArgumentError) { @c.color = -1.1 } assert_nothing_raised { @c.color = "FF00FF00" } - assert_equal(@c.color.rgb, "FF00FF00") + assert_equal("FF00FF00", @c.color.rgb) end def test_scheme assert_raise(ArgumentError) { @c.scheme = -1.1 } assert_nothing_raised { @c.scheme = :major } - assert_equal(@c.scheme, :major) + assert_equal(:major, @c.scheme) end def test_vertAlign assert_raise(ArgumentError) { @c.vertAlign = -1.1 } assert_nothing_raised { @c.vertAlign = :baseline } - assert_equal(@c.vertAlign, :baseline) + assert_equal(:baseline, @c.vertAlign) end def test_sz assert_raise(ArgumentError) { @c.sz = -1.1 } assert_nothing_raised { @c.sz = 12 } - assert_equal(@c.sz, 12) + assert_equal(12, @c.sz) end def test_extend assert_raise(ArgumentError) { @c.extend = -1.1 } assert_nothing_raised { @c.extend = false } - assert_equal(@c.extend, false) + refute(@c.extend) end def test_condense assert_raise(ArgumentError) { @c.condense = -1.1 } assert_nothing_raised { @c.condense = false } - assert_equal(@c.condense, false) + refute(@c.condense) end def test_shadow assert_raise(ArgumentError) { @c.shadow = -1.1 } assert_nothing_raised { @c.shadow = false } - assert_equal(@c.shadow, false) + refute(@c.shadow) end def test_outline assert_raise(ArgumentError) { @c.outline = -1.1 } assert_nothing_raised { @c.outline = false } - assert_equal(@c.outline, false) + refute(@c.outline) end def test_strike assert_raise(ArgumentError) { @c.strike = -1.1 } assert_nothing_raised { @c.strike = false } - assert_equal(@c.strike, false) + refute(@c.strike) end def test_u @c.type = :string assert_raise(ArgumentError) { @c.u = -1.1 } assert_nothing_raised { @c.u = :single } - assert_equal(@c.u, :single) + assert_equal(:single, @c.u) doc = Nokogiri::XML(@c.to_xml_string(1, 1)) + assert(doc.xpath('//u[@val="single"]')) end def test_i assert_raise(ArgumentError) { @c.i = -1.1 } assert_nothing_raised { @c.i = false } - assert_equal(@c.i, false) + refute(@c.i) end def test_rFont assert_raise(ArgumentError) { @c.font_name = -1.1 } assert_nothing_raised { @c.font_name = "Arial" } - assert_equal(@c.font_name, "Arial") + assert_equal("Arial", @c.font_name) end def test_charset assert_raise(ArgumentError) { @c.charset = -1.1 } assert_nothing_raised { @c.charset = 1 } - assert_equal(@c.charset, 1) + assert_equal(1, @c.charset) end def test_family assert_raise(ArgumentError) { @c.family = -1.1 } assert_nothing_raised { @c.family = 5 } - assert_equal(@c.family, 5) + assert_equal(5, @c.family) end def test_b assert_raise(ArgumentError) { @c.b = -1.1 } assert_nothing_raised { @c.b = false } - assert_equal(@c.b, false) + refute(@c.b) end def test_merge_with_string @c.row.add_cell 2 @c.row.add_cell 3 @c.merge "A2" - assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:A2") + + assert_equal("A1:A2", @c.row.worksheet.send(:merged_cells).last) end def test_merge_with_cell @c.row.add_cell 2 @c.row.add_cell 3 @c.merge @row.cells.last - assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1") + + assert_equal("A1:C1", @c.row.worksheet.send(:merged_cells).last) end def test_reverse_merge_with_cell @c.row.add_cell 2 @c.row.add_cell 3 @row.cells.last.merge @c - assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1") + + assert_equal("A1:C1", @c.row.worksheet.send(:merged_cells).last) end def test_ssti assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) } @c.send :ssti=, 1 - assert_equal(@c.ssti, 1) + + assert_equal(1, @c.ssti) end def test_plain_string @c.escape_formulas = false @c.type = :integer - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) @c.type = :string @c.value = 'plain string' - assert_equal(@c.plain_string?, true) + + assert_predicate(@c, :plain_string?) @c.value = nil - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) @c.value = '' - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) @c.value = '=sum' - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) @c.value = '{=sum}' - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) @c.escape_formulas = true @c.value = '=sum' - assert_equal(@c.plain_string?, true) + + assert_predicate(@c, :plain_string?) @c.value = '{=sum}' - assert_equal(@c.plain_string?, true) + + assert_predicate(@c, :plain_string?) @c.value = 'plain string' @c.font_name = 'Arial' - assert_equal(@c.plain_string?, false) + + refute_predicate(@c, :plain_string?) end def test_to_xml_string c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) - assert_equal(c_xml.xpath("/c[@s=1]").size, 1) + + assert_equal(1, c_xml.xpath("/c[@s=1]").size) end def test_to_xml_string_nil @c.value = nil c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) - assert_equal(c_xml.xpath("/c[@s=1]").size, 1) + + assert_equal(1, c_xml.xpath("/c[@s=1]").size) end def test_to_xml_string_with_run @@ -371,7 +403,8 @@ class TestCell < Test::Unit::TestCase @c.font_name = 'arial' @c.color = 'FF0000' c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) - assert(c_xml.xpath("//b").any?) + + assert_predicate(c_xml.xpath("//b"), :any?) end def test_to_xml_string_formula @@ -381,7 +414,8 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?) + + assert_predicate(doc.xpath("//f[text()='IF(2+2=4,4,5)']"), :any?) end def test_to_xml_string_formula_escaped @@ -391,7 +425,8 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?) + + assert_predicate(doc.xpath("//t[text()='=IF(2+2=4,4,5)']"), :any?) end def test_to_xml_string_numeric_escaped @@ -401,8 +436,9 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//t[text()='-1']").any?) - assert(doc.xpath("//t[text()='+2']").any?) + + assert_predicate(doc.xpath("//t[text()='-1']"), :any?) + assert_predicate(doc.xpath("//t[text()='+2']"), :any?) end def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas @@ -422,11 +458,12 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//t[text()='@1']").any?) - assert(doc.xpath("//t[text()='%2']").any?) - assert(doc.xpath("//t[text()='|3']").any?) - assert(doc.xpath("//t[text()='\nfoo']").any?) - assert(doc.xpath("//t[text()='\tbar']").any?) + + assert_predicate(doc.xpath("//t[text()='@1']"), :any?) + assert_predicate(doc.xpath("//t[text()='%2']"), :any?) + assert_predicate(doc.xpath("//t[text()='|3']"), :any?) + assert_predicate(doc.xpath("//t[text()='\nfoo']"), :any?) + assert_predicate(doc.xpath("//t[text()='\tbar']"), :any?) end def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas_with_escape_formulas @@ -446,11 +483,12 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//t[text()='@1']").any?) - assert(doc.xpath("//t[text()='%2']").any?) - assert(doc.xpath("//t[text()='|3']").any?) - assert(doc.xpath("//t[text()='\nfoo']").any?) - assert(doc.xpath("//t[text()='\tbar']").any?) + + assert_predicate(doc.xpath("//t[text()='@1']"), :any?) + assert_predicate(doc.xpath("//t[text()='%2']"), :any?) + assert_predicate(doc.xpath("//t[text()='|3']"), :any?) + assert_predicate(doc.xpath("//t[text()='\nfoo']"), :any?) + assert_predicate(doc.xpath("//t[text()='\tbar']"), :any?) end def test_to_xml_string_formula_escape_array_parameter @@ -465,9 +503,9 @@ class TestCell < Test::Unit::TestCase doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?) - assert(doc.xpath("//f[text()='IF(13+13=4,4,5)']").any?) - assert(doc.xpath("//t[text()='=IF(99+99=4,4,5)']").any?) + assert_predicate(doc.xpath("//t[text()='=IF(2+2=4,4,5)']"), :any?) + assert_predicate(doc.xpath("//f[text()='IF(13+13=4,4,5)']"), :any?) + assert_predicate(doc.xpath("//t[text()='=IF(99+99=4,4,5)']"), :any?) end def test_to_xml_string_array_formula @@ -477,9 +515,10 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?) - assert(doc.xpath("//f[@t='array']").any?) - assert(doc.xpath("//f[@ref='A1']").any?) + + assert_predicate(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']"), :any?) + assert_predicate(doc.xpath("//f[@t='array']"), :any?) + assert_predicate(doc.xpath("//f[@ref='A1']"), :any?) end def test_to_xml_string_text_formula @@ -490,32 +529,36 @@ class TestCell < Test::Unit::TestCase doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//f[text()='1+1']").empty?) - assert(doc.xpath("//t[text()='=1+1']").any?) + assert_empty(doc.xpath("//f[text()='1+1']")) + assert_predicate(doc.xpath("//t[text()='=1+1']"), :any?) - assert(doc.xpath("//f[text()='1+1']").empty?) - assert(doc.xpath("//t[text()='-1+1']").any?) + assert_empty(doc.xpath("//f[text()='1+1']")) + assert_predicate(doc.xpath("//t[text()='-1+1']"), :any?) end def test_font_size_with_custom_style_and_no_sz @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF' sz = @c.send(:font_size) + assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz) end def test_font_size_with_bolding @c.style = @c.row.worksheet.workbook.styles.add_style :b => true + assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size)) end def test_font_size_with_custom_sz @c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52 sz = @c.send(:font_size) - assert_equal(sz, 52) + + assert_equal(52, sz) end def test_cell_with_sz @c.sz = 25 + assert_equal(25, @c.send(:font_size)) end @@ -531,6 +574,7 @@ class TestCell < Test::Unit::TestCase errors.push error puts error.message end - assert(errors.empty?, "error free validation") + + assert_empty(errors, "error free validation") end end diff --git a/test/workbook/worksheet/tc_cfvo.rb b/test/workbook/worksheet/tc_cfvo.rb index 71ba6bbc..de3aa5d8 100644 --- a/test/workbook/worksheet/tc_cfvo.rb +++ b/test/workbook/worksheet/tc_cfvo.rb @@ -7,24 +7,25 @@ class TestCfvo < Test::Unit::TestCase def test_val assert_nothing_raised { @cfvo.val = "abc" } - assert_equal(@cfvo.val, "abc") + assert_equal("abc", @cfvo.val) end def test_type assert_raise(ArgumentError) { @cfvo.type = :invalid_type } assert_nothing_raised { @cfvo.type = :max } - assert_equal(@cfvo.type, :max) + assert_equal(:max, @cfvo.type) end def test_gte assert_raise(ArgumentError) { @cfvo.gte = :bob } - assert_equal(@cfvo.gte, true) + assert(@cfvo.gte) assert_nothing_raised { @cfvo.gte = false } - assert_equal(@cfvo.gte, false) + refute(@cfvo.gte) end def test_to_xml_string doc = Nokogiri::XML.parse(@cfvo.to_xml_string) + assert doc.xpath(".//cfvo[@type='min'][@val=0][@gte=true]") end end diff --git a/test/workbook/worksheet/tc_col.rb b/test/workbook/worksheet/tc_col.rb index 986c6bb7..f9108b1a 100644 --- a/test/workbook/worksheet/tc_col.rb +++ b/test/workbook/worksheet/tc_col.rb @@ -9,6 +9,7 @@ class TestCol < Test::Unit::TestCase options = { :width => 12, :collapsed => true, :hidden => true, :outline_level => 1, :phonetic => true, :style => 1 } col = Axlsx::Col.new 0, 0, options + options.each { |key, value| assert_equal(col.send(key.to_sym), value) } end @@ -19,55 +20,59 @@ class TestCol < Test::Unit::TestCase end def test_bestFit - assert_equal(@col.bestFit, nil) + assert_nil(@col.bestFit) assert_raise(NoMethodError, 'bestFit is read only') { @col.bestFit = 'bob' } @col.width = 1.999 - assert_equal(@col.bestFit, true, 'bestFit should be true when width has been set') + + assert(@col.bestFit, 'bestFit should be true when width has been set') end def test_collapsed - assert_equal(@col.collapsed, nil) + assert_nil(@col.collapsed) assert_raise(ArgumentError, 'collapsed must be boolean(ish)') { @col.collapsed = 'bob' } assert_nothing_raised('collapsed must be boolean(ish)') { @col.collapsed = true } end def test_customWidth - assert_equal(@col.customWidth, nil) + assert_nil(@col.customWidth) @col.width = 3 assert_raise(NoMethodError, 'customWidth is read only') { @col.customWidth = 3 } - assert_equal(@col.customWidth, true, 'customWidth is true when width is set') + assert(@col.customWidth, 'customWidth is true when width is set') end def test_widthUnderLimit @col.width = 3 - assert_equal(@col.width, 3, 'width is set to exact value') + + assert_equal(3, @col.width, 'width is set to exact value') end def test_widthOverLimit @col.width = 31337 - assert_equal(@col.width, 255, 'width is set to maximum allowed value') + + assert_equal(255, @col.width, 'width is set to maximum allowed value') end def test_widthSetToNil @col.width = nil - assert_equal(@col.width, nil, 'width is set to unspecified value') + + assert_nil(@col.width, 'width is set to unspecified value') end def test_hidden - assert_equal(@col.hidden, nil) + assert_nil(@col.hidden) assert_raise(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = 'bob' } assert_nothing_raised(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = true } end def test_outlineLevel - assert_equal(@col.outlineLevel, nil) + assert_nil(@col.outlineLevel) assert_raise(ArgumentError, 'outline level cannot be negative') { @col.outlineLevel = -1 } assert_raise(ArgumentError, 'outline level cannot be greater than 7') { @col.outlineLevel = 8 } assert_nothing_raised('can set outlineLevel') { @col.outlineLevel = 1 } end def test_phonetic - assert_equal(@col.phonetic, nil) + assert_nil(@col.phonetic) assert_raise(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = 'bob' } assert_nothing_raised(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = true } end @@ -75,6 +80,7 @@ class TestCol < Test::Unit::TestCase def test_to_xml_string @col.width = 100 doc = Nokogiri::XML(@col.to_xml_string) + assert_equal(1, doc.xpath("//col [@bestFit='#{@col.best_fit ? 1 : 0}']").size) assert_equal(1, doc.xpath("//col [@max=#{@col.max}]").size) assert_equal(1, doc.xpath("//col [@min=#{@col.min}]").size) @@ -83,9 +89,10 @@ class TestCol < Test::Unit::TestCase end def test_style - assert_equal(@col.style, nil) + assert_nil(@col.style) @col.style = 1 - assert_equal(@col.style, 1) + + assert_equal(1, @col.style) # TODO: check that the style specified is actually in the styles xfs collection end end diff --git a/test/workbook/worksheet/tc_color_scale.rb b/test/workbook/worksheet/tc_color_scale.rb index 073cd71f..a4e5816b 100644 --- a/test/workbook/worksheet/tc_color_scale.rb +++ b/test/workbook/worksheet/tc_color_scale.rb @@ -7,12 +7,14 @@ class TestColorScale < Test::Unit::TestCase def test_three_tone color_scale = Axlsx::ColorScale.three_tone + assert_equal 3, color_scale.value_objects.size assert_equal 3, color_scale.colors.size end def test_two_tone color_scale = Axlsx::ColorScale.two_tone + assert_equal 2, color_scale.value_objects.size assert_equal 2, color_scale.colors.size end @@ -20,6 +22,7 @@ class TestColorScale < Test::Unit::TestCase def test_default_cfvo first = Axlsx::ColorScale.default_cfvos.first second = Axlsx::ColorScale.default_cfvos.last + assert_equal 'FFFF7128', first[:color] assert_equal :min, first[:type] assert_equal 0, first[:val] @@ -32,6 +35,7 @@ class TestColorScale < Test::Unit::TestCase def test_partial_default_cfvo_override first_def = { :type => :percent, :val => "10.0", :color => 'FF00FF00' } color_scale = Axlsx::ColorScale.new(first_def) + assert_equal color_scale.value_objects.first.val, first_def[:val] assert_equal color_scale.value_objects.first.type, first_def[:type] assert_equal color_scale.colors.first.rgb, first_def[:color] @@ -39,20 +43,22 @@ class TestColorScale < Test::Unit::TestCase def test_add @color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE" - assert_equal(@color_scale.value_objects.size, 3) - assert_equal(@color_scale.colors.size, 3) + + assert_equal(3, @color_scale.value_objects.size) + assert_equal(3, @color_scale.colors.size) end def test_delete_at @color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE" assert_nothing_raised { @color_scale.delete_at 2 } - assert_equal(@color_scale.value_objects.size, 2) - assert_equal(@color_scale.colors.size, 2) + assert_equal(2, @color_scale.value_objects.size) + assert_equal(2, @color_scale.colors.size) end def test_to_xml_string doc = Nokogiri::XML.parse(@color_scale.to_xml_string) - assert_equal(doc.xpath(".//colorScale//cfvo").size, 2) - assert_equal(doc.xpath(".//colorScale//color").size, 2) + + assert_equal(2, doc.xpath(".//colorScale//cfvo").size) + assert_equal(2, doc.xpath(".//colorScale//color").size) end end diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb index 8d5df652..9ada0b4e 100644 --- a/test/workbook/worksheet/tc_comment.rb +++ b/test/workbook/worksheet/tc_comment.rb @@ -14,59 +14,63 @@ class TestComment < Test::Unit::TestCase end def test_author - assert(@c1.author == 'author with special char <') - assert(@c2.author == 'PO') + assert_equal('author with special char <', @c1.author) + assert_equal('PO', @c2.author) end def test_text - assert(@c1.text == 'text with special char <') - assert(@c2.text == 'rust bucket') + assert_equal('text with special char <', @c1.text) + assert_equal('rust bucket', @c2.text) end def test_author_index - assert_equal(@c1.author_index, 1) - assert_equal(@c2.author_index, 0) + assert_equal(1, @c1.author_index) + assert_equal(0, @c2.author_index) end def test_visible - assert_equal(false, @c1.visible) - assert_equal(true, @c2.visible) + refute(@c1.visible) + assert(@c2.visible) end def test_ref - assert(@c1.ref == 'A1') - assert(@c2.ref == 'C3') + assert_equal('A1', @c1.ref) + assert_equal('C3', @c2.ref) end def test_vml_shape pos = Axlsx::name_to_indices(@c1.ref) + assert(@c1.vml_shape.is_a?(Axlsx::VmlShape)) - assert(@c1.vml_shape.column == pos[0]) - assert(@c1.vml_shape.row == pos[1]) - assert(@c1.vml_shape.row == pos[1]) + assert_equal(@c1.vml_shape.column, pos[0]) + assert_equal(@c1.vml_shape.row, pos[1]) + assert_equal(@c1.vml_shape.row, pos[1]) assert_equal(pos[0], @c1.vml_shape.left_column) - assert(@c1.vml_shape.top_row == pos[1]) + assert_equal(@c1.vml_shape.top_row, pos[1]) assert_equal(pos[0] + 2, @c1.vml_shape.right_column) - assert(@c1.vml_shape.bottom_row == pos[1] + 4) + assert_equal(@c1.vml_shape.bottom_row, pos[1] + 4) end def test_to_xml_string doc = Nokogiri::XML(@c1.to_xml_string) - assert_equal(doc.xpath("//comment[@ref='#{@c1.ref}']").size, 1) - assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index}']").size, 1) - assert_equal(doc.xpath("//t[text()='#{@c1.author}:\n']").size, 1) - assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1) + + assert_equal(1, doc.xpath("//comment[@ref='#{@c1.ref}']").size) + assert_equal(1, doc.xpath("//comment[@authorId='#{@c1.author_index}']").size) + assert_equal(1, doc.xpath("//t[text()='#{@c1.author}:\n']").size) + assert_equal(1, doc.xpath("//t[text()='#{@c1.text}']").size) end def test_comment_text_contain_author_and_text comment = @ws.add_comment :ref => 'C4', :text => 'some text', :author => 'Bob' doc = Nokogiri::XML(comment.to_xml_string) + assert_equal("Bob:\nsome text", doc.xpath("//comment/text").text) end def test_comment_text_does_not_contain_stray_colon_if_author_blank comment = @ws.add_comment :ref => 'C5', :text => 'some text', :author => '' doc = Nokogiri::XML(comment.to_xml_string) + assert_equal("some text", doc.xpath("//comment/text").text) end end diff --git a/test/workbook/worksheet/tc_comments.rb b/test/workbook/worksheet/tc_comments.rb index cb2e3741..55ba744f 100644 --- a/test/workbook/worksheet/tc_comments.rb +++ b/test/workbook/worksheet/tc_comments.rb @@ -15,21 +15,23 @@ class TestComments < Test::Unit::TestCase end def test_add_comment - assert_equal(@ws.comments.size, 2) + assert_equal(2, @ws.comments.size) assert_raise(ArgumentError) { @ws.comments.add_comment } assert_raise(ArgumentError) { @ws.comments.add_comment(:text => 'Yes We Can', :ref => 'A1') } assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :ref => 'A1') } assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can') } assert_nothing_raised { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can', :ref => 'A1') } - assert_equal(@ws.comments.size, 3) + assert_equal(3, @ws.comments.size) end def test_authors assert_equal(@ws.comments.authors.size, @ws.comments.size) @ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1') - assert_equal(@ws.comments.authors.size, 3) + + assert_equal(3, @ws.comments.authors.size) @ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1') - assert_equal(@ws.comments.authors.size, 3, 'only unique authors are returned') + + assert_equal(3, @ws.comments.authors.size, 'only unique authors are returned') end def test_pn @@ -47,6 +49,7 @@ class TestComments < Test::Unit::TestCase schema.validate(doc).each do |error| errors << error end + assert_equal(0, errors.length) # TODO: figure out why these xpath expressions dont work! diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb index e6fc6324..1ee26ca0 100644 --- a/test/workbook/worksheet/tc_conditional_formatting.rb +++ b/test/workbook/worksheet/tc_conditional_formatting.rb @@ -11,6 +11,7 @@ class TestConditionalFormatting < Test::Unit::TestCase def test_initialize_with_options optioned = Axlsx::ConditionalFormatting.new(:sqref => "AA1:AB100", :rules => [1, 2]) + assert_equal("AA1:AB100", optioned.sqref) assert_equal([1, 2], optioned.rules) end @@ -37,24 +38,28 @@ class TestConditionalFormatting < Test::Unit::TestCase assert(cfr.color_scale.is_a?(Axlsx::ColorScale)) cfs = @ws.add_conditional_formatting("B2:B2", [cfr]) doc = Nokogiri::XML.parse(cfs.last.to_xml_string) + assert_equal(1, doc.xpath(".//conditionalFormatting[@sqref='B2:B2']//cfRule[@type='containsText'][@dxfId=0][@priority=1]").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='containsText'][@dxfId=0][@priority=1]//formula='NOT(ISERROR(SEARCH(\"FALSE\",AB1)))'") cfs.last.rules.last.type = :colorScale doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size, 2) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size, 2) + + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size) + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size) cfs.last.rules.last.type = :dataBar doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar").size, 1) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size, 2) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size, 1) + + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar").size) + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size) cfs.last.rules.last.type = :iconSet doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 3) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size, 1) + + assert_equal(3, doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size) end def test_add_as_hash @@ -75,28 +80,33 @@ class TestConditionalFormatting < Test::Unit::TestCase :data_bar => data_bar, :icon_set => icon_set }]) doc = Nokogiri::XML.parse(cfs.last.to_xml_string) + assert_equal(1, doc.xpath(".//conditionalFormatting[@sqref='B2:B2']//cfRule[@type='containsText'][@dxfId=0][@priority=1]").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='containsText'][@dxfId=0][@priority=1]//formula='NOT(ISERROR(SEARCH(\"FALSE\",AB1)))'") cfs.last.rules.last.type = :colorScale doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size, 2) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size, 2) + + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size) + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size) cfs.last.rules.last.type = :dataBar doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar").size, 1) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size, 2) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size, 1) + + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar").size) + assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size) cfs.last.rules.last.type = :iconSet doc = Nokogiri::XML.parse(cfs.last.to_xml_string) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 3) - assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size, 1) + + assert_equal(3, doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size) end def test_single_rule doc = Nokogiri::XML.parse(@cf.to_xml_string) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//formula='0.5'") end @@ -108,12 +118,14 @@ class TestConditionalFormatting < Test::Unit::TestCase :percent => false, :rank => 0, :stdDev => 1, :stopIfTrue => true, :timePeriod => :today, :formula => "0.0" }) doc = Nokogiri::XML.parse(cf.to_xml_string) + assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage=0][@bottom=0][@dxfId=0][@equalAverage=0][@priority=2][@operator='lessThan'][@text=''][@percent=0][@rank=0][@stdDev=1][@stopIfTrue=1][@timePeriod='today']").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage=0][@bottom=0][@dxfId=0][@equalAverage=0][@priority=2][@operator='lessThan'][@text=''][@percent=0][@rank=0][@stdDev=1][@stopIfTrue=1][@timePeriod='today']//formula=0.0") end def test_to_xml doc = Nokogiri::XML.parse(@ws.to_xml_string) + assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size) assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'") end @@ -121,6 +133,7 @@ class TestConditionalFormatting < Test::Unit::TestCase def test_multiple_formats @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :greaterThan, :formula => "1" } doc = Nokogiri::XML.parse(@ws.to_xml_string) + assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='1'") assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'") end @@ -128,6 +141,7 @@ class TestConditionalFormatting < Test::Unit::TestCase def test_multiple_formulas @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2", "5"] } doc = Nokogiri::XML.parse(@ws.to_xml_string) + assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1 <> 2'") assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='5'") end @@ -135,84 +149,84 @@ class TestConditionalFormatting < Test::Unit::TestCase def test_sqref assert_raise(ArgumentError) { @cf.sqref = 10 } assert_nothing_raised { @cf.sqref = "A1:A1" } - assert_equal(@cf.sqref, "A1:A1") + assert_equal("A1:A1", @cf.sqref) end def test_type assert_raise(ArgumentError) { @cfr.type = "illegal" } assert_nothing_raised { @cfr.type = :containsBlanks } - assert_equal(@cfr.type, :containsBlanks) + assert_equal(:containsBlanks, @cfr.type) end def test_above_average assert_raise(ArgumentError) { @cfr.aboveAverage = "illegal" } assert_nothing_raised { @cfr.aboveAverage = true } - assert_equal(@cfr.aboveAverage, true) + assert(@cfr.aboveAverage) end def test_equal_average assert_raise(ArgumentError) { @cfr.equalAverage = "illegal" } assert_nothing_raised { @cfr.equalAverage = true } - assert_equal(@cfr.equalAverage, true) + assert(@cfr.equalAverage) end def test_bottom assert_raise(ArgumentError) { @cfr.bottom = "illegal" } assert_nothing_raised { @cfr.bottom = true } - assert_equal(@cfr.bottom, true) + assert(@cfr.bottom) end def test_operator assert_raise(ArgumentError) { @cfr.operator = "cellIs" } assert_nothing_raised { @cfr.operator = :notBetween } - assert_equal(@cfr.operator, :notBetween) + assert_equal(:notBetween, @cfr.operator) end def test_dxf_id assert_raise(ArgumentError) { @cfr.dxfId = "illegal" } assert_nothing_raised { @cfr.dxfId = 1 } - assert_equal(@cfr.dxfId, 1) + assert_equal(1, @cfr.dxfId) end def test_priority assert_raise(ArgumentError) { @cfr.priority = -1.0 } assert_nothing_raised { @cfr.priority = 1 } - assert_equal(@cfr.priority, 1) + assert_equal(1, @cfr.priority) end def test_text assert_raise(ArgumentError) { @cfr.text = 1.0 } assert_nothing_raised { @cfr.text = "testing" } - assert_equal(@cfr.text, "testing") + assert_equal("testing", @cfr.text) end def test_percent assert_raise(ArgumentError) { @cfr.percent = "10%" } # WRONG! assert_nothing_raised { @cfr.percent = true } - assert_equal(@cfr.percent, true) + assert(@cfr.percent) end def test_rank assert_raise(ArgumentError) { @cfr.rank = -1 } assert_nothing_raised { @cfr.rank = 1 } - assert_equal(@cfr.rank, 1) + assert_equal(1, @cfr.rank) end def test_std_dev assert_raise(ArgumentError) { @cfr.stdDev = -1 } assert_nothing_raised { @cfr.stdDev = 1 } - assert_equal(@cfr.stdDev, 1) + assert_equal(1, @cfr.stdDev) end def test_stop_if_true assert_raise(ArgumentError) { @cfr.stopIfTrue = "illegal" } assert_nothing_raised { @cfr.stopIfTrue = false } - assert_equal(@cfr.stopIfTrue, false) + refute(@cfr.stopIfTrue) end def test_time_period assert_raise(ArgumentError) { @cfr.timePeriod = "illegal" } assert_nothing_raised { @cfr.timePeriod = :today } - assert_equal(@cfr.timePeriod, :today) + assert_equal(:today, @cfr.timePeriod) end end diff --git a/test/workbook/worksheet/tc_data_bar.rb b/test/workbook/worksheet/tc_data_bar.rb index aa39c48b..ccb31d40 100644 --- a/test/workbook/worksheet/tc_data_bar.rb +++ b/test/workbook/worksheet/tc_data_bar.rb @@ -6,13 +6,14 @@ class TestDataBar < Test::Unit::TestCase end def test_defaults - assert_equal @data_bar.minLength, 10 - assert_equal @data_bar.maxLength, 90 - assert_equal @data_bar.showValue, true + assert_equal(10, @data_bar.minLength) + assert_equal(90, @data_bar.maxLength) + assert(@data_bar.showValue) end def test_override_default_cfvos data_bar = Axlsx::DataBar.new({ :color => 'FF00FF00' }, { :type => :min, :val => "20" }) + assert_equal("20", data_bar.value_objects.first.val) assert_equal("0", data_bar.value_objects.last.val) end @@ -20,25 +21,26 @@ class TestDataBar < Test::Unit::TestCase def test_minLength assert_raise(ArgumentError) { @data_bar.minLength = :invalid_type } assert_nothing_raised { @data_bar.minLength = 0 } - assert_equal(@data_bar.minLength, 0) + assert_equal(0, @data_bar.minLength) end def test_maxLength assert_raise(ArgumentError) { @data_bar.maxLength = :invalid_type } assert_nothing_raised { @data_bar.maxLength = 0 } - assert_equal(@data_bar.maxLength, 0) + assert_equal(0, @data_bar.maxLength) end def test_showValue assert_raise(ArgumentError) { @data_bar.showValue = :invalid_type } assert_nothing_raised { @data_bar.showValue = false } - assert_equal(@data_bar.showValue, false) + refute(@data_bar.showValue) end def test_to_xml_string doc = Nokogiri::XML.parse(@data_bar.to_xml_string) - assert_equal(doc.xpath(".//dataBar[@minLength=10][@maxLength=90][@showValue=1]").size, 1) - assert_equal(doc.xpath(".//dataBar//cfvo").size, 2) - assert_equal(doc.xpath(".//dataBar//color").size, 1) + + assert_equal(1, doc.xpath(".//dataBar[@minLength=10][@maxLength=90][@showValue=1]").size) + assert_equal(2, doc.xpath(".//dataBar//cfvo").size) + assert_equal(1, doc.xpath(".//dataBar//color").size) end end diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb index aac2019d..aa4efd55 100644 --- a/test/workbook/worksheet/tc_data_validation.rb +++ b/test/workbook/worksheet/tc_data_validation.rb @@ -28,7 +28,7 @@ class TestDataValidation < Test::Unit::TestCase end @nil_options.each do |key, value| - assert_equal(nil, dv.send(key.to_sym), "initialized default #{key} should be nil") + assert_nil(dv.send(key.to_sym), "initialized default #{key} should be nil") assert_equal(value, @dv.send(key.to_sym), "initialized options #{key} should be #{value}") end @@ -67,62 +67,62 @@ class TestDataValidation < Test::Unit::TestCase def test_formula1 assert_raise(ArgumentError) { @dv.formula1 = 10 } assert_nothing_raised { @dv.formula1 = "=SUM(A1:A1)" } - assert_equal(@dv.formula1, "=SUM(A1:A1)") + assert_equal("=SUM(A1:A1)", @dv.formula1) end def test_formula2 assert_raise(ArgumentError) { @dv.formula2 = 10 } assert_nothing_raised { @dv.formula2 = "=SUM(A1:A1)" } - assert_equal(@dv.formula2, "=SUM(A1:A1)") + assert_equal("=SUM(A1:A1)", @dv.formula2) end def test_allowBlank assert_raise(ArgumentError) { @dv.allowBlank = "foo´" } assert_nothing_raised { @dv.allowBlank = false } - assert_equal(@dv.allowBlank, false) + refute(@dv.allowBlank) end def test_error assert_raise(ArgumentError) { @dv.error = :symbol } assert_nothing_raised { @dv.error = "This is a error message" } - assert_equal(@dv.error, "This is a error message") + assert_equal("This is a error message", @dv.error) end def test_errorStyle assert_raise(ArgumentError) { @dv.errorStyle = "foo" } assert_nothing_raised { @dv.errorStyle = :information } - assert_equal(@dv.errorStyle, :information) + assert_equal(:information, @dv.errorStyle) end def test_errorTitle assert_raise(ArgumentError) { @dv.errorTitle = :symbol } assert_nothing_raised { @dv.errorTitle = "This is the error title" } - assert_equal(@dv.errorTitle, "This is the error title") + assert_equal("This is the error title", @dv.errorTitle) end def test_operator assert_raise(ArgumentError) { @dv.operator = "foo" } assert_nothing_raised { @dv.operator = :greaterThan } - assert_equal(@dv.operator, :greaterThan) + assert_equal(:greaterThan, @dv.operator) end def test_prompt assert_raise(ArgumentError) { @dv.prompt = :symbol } assert_nothing_raised { @dv.prompt = "This is a prompt message" } - assert_equal(@dv.prompt, "This is a prompt message") + assert_equal("This is a prompt message", @dv.prompt) end def test_promptTitle assert_raise(ArgumentError) { @dv.promptTitle = :symbol } assert_nothing_raised { @dv.promptTitle = "This is the prompt title" } - assert_equal(@dv.promptTitle, "This is the prompt title") + assert_equal("This is the prompt title", @dv.promptTitle) end def test_showDropDown warnings = capture_warnings do assert_raise(ArgumentError) { @dv.showDropDown = "foo´" } assert_nothing_raised { @dv.showDropDown = false } - assert_equal(@dv.showDropDown, false) + refute(@dv.showDropDown) end assert_equal 2, warnings.size @@ -132,33 +132,33 @@ class TestDataValidation < Test::Unit::TestCase def test_hideDropDown assert_raise(ArgumentError) { @dv.hideDropDown = "foo´" } assert_nothing_raised { @dv.hideDropDown = false } - assert_equal(@dv.hideDropDown, false) + refute(@dv.hideDropDown) # As hideDropdown is just an alias for showDropDown, we should test the original value too - assert_equal(@dv.showDropDown, false) + refute(@dv.showDropDown) end def test_showErrorMessage assert_raise(ArgumentError) { @dv.showErrorMessage = "foo´" } assert_nothing_raised { @dv.showErrorMessage = false } - assert_equal(@dv.showErrorMessage, false) + refute(@dv.showErrorMessage) end def test_showInputMessage assert_raise(ArgumentError) { @dv.showInputMessage = "foo´" } assert_nothing_raised { @dv.showInputMessage = false } - assert_equal(@dv.showInputMessage, false) + refute(@dv.showInputMessage) end def test_sqref assert_raise(ArgumentError) { @dv.sqref = 10 } assert_nothing_raised { @dv.sqref = "A1:A1" } - assert_equal(@dv.sqref, "A1:A1") + assert_equal("A1:A1", @dv.sqref) end def test_type assert_raise(ArgumentError) { @dv.type = "foo" } assert_nothing_raised { @dv.type = :list } - assert_equal(@dv.type, :list) + assert_equal(:list, @dv.type) end def test_whole_decimal_data_time_textLength_to_xml @@ -273,6 +273,7 @@ class TestDataValidation < Test::Unit::TestCase def test_empty_attributes v = Axlsx::DataValidation.new - assert_equal(nil, v.send(:get_valid_attributes)) + + assert_nil(v.send(:get_valid_attributes)) end end diff --git a/test/workbook/worksheet/tc_date_time_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb index 891fa80f..4bf0e930 100644 --- a/test/workbook/worksheet/tc_date_time_converter.rb +++ b/test/workbook/worksheet/tc_date_time_converter.rb @@ -32,6 +32,7 @@ class TestDateTimeConverter < Test::Unit::TestCase end tests.each do |date_string, expected| serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string) + assert_equal expected, serial end end @@ -56,6 +57,7 @@ class TestDateTimeConverter < Test::Unit::TestCase end tests.each do |date_string, expected| serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string) + assert_equal expected, serial end end @@ -80,6 +82,7 @@ class TestDateTimeConverter < Test::Unit::TestCase end tests.each do |time_string, expected| serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string) + assert_in_delta expected, serial, @margin_of_error end end @@ -105,6 +108,7 @@ class TestDateTimeConverter < Test::Unit::TestCase end tests.each do |time_string, expected| serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string) + assert_in_delta expected, serial, @margin_of_error end end @@ -116,6 +120,7 @@ class TestDateTimeConverter < Test::Unit::TestCase assert_equal local, utc assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86400), Axlsx::DateTimeConverter::time_to_serial(utc) Axlsx::Workbook.date1904 = true + assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86400), Axlsx::DateTimeConverter::time_to_serial(utc) end end diff --git a/test/workbook/worksheet/tc_header_footer.rb b/test/workbook/worksheet/tc_header_footer.rb index 1ecea096..45a90825 100644 --- a/test/workbook/worksheet/tc_header_footer.rb +++ b/test/workbook/worksheet/tc_header_footer.rb @@ -8,17 +8,17 @@ class TestHeaderFooter < Test::Unit::TestCase end def test_initialize - assert_equal(nil, @hf.odd_header) - assert_equal(nil, @hf.odd_footer) + assert_nil(@hf.odd_header) + assert_nil(@hf.odd_footer) - assert_equal(nil, @hf.even_header) - assert_equal(nil, @hf.even_footer) + assert_nil(@hf.even_header) + assert_nil(@hf.even_footer) - assert_equal(nil, @hf.first_header) - assert_equal(nil, @hf.first_footer) + assert_nil(@hf.first_header) + assert_nil(@hf.first_footer) - assert_equal(nil, @hf.different_first) - assert_equal(nil, @hf.different_odd_even) + assert_nil(@hf.different_first) + assert_nil(@hf.different_odd_even) end def test_initialize_with_options @@ -46,8 +46,8 @@ class TestHeaderFooter < Test::Unit::TestCase assert_equal('fh', optioned.first_header) assert_equal('ff', optioned.first_footer) - assert_equal(true, optioned.different_first) - assert_equal(true, optioned.different_odd_even) + assert(optioned.different_first) + assert(optioned.different_odd_even) end def test_string_attributes @@ -88,8 +88,8 @@ class TestHeaderFooter < Test::Unit::TestCase assert_equal('fh', @hf.first_header) assert_equal('ff', @hf.first_footer) - assert_equal(true, @hf.different_first) - assert_equal(true, @hf.different_odd_even) + assert(@hf.different_first) + assert(@hf.different_odd_even) end def test_to_xml_all_values @@ -108,6 +108,7 @@ class TestHeaderFooter < Test::Unit::TestCase ) doc = Nokogiri::XML.parse(@hf.to_xml_string) + assert_equal(1, doc.xpath(".//headerFooter[@differentFirst=1][@differentOddEven=1]").size) assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size) @@ -133,6 +134,7 @@ class TestHeaderFooter < Test::Unit::TestCase ) doc = Nokogiri::XML.parse(@hf.to_xml_string) + assert_equal(1, doc.xpath(".//headerFooter[@differentOddEven=0]").size) assert_equal(0, doc.xpath(".//headerFooter[@differentFirst]").size) diff --git a/test/workbook/worksheet/tc_icon_set.rb b/test/workbook/worksheet/tc_icon_set.rb index 3a4079bf..3a52cb98 100644 --- a/test/workbook/worksheet/tc_icon_set.rb +++ b/test/workbook/worksheet/tc_icon_set.rb @@ -6,39 +6,40 @@ class TestIconSet < Test::Unit::TestCase end def test_defaults - assert_equal @icon_set.iconSet, "3TrafficLights1" - assert_equal @icon_set.percent, true - assert_equal @icon_set.reverse, false - assert_equal @icon_set.showValue, true + assert_equal("3TrafficLights1", @icon_set.iconSet) + assert(@icon_set.percent) + refute(@icon_set.reverse) + assert(@icon_set.showValue) end def test_icon_set assert_raise(ArgumentError) { @icon_set.iconSet = "invalid_value" } assert_nothing_raised { @icon_set.iconSet = "5Rating" } - assert_equal(@icon_set.iconSet, "5Rating") + assert_equal("5Rating", @icon_set.iconSet) end def test_percent assert_raise(ArgumentError) { @icon_set.percent = :invalid_type } assert_nothing_raised { @icon_set.percent = false } - assert_equal(@icon_set.percent, false) + refute(@icon_set.percent) end def test_showValue assert_raise(ArgumentError) { @icon_set.showValue = :invalid_type } assert_nothing_raised { @icon_set.showValue = false } - assert_equal(@icon_set.showValue, false) + refute(@icon_set.showValue) end def test_reverse assert_raise(ArgumentError) { @icon_set.reverse = :invalid_type } assert_nothing_raised { @icon_set.reverse = false } - assert_equal(@icon_set.reverse, false) + refute(@icon_set.reverse) end def test_to_xml_string doc = Nokogiri::XML.parse(@icon_set.to_xml_string) - assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size, 1) - assert_equal(doc.xpath(".//iconSet//cfvo").size, 3) + + assert_equal(1, doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size) + assert_equal(3, doc.xpath(".//iconSet//cfvo").size) end end diff --git a/test/workbook/worksheet/tc_outline_pr.rb b/test/workbook/worksheet/tc_outline_pr.rb index d2906a61..c6b086fe 100644 --- a/test/workbook/worksheet/tc_outline_pr.rb +++ b/test/workbook/worksheet/tc_outline_pr.rb @@ -6,14 +6,14 @@ class TestOutlinePr < Test::Unit::TestCase end def test_summary_below - assert_equal false, @outline_pr.summary_below + refute @outline_pr.summary_below end def test_summary_right - assert_equal true, @outline_pr.summary_right + assert @outline_pr.summary_right end def test_apply_styles - assert_equal false, @outline_pr.apply_styles + refute @outline_pr.apply_styles end end diff --git a/test/workbook/worksheet/tc_page_margins.rb b/test/workbook/worksheet/tc_page_margins.rb index ba532e7f..26aa4850 100644 --- a/test/workbook/worksheet/tc_page_margins.rb +++ b/test/workbook/worksheet/tc_page_margins.rb @@ -18,28 +18,31 @@ class TestPageMargins < Test::Unit::TestCase def test_initialize_with_options optioned = Axlsx::PageMargins.new(:left => 2, :right => 3, :top => 2, :bottom => 1, :header => 0.1, :footer => 0.1) + assert_equal(2, optioned.left) assert_equal(3, optioned.right) assert_equal(2, optioned.top) assert_equal(1, optioned.bottom) - assert_equal(0.1, optioned.header) - assert_equal(0.1, optioned.footer) + assert_in_delta(0.1, optioned.header) + assert_in_delta(0.1, optioned.footer) end def test_set_all_values @pm.set(:left => 1.1, :right => 1.2, :top => 1.3, :bottom => 1.4, :header => 0.8, :footer => 0.9) - assert_equal(1.1, @pm.left) - assert_equal(1.2, @pm.right) - assert_equal(1.3, @pm.top) - assert_equal(1.4, @pm.bottom) - assert_equal(0.8, @pm.header) - assert_equal(0.9, @pm.footer) + + assert_in_delta(1.1, @pm.left) + assert_in_delta(1.2, @pm.right) + assert_in_delta(1.3, @pm.top) + assert_in_delta(1.4, @pm.bottom) + assert_in_delta(0.8, @pm.header) + assert_in_delta(0.9, @pm.footer) end def test_set_some_values @pm.set(:left => 1.1, :right => 1.2) - assert_equal(1.1, @pm.left) - assert_equal(1.2, @pm.right) + + assert_in_delta(1.1, @pm.left) + assert_in_delta(1.2, @pm.right) assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.top) assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.bottom) assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.header) @@ -54,42 +57,43 @@ class TestPageMargins < Test::Unit::TestCase @pm.header = 0.8 @pm.footer = 0.9 doc = Nokogiri::XML.parse(@pm.to_xml_string) + assert_equal(1, doc.xpath(".//pageMargins[@left=1.1][@right=1.2][@top=1.3][@bottom=1.4][@header=0.8][@footer=0.9]").size) end def test_left assert_raise(ArgumentError) { @pm.left = -1.2 } assert_nothing_raised { @pm.left = 1.5 } - assert_equal(@pm.left, 1.5) + assert_in_delta(@pm.left, 1.5) end def test_right assert_raise(ArgumentError) { @pm.right = -1.2 } assert_nothing_raised { @pm.right = 1.5 } - assert_equal(@pm.right, 1.5) + assert_in_delta(@pm.right, 1.5) end def test_top assert_raise(ArgumentError) { @pm.top = -1.2 } assert_nothing_raised { @pm.top = 1.5 } - assert_equal(@pm.top, 1.5) + assert_in_delta(@pm.top, 1.5) end def test_bottom assert_raise(ArgumentError) { @pm.bottom = -1.2 } assert_nothing_raised { @pm.bottom = 1.5 } - assert_equal(@pm.bottom, 1.5) + assert_in_delta(@pm.bottom, 1.5) end def test_header assert_raise(ArgumentError) { @pm.header = -1.2 } assert_nothing_raised { @pm.header = 1.5 } - assert_equal(@pm.header, 1.5) + assert_in_delta(@pm.header, 1.5) end def test_footer assert_raise(ArgumentError) { @pm.footer = -1.2 } assert_nothing_raised { @pm.footer = 1.5 } - assert_equal(@pm.footer, 1.5) + assert_in_delta(@pm.footer, 1.5) end end diff --git a/test/workbook/worksheet/tc_page_set_up_pr.rb b/test/workbook/worksheet/tc_page_set_up_pr.rb index 8ca4f825..f634ba38 100644 --- a/test/workbook/worksheet/tc_page_set_up_pr.rb +++ b/test/workbook/worksheet/tc_page_set_up_pr.rb @@ -6,10 +6,10 @@ class TestPageSetUpPr < Test::Unit::TestCase end def test_fit_to_page - assert_equal true, @page_setup_pr.fit_to_page + assert @page_setup_pr.fit_to_page end def test_auto_page_breaks - assert_equal true, @page_setup_pr.auto_page_breaks + assert @page_setup_pr.auto_page_breaks end end diff --git a/test/workbook/worksheet/tc_page_setup.rb b/test/workbook/worksheet/tc_page_setup.rb index 6dca8b0a..85b0013a 100644 --- a/test/workbook/worksheet/tc_page_setup.rb +++ b/test/workbook/worksheet/tc_page_setup.rb @@ -8,12 +8,12 @@ class TestPageSetup < Test::Unit::TestCase end def test_initialize - assert_equal(nil, @ps.fit_to_height) - assert_equal(nil, @ps.fit_to_width) - assert_equal(nil, @ps.orientation) - assert_equal(nil, @ps.paper_height) - assert_equal(nil, @ps.paper_width) - assert_equal(nil, @ps.scale) + assert_nil(@ps.fit_to_height) + assert_nil(@ps.fit_to_width) + assert_nil(@ps.orientation) + assert_nil(@ps.paper_height) + assert_nil(@ps.paper_width) + assert_nil(@ps.scale) end def test_initialize_with_options @@ -25,6 +25,7 @@ class TestPageSetup < Test::Unit::TestCase :scale => 50 } optioned = @p.workbook.add_worksheet(:name => 'optioned', :page_setup => page_setup).page_setup + assert_equal(1, optioned.fit_to_height) assert_equal(2, optioned.fit_to_width) assert_equal(:landscape, optioned.orientation) @@ -35,6 +36,7 @@ class TestPageSetup < Test::Unit::TestCase def test_set_all_values @ps.set(:fit_to_height => 1, :fit_to_width => 2, :orientation => :landscape, :paper_height => "297mm", :paper_width => "210mm", :scale => 50) + assert_equal(1, @ps.fit_to_height) assert_equal(2, @ps.fit_to_width) assert_equal(:landscape, @ps.orientation) @@ -50,40 +52,45 @@ class TestPageSetup < Test::Unit::TestCase def test_set_some_values @ps.set(:fit_to_width => 2, :orientation => :portrait) + assert_equal(2, @ps.fit_to_width) assert_equal(:portrait, @ps.orientation) - assert_equal(nil, @ps.fit_to_height) - assert_equal(nil, @ps.paper_height) - assert_equal(nil, @ps.paper_width) - assert_equal(nil, @ps.scale) + assert_nil(@ps.fit_to_height) + assert_nil(@ps.paper_height) + assert_nil(@ps.paper_width) + assert_nil(@ps.scale) end def test_default_fit_to_page? assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) - assert(@ps.fit_to_page? == false) + refute_predicate(@ps, :fit_to_page?) end def test_with_height_fit_to_page? assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) @ps.set(:fit_to_height => 1) - assert(@ps.fit_to_page?) + + assert_predicate(@ps, :fit_to_page?) end def test_with_width_fit_to_page? assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) @ps.set(:fit_to_width => 1) - assert(@ps.fit_to_page?) + + assert_predicate(@ps, :fit_to_page?) end def test_to_xml_all_values @ps.set(:fit_to_height => 1, :fit_to_width => 2, :orientation => :landscape, :paper_height => "297mm", :paper_width => "210mm", :scale => 50) doc = Nokogiri::XML.parse(@ps.to_xml_string) + assert_equal(1, doc.xpath(".//pageSetup[@fitToHeight='1'][@fitToWidth='2'][@orientation='landscape'][@paperHeight='297mm'][@paperWidth='210mm'][@scale='50']").size) end def test_to_xml_some_values @ps.set(:orientation => :portrait) doc = Nokogiri::XML.parse(@ps.to_xml_string) + assert_equal(1, doc.xpath(".//pageSetup[@orientation='portrait']").size) assert_equal(0, doc.xpath(".//pageSetup[@fitToHeight]").size) assert_equal(0, doc.xpath(".//pageSetup[@fitToWidth]").size) @@ -130,11 +137,14 @@ class TestPageSetup < Test::Unit::TestCase def test_fit_to fits = @ps.fit_to(:width => 1) + assert_equal([1, 999], fits) fits = @ps.fit_to :height => 1 - assert_equal(fits, [999, 1]) + + assert_equal([999, 1], fits) fits = @ps.fit_to :height => 7, :width => 2 - assert_equal(fits, [2, 7]) + + assert_equal([2, 7], fits) assert_raise(ArgumentError) { puts @ps.fit_to(:width => true) } end end diff --git a/test/workbook/worksheet/tc_pane.rb b/test/workbook/worksheet/tc_pane.rb index 9a16866b..0e0c98fb 100644 --- a/test/workbook/worksheet/tc_pane.rb +++ b/test/workbook/worksheet/tc_pane.rb @@ -13,41 +13,43 @@ class TestPane < Test::Unit::TestCase def test_active_pane assert_raise(ArgumentError) { @pane.active_pane = "10" } assert_nothing_raised { @pane.active_pane = :top_left } - assert_equal(@pane.active_pane, "topLeft") + assert_equal("topLeft", @pane.active_pane) end def test_state assert_raise(ArgumentError) { @pane.state = "foo" } assert_nothing_raised { @pane.state = :frozen_split } - assert_equal(@pane.state, "frozenSplit") + assert_equal("frozenSplit", @pane.state) end def test_x_split assert_raise(ArgumentError) { @pane.x_split = "foo´" } assert_nothing_raised { @pane.x_split = 200 } - assert_equal(@pane.x_split, 200) + assert_equal(200, @pane.x_split) end def test_y_split assert_raise(ArgumentError) { @pane.y_split = 'foo' } assert_nothing_raised { @pane.y_split = 300 } - assert_equal(@pane.y_split, 300) + assert_equal(300, @pane.y_split) end def test_top_left_cell assert_raise(ArgumentError) { @pane.top_left_cell = :cell } assert_nothing_raised { @pane.top_left_cell = "A2" } - assert_equal(@pane.top_left_cell, "A2") + assert_equal("A2", @pane.top_left_cell) end def test_to_xml doc = Nokogiri::XML.parse(@pane.to_xml_string) + assert_equal(1, doc.xpath("//pane[@ySplit=2][@xSplit='2'][@topLeftCell='A2'][@state='frozen'][@activePane='bottomLeft']").size) end def test_to_xml_frozen pane = Axlsx::Pane.new :state => :frozen, :y_split => 2 doc = Nokogiri::XML(pane.to_xml_string) + assert_equal(1, doc.xpath("//pane[@topLeftCell='A3']").size) end end diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb index a5bb8906..91df5597 100644 --- a/test/workbook/worksheet/tc_pivot_table.rb +++ b/test/workbook/worksheet/tc_pivot_table.rb @@ -8,7 +8,8 @@ def shared_test_pivot_table_xml_validity(pivot_table) errors.push error puts error.message end - assert(errors.empty?, "error free validation") + + assert_empty(errors, "error free validation") end class TestPivotTable < Test::Unit::TestCase @@ -21,12 +22,13 @@ class TestPivotTable < Test::Unit::TestCase end def test_initialization - assert(@ws.workbook.pivot_tables.empty?) - assert(@ws.pivot_tables.empty?) + assert_empty(@ws.workbook.pivot_tables) + assert_empty(@ws.pivot_tables) end def test_add_pivot_table pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') + assert_equal('G5:G6', pivot_table.ref, 'ref assigned from first parameter') assert_equal('A1:D5', pivot_table.range, 'range assigned from second parameter') assert_equal('PivotTable1', pivot_table.name, 'name automatically generated') @@ -42,6 +44,7 @@ class TestPivotTable < Test::Unit::TestCase assert_equal(pivot_table.data_sheet.name, @ws.name, "must default to the same sheet the pivot table is added to") pivot_table.data_sheet = data_sheet + assert_equal(pivot_table.data_sheet.name, data_sheet.name, "data sheet assigned to pivot table") end @@ -52,6 +55,7 @@ class TestPivotTable < Test::Unit::TestCase pt.data = ['Sales'] pt.pages = ['Region'] end + assert_equal(['Year', 'Month'], pivot_table.rows) assert_equal(['Type'], pivot_table.columns) assert_equal([{ :ref => "Sales" }], pivot_table.data) @@ -63,6 +67,7 @@ class TestPivotTable < Test::Unit::TestCase pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt| pt.data = [{ :ref => "Sales", :subtotal => 'average' }] end + assert_equal([{ :ref => "Sales", :subtotal => 'average' }], pivot_table.data) end @@ -74,6 +79,7 @@ class TestPivotTable < Test::Unit::TestCase pt.data = ['Sales'] pt.pages = ['Region'] end + assert_equal(style_info_data, pivot_table.style_info) shared_test_pivot_table_xml_validity(pivot_table) end @@ -83,6 +89,7 @@ class TestPivotTable < Test::Unit::TestCase pt.data = ['Sales'] pt.rows = ['Year', 'Month'] end + assert_equal(['Year'], pivot_table.no_subtotals_on_headers) end @@ -91,9 +98,11 @@ class TestPivotTable < Test::Unit::TestCase pt.data = ['Sales'] pt.rows = ['Year', 'Month'] end + assert_equal({ 'Month' => :ascending }, pivot_table.sort_on_headers) pivot_table.sort_on_headers = { 'Month' => :descending } + assert_equal({ 'Month' => :descending }, pivot_table.sort_on_headers) shared_test_pivot_table_xml_validity(pivot_table) @@ -101,31 +110,36 @@ class TestPivotTable < Test::Unit::TestCase def test_header_indices pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') + assert_equal(0, pivot_table.header_index_of('Year')) assert_equal(1, pivot_table.header_index_of('Month')) assert_equal(2, pivot_table.header_index_of('Region')) assert_equal(3, pivot_table.header_index_of('Type')) assert_equal(4, pivot_table.header_index_of('Sales')) - assert_equal(nil, pivot_table.header_index_of('Missing')) + assert_nil(pivot_table.header_index_of('Missing')) assert_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs) end def test_pn @ws.add_pivot_table('G5:G6', 'A1:D5') - assert_equal(@ws.pivot_tables.first.pn, "pivotTables/pivotTable1.xml") + + assert_equal("pivotTables/pivotTable1.xml", @ws.pivot_tables.first.pn) end def test_index @ws.add_pivot_table('G5:G6', 'A1:D5') + assert_equal(@ws.pivot_tables.first.index, @ws.workbook.pivot_tables.index(@ws.pivot_tables.first)) end def test_relationships - assert(@ws.relationships.empty?) + assert_empty(@ws.relationships) @ws.add_pivot_table('G5:G6', 'A1:D5') - assert_equal(@ws.relationships.size, 1, "adding a pivot table adds a relationship") + + assert_equal(1, @ws.relationships.size, "adding a pivot table adds a relationship") @ws.add_pivot_table('G10:G11', 'A1:D5') - assert_equal(@ws.relationships.size, 2, "adding a pivot table adds a relationship") + + assert_equal(2, @ws.relationships.size, "adding a pivot table adds a relationship") end def test_to_xml_string @@ -150,6 +164,7 @@ class TestPivotTable < Test::Unit::TestCase pt.data = [{ :ref => "Sales", :subtotal => 'sum', num_fmt: 4 }] end doc = Nokogiri::XML(pivot_table.to_xml_string) + assert_equal('4', doc.at_css('dataFields dataField')['numFmtId'], 'adding format options to pivot_table') end @@ -167,9 +182,9 @@ class TestPivotTable < Test::Unit::TestCase xml = pivot_table.to_xml_string - assert(!xml.include?('dataOnRows')) - assert(xml.include?('colFields')) - assert(xml.include?('colItems')) + refute_includes(xml, 'dataOnRows') + assert_includes(xml, 'colFields') + assert_includes(xml, 'colItems') doc = Nokogiri::XML(pivot_table.to_xml_string) @@ -195,9 +210,9 @@ class TestPivotTable < Test::Unit::TestCase xml = pivot_table.to_xml_string - assert(xml.include?('dataOnRows')) - assert(xml.include?('colItems')) + assert_includes(xml, 'dataOnRows') + assert_includes(xml, 'colItems') - assert(!xml.include?('colFields')) + refute_includes(xml, 'colFields') end end diff --git a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb index 2127c4b3..b3a4484d 100644 --- a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +++ b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb @@ -37,7 +37,7 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase data_sheet.name = "Pivot Table Data Source" @pivot_table.data_sheet = data_sheet - assert(@cache_definition.to_xml_string.include?(data_sheet.name), "must set the data source correctly") + assert_includes(@cache_definition.to_xml_string, data_sheet.name, "must set the data source correctly") end def test_to_xml_string @@ -48,7 +48,8 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase errors.push error puts error.message end - assert(errors.empty?, "error free validation") + + assert_empty(errors, "error free validation") end def test_to_xml_string_for_special_characters @@ -57,6 +58,7 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase doc = Nokogiri::XML(@cache_definition.to_xml_string) errors = doc.errors - assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + + assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}") end end diff --git a/test/workbook/worksheet/tc_print_options.rb b/test/workbook/worksheet/tc_print_options.rb index 8dc2b804..40812b3e 100644 --- a/test/workbook/worksheet/tc_print_options.rb +++ b/test/workbook/worksheet/tc_print_options.rb @@ -8,63 +8,67 @@ class TestPrintOptions < Test::Unit::TestCase end def test_initialize - assert_equal(false, @po.grid_lines) - assert_equal(false, @po.headings) - assert_equal(false, @po.horizontal_centered) - assert_equal(false, @po.vertical_centered) + refute(@po.grid_lines) + refute(@po.headings) + refute(@po.horizontal_centered) + refute(@po.vertical_centered) end def test_initialize_with_options optioned = Axlsx::PrintOptions.new(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true) - assert_equal(true, optioned.grid_lines) - assert_equal(true, optioned.headings) - assert_equal(true, optioned.horizontal_centered) - assert_equal(true, optioned.vertical_centered) + + assert(optioned.grid_lines) + assert(optioned.headings) + assert(optioned.horizontal_centered) + assert(optioned.vertical_centered) end def test_set_all_values @po.set(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true) - assert_equal(true, @po.grid_lines) - assert_equal(true, @po.headings) - assert_equal(true, @po.horizontal_centered) - assert_equal(true, @po.vertical_centered) + + assert(@po.grid_lines) + assert(@po.headings) + assert(@po.horizontal_centered) + assert(@po.vertical_centered) end def test_set_some_values @po.set(:grid_lines => true, :headings => true) - assert_equal(true, @po.grid_lines) - assert_equal(true, @po.headings) - assert_equal(false, @po.horizontal_centered) - assert_equal(false, @po.vertical_centered) + + assert(@po.grid_lines) + assert(@po.headings) + refute(@po.horizontal_centered) + refute(@po.vertical_centered) end def test_to_xml @po.set(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true) doc = Nokogiri::XML.parse(@po.to_xml_string) + assert_equal(1, doc.xpath(".//printOptions[@gridLines=1][@headings=1][@horizontalCentered=1][@verticalCentered=1]").size) end def test_grid_lines assert_raise(ArgumentError) { @po.grid_lines = 99 } assert_nothing_raised { @po.grid_lines = true } - assert_equal(@po.grid_lines, true) + assert(@po.grid_lines) end def test_headings assert_raise(ArgumentError) { @po.headings = 99 } assert_nothing_raised { @po.headings = true } - assert_equal(@po.headings, true) + assert(@po.headings) end def test_horizontal_centered assert_raise(ArgumentError) { @po.horizontal_centered = 99 } assert_nothing_raised { @po.horizontal_centered = true } - assert_equal(@po.horizontal_centered, true) + assert(@po.horizontal_centered) end def test_vertical_centered assert_raise(ArgumentError) { @po.vertical_centered = 99 } assert_nothing_raised { @po.vertical_centered = true } - assert_equal(@po.vertical_centered, true) + assert(@po.vertical_centered) end end diff --git a/test/workbook/worksheet/tc_protected_range.rb b/test/workbook/worksheet/tc_protected_range.rb index 906c6014..db1ab93a 100644 --- a/test/workbook/worksheet/tc_protected_range.rb +++ b/test/workbook/worksheet/tc_protected_range.rb @@ -11,6 +11,7 @@ class TestProtectedRange < Test::Unit::TestCase def test_range r = @ws.protect_range('A1:B1') + assert_equal('A1:B1', r.sqref) end end diff --git a/test/workbook/worksheet/tc_rich_text.rb b/test/workbook/worksheet/tc_rich_text.rb index 6c9627d4..6ed8e5f0 100644 --- a/test/workbook/worksheet/tc_rich_text.rb +++ b/test/workbook/worksheet/tc_rich_text.rb @@ -19,19 +19,22 @@ class RichText < Test::Unit::TestCase rt_direct = Axlsx::RichText.new('hi', :i => true) rt_indirect = Axlsx::RichText.new rt_indirect.add_run('hi', :i => true) - assert_equal(rt_direct.runs.length, 1) - assert_equal(rt_indirect.runs.length, 1) + + assert_equal(1, rt_direct.runs.length) + assert_equal(1, rt_indirect.runs.length) row = @ws.add_row [rt_direct, rt_indirect] + assert_equal(row[0].to_xml_string(0, 0), row[1].to_xml_string(0, 0)) end def test_textruns runs = @rt.runs - assert_equal(runs.length, 27) - assert_equal(runs.first.b, false) - assert_equal(runs.first.i, true) - assert_equal(runs[1].b, true) - assert_equal(runs[1].i, false) + + assert_equal(27, runs.length) + refute(runs.first.b) + assert(runs.first.i) + assert(runs[1].b) + refute(runs[1].i) end def test_implicit_richtext @@ -39,6 +42,7 @@ class RichText < Test::Unit::TestCase row_rt = @ws.add_row [rt] row_imp = @ws.add_row ['a'] row_imp[0].b = true + assert_equal(row_rt[0].to_xml_string(0, 0), row_imp[0].to_xml_string(0, 0)) end end diff --git a/test/workbook/worksheet/tc_rich_text_run.rb b/test/workbook/worksheet/tc_rich_text_run.rb index d21329a9..61c462f0 100644 --- a/test/workbook/worksheet/tc_rich_text_run.rb +++ b/test/workbook/worksheet/tc_rich_text_run.rb @@ -15,21 +15,24 @@ class RichTextRun < Test::Unit::TestCase end def test_initialize - assert_equal(@rtr.value, 'hihihi') - assert_equal(@rtr.b, true) - assert_equal(@rtr.i, false) + assert_equal('hihihi', @rtr.value) + assert(@rtr.b) + refute(@rtr.i) end def test_font_size_with_custom_style_and_no_sz @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF' sz = @rtr.send(:font_size) + assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz * 1.5) sz = @rtr2.send(:font_size) + assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz) end def test_font_size_with_bolding @c.style = @c.row.worksheet.workbook.styles.add_style :b => true + assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr.send(:font_size)) assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr2.send(:font_size)) # is this the correct behaviour? end @@ -37,107 +40,111 @@ class RichTextRun < Test::Unit::TestCase def test_font_size_with_custom_sz @c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52 sz = @rtr.send(:font_size) - assert_equal(sz, 52 * 1.5) + + assert_equal(52 * 1.5, sz) sz2 = @rtr2.send(:font_size) - assert_equal(sz2, 52) + + assert_equal(52, sz2) end def test_rtr_with_sz @rtr.sz = 25 + assert_equal(25, @rtr.send(:font_size)) end def test_color assert_raise(ArgumentError) { @rtr.color = -1.1 } assert_nothing_raised { @rtr.color = "FF00FF00" } - assert_equal(@rtr.color.rgb, "FF00FF00") + assert_equal("FF00FF00", @rtr.color.rgb) end def test_scheme assert_raise(ArgumentError) { @rtr.scheme = -1.1 } assert_nothing_raised { @rtr.scheme = :major } - assert_equal(@rtr.scheme, :major) + assert_equal(:major, @rtr.scheme) end def test_vertAlign assert_raise(ArgumentError) { @rtr.vertAlign = -1.1 } assert_nothing_raised { @rtr.vertAlign = :baseline } - assert_equal(@rtr.vertAlign, :baseline) + assert_equal(:baseline, @rtr.vertAlign) end def test_sz assert_raise(ArgumentError) { @rtr.sz = -1.1 } assert_nothing_raised { @rtr.sz = 12 } - assert_equal(@rtr.sz, 12) + assert_equal(12, @rtr.sz) end def test_extend assert_raise(ArgumentError) { @rtr.extend = -1.1 } assert_nothing_raised { @rtr.extend = false } - assert_equal(@rtr.extend, false) + refute(@rtr.extend) end def test_condense assert_raise(ArgumentError) { @rtr.condense = -1.1 } assert_nothing_raised { @rtr.condense = false } - assert_equal(@rtr.condense, false) + refute(@rtr.condense) end def test_shadow assert_raise(ArgumentError) { @rtr.shadow = -1.1 } assert_nothing_raised { @rtr.shadow = false } - assert_equal(@rtr.shadow, false) + refute(@rtr.shadow) end def test_outline assert_raise(ArgumentError) { @rtr.outline = -1.1 } assert_nothing_raised { @rtr.outline = false } - assert_equal(@rtr.outline, false) + refute(@rtr.outline) end def test_strike assert_raise(ArgumentError) { @rtr.strike = -1.1 } assert_nothing_raised { @rtr.strike = false } - assert_equal(@rtr.strike, false) + refute(@rtr.strike) end def test_u @c.type = :string assert_raise(ArgumentError) { @c.u = -1.1 } assert_nothing_raised { @c.u = :single } - assert_equal(@c.u, :single) + assert_equal(:single, @c.u) doc = Nokogiri::XML(@c.to_xml_string(1, 1)) + assert(doc.xpath('//u[@val="single"]')) end def test_i assert_raise(ArgumentError) { @c.i = -1.1 } assert_nothing_raised { @c.i = false } - assert_equal(@c.i, false) + refute(@c.i) end def test_rFont assert_raise(ArgumentError) { @c.font_name = -1.1 } assert_nothing_raised { @c.font_name = "Arial" } - assert_equal(@c.font_name, "Arial") + assert_equal("Arial", @c.font_name) end def test_charset assert_raise(ArgumentError) { @c.charset = -1.1 } assert_nothing_raised { @c.charset = 1 } - assert_equal(@c.charset, 1) + assert_equal(1, @c.charset) end def test_family assert_raise(ArgumentError) { @rtr.family = 0 } assert_nothing_raised { @rtr.family = 1 } - assert_equal(@rtr.family, 1) + assert_equal(1, @rtr.family) end def test_b assert_raise(ArgumentError) { @c.b = -1.1 } assert_nothing_raised { @c.b = false } - assert_equal(@c.b, false) + refute(@c.b) end def test_multiline_autowidth @@ -148,8 +155,9 @@ class RichTextRun < Test::Unit::TestCase @ws.add_row [rt], :style => wrap ar = [0] awtr.autowidth(ar) + assert_equal(2, ar.length) - assert_equal(13.2, ar[0]) + assert_in_delta(13.2, ar[0]) assert_equal(0, ar[1]) end @@ -161,7 +169,8 @@ class RichTextRun < Test::Unit::TestCase puts error.message errors.push error end - assert(errors.empty?, "error free validation") + + assert_empty(errors, "error free validation") assert(doc.xpath('//rPr/b[@val=1]')) assert(doc.xpath('//rPr/i[@val=0]')) diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index cf8fa7c3..0d1c724d 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -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 diff --git a/test/workbook/worksheet/tc_selection.rb b/test/workbook/worksheet/tc_selection.rb index d600aa67..97419a64 100644 --- a/test/workbook/worksheet/tc_selection.rb +++ b/test/workbook/worksheet/tc_selection.rb @@ -9,25 +9,25 @@ class TestSelection < Test::Unit::TestCase def test_active_cell assert_raise(ArgumentError) { @selection.active_cell = :active_cell } assert_nothing_raised { @selection.active_cell = "F5" } - assert_equal(@selection.active_cell, "F5") + assert_equal("F5", @selection.active_cell) end def test_active_cell_id assert_raise(ArgumentError) { @selection.active_cell_id = "foo" } assert_nothing_raised { @selection.active_cell_id = 11 } - assert_equal(@selection.active_cell_id, 11) + assert_equal(11, @selection.active_cell_id) end def test_pane assert_raise(ArgumentError) { @selection.pane = "foo´" } assert_nothing_raised { @selection.pane = :bottom_right } - assert_equal(@selection.pane, "bottomRight") + assert_equal("bottomRight", @selection.pane) end def test_sqref assert_raise(ArgumentError) { @selection.sqref = :sqref } assert_nothing_raised { @selection.sqref = "G32" } - assert_equal(@selection.sqref, "G32") + assert_equal("G32", @selection.sqref) end def test_to_xml diff --git a/test/workbook/worksheet/tc_sheet_calc_pr.rb b/test/workbook/worksheet/tc_sheet_calc_pr.rb index 9473c94b..0d810378 100644 --- a/test/workbook/worksheet/tc_sheet_calc_pr.rb +++ b/test/workbook/worksheet/tc_sheet_calc_pr.rb @@ -6,12 +6,13 @@ class TestSheetCalcPr < Test::Unit::TestCase end def test_full_calc_on_load - assert_equal false, @sheet_calc_pr.full_calc_on_load + refute @sheet_calc_pr.full_calc_on_load assert Axlsx::SheetCalcPr.new.full_calc_on_load end def test_to_xml_string doc = Nokogiri::XML(@sheet_calc_pr.to_xml_string) + assert_equal 1, doc.xpath('//sheetCalcPr[@fullCalcOnLoad=0]').size end end diff --git a/test/workbook/worksheet/tc_sheet_format_pr.rb b/test/workbook/worksheet/tc_sheet_format_pr.rb index 1240da26..6a8141c4 100644 --- a/test/workbook/worksheet/tc_sheet_format_pr.rb +++ b/test/workbook/worksheet/tc_sheet_format_pr.rb @@ -18,6 +18,7 @@ class TestSheetFormatPr < Test::Unit::TestCase def test_default_initialization sheet_format_pr = Axlsx::SheetFormatPr.new + assert_equal 8, sheet_format_pr.base_col_width assert_equal 18, sheet_format_pr.default_row_height end @@ -75,6 +76,7 @@ class TestSheetFormatPr < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@sheet_format_pr.to_xml_string) + assert doc.xpath("sheetFormatPr[@thickBottom=1]") assert doc.xpath("sheetFormatPr[@baseColWidth=5]") assert doc.xpath("sheetFormatPr[@default_col_width=7.2]") diff --git a/test/workbook/worksheet/tc_sheet_pr.rb b/test/workbook/worksheet/tc_sheet_pr.rb index 70ce0428..819b265a 100644 --- a/test/workbook/worksheet/tc_sheet_pr.rb +++ b/test/workbook/worksheet/tc_sheet_pr.rb @@ -22,7 +22,8 @@ class TestSheetPr < Test::Unit::TestCase @options.each do |key, value| if key == :tab_color stored_value = @sheet_pr.send(key) - assert_equal Axlsx::Color, stored_value.class + + assert_instance_of Axlsx::Color, stored_value assert_equal value, stored_value.rgb else assert_equal value, @sheet_pr.send(key) @@ -32,16 +33,17 @@ class TestSheetPr < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@sheet_pr.to_xml_string) - assert_equal(doc.xpath("//sheetPr[@syncHorizontal='0']").size, 1) - assert_equal(doc.xpath("//sheetPr[@syncVertical='0']").size, 1) - assert_equal(doc.xpath("//sheetPr[@transitionEvaluation='1']").size, 1) - assert_equal(doc.xpath("//sheetPr[@transitionEntry='1']").size, 1) - assert_equal(doc.xpath("//sheetPr[@published='0']").size, 1) - assert_equal(doc.xpath("//sheetPr[@filterMode='1']").size, 1) - assert_equal(doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size, 1) - assert_equal(doc.xpath("//sheetPr[@codeName='007']").size, 1) - assert_equal(doc.xpath("//sheetPr[@syncRef='foo']").size, 1) - assert_equal(doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size, 1) - assert_equal(doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size, 1) + + assert_equal(1, doc.xpath("//sheetPr[@syncHorizontal='0']").size) + assert_equal(1, doc.xpath("//sheetPr[@syncVertical='0']").size) + assert_equal(1, doc.xpath("//sheetPr[@transitionEvaluation='1']").size) + assert_equal(1, doc.xpath("//sheetPr[@transitionEntry='1']").size) + assert_equal(1, doc.xpath("//sheetPr[@published='0']").size) + assert_equal(1, doc.xpath("//sheetPr[@filterMode='1']").size) + assert_equal(1, doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size) + assert_equal(1, doc.xpath("//sheetPr[@codeName='007']").size) + assert_equal(1, doc.xpath("//sheetPr[@syncRef='foo']").size) + assert_equal(1, doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size) + assert_equal(1, doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size) end end diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb index e8f18df5..08fe1cb9 100644 --- a/test/workbook/worksheet/tc_sheet_protection.rb +++ b/test/workbook/worksheet/tc_sheet_protection.rb @@ -54,6 +54,7 @@ class TestSheetProtection < Test::Unit::TestCase def test_to_xml_string @sp.password = 'fish' # -> CA3F doc = Nokogiri::XML(@sp.to_xml_string) + @options.each do |key, value| assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { $1.upcase }}='#{value}']")) end diff --git a/test/workbook/worksheet/tc_sheet_view.rb b/test/workbook/worksheet/tc_sheet_view.rb index 18bb3308..f53eb506 100644 --- a/test/workbook/worksheet/tc_sheet_view.rb +++ b/test/workbook/worksheet/tc_sheet_view.rb @@ -29,7 +29,7 @@ class TestSheetView < Test::Unit::TestCase end @nil_options.each do |key, value| - assert_equal(nil, sv.send(key.to_sym), "initialized default #{key} should be nil") + assert_nil(sv.send(key.to_sym), "initialized default #{key} should be nil") assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}") end @@ -75,115 +75,115 @@ class TestSheetView < Test::Unit::TestCase def test_color_id assert_raise(ArgumentError) { @sv.color_id = "10" } assert_nothing_raised { @sv.color_id = 2 } - assert_equal(@sv.color_id, 2) + assert_equal(2, @sv.color_id) end def test_default_grid_color assert_raise(ArgumentError) { @sv.default_grid_color = "foo" } assert_nothing_raised { @sv.default_grid_color = false } - assert_equal(@sv.default_grid_color, false) + refute(@sv.default_grid_color) end def test_right_to_left assert_raise(ArgumentError) { @sv.right_to_left = "foo´" } assert_nothing_raised { @sv.right_to_left = true } - assert_equal(@sv.right_to_left, true) + assert(@sv.right_to_left) end def test_show_formulas assert_raise(ArgumentError) { @sv.show_formulas = 'foo' } assert_nothing_raised { @sv.show_formulas = false } - assert_equal(@sv.show_formulas, false) + refute(@sv.show_formulas) end def test_show_grid_lines assert_raise(ArgumentError) { @sv.show_grid_lines = "foo" } assert_nothing_raised { @sv.show_grid_lines = false } - assert_equal(@sv.show_grid_lines, false) + refute(@sv.show_grid_lines) end def test_show_outline_symbols assert_raise(ArgumentError) { @sv.show_outline_symbols = 'foo' } assert_nothing_raised { @sv.show_outline_symbols = false } - assert_equal(@sv.show_outline_symbols, false) + refute(@sv.show_outline_symbols) end def test_show_row_col_headers assert_raise(ArgumentError) { @sv.show_row_col_headers = "foo" } assert_nothing_raised { @sv.show_row_col_headers = false } - assert_equal(@sv.show_row_col_headers, false) + refute(@sv.show_row_col_headers) end def test_show_ruler assert_raise(ArgumentError) { @sv.show_ruler = 'foo' } assert_nothing_raised { @sv.show_ruler = false } - assert_equal(@sv.show_ruler, false) + refute(@sv.show_ruler) end def test_show_white_space assert_raise(ArgumentError) { @sv.show_white_space = 'foo' } assert_nothing_raised { @sv.show_white_space = false } - assert_equal(@sv.show_white_space, false) + refute(@sv.show_white_space) end def test_show_zeros assert_raise(ArgumentError) { @sv.show_zeros = "foo" } assert_nothing_raised { @sv.show_zeros = false } - assert_equal(@sv.show_zeros, false) + refute(@sv.show_zeros) end def test_tab_selected assert_raise(ArgumentError) { @sv.tab_selected = "foo" } assert_nothing_raised { @sv.tab_selected = false } - assert_equal(@sv.tab_selected, false) + refute(@sv.tab_selected) end def test_top_left_cell assert_raise(ArgumentError) { @sv.top_left_cell = :cell_adress } assert_nothing_raised { @sv.top_left_cell = "A2" } - assert_equal(@sv.top_left_cell, "A2") + assert_equal("A2", @sv.top_left_cell) end def test_view assert_raise(ArgumentError) { @sv.view = 'view' } assert_nothing_raised { @sv.view = :page_break_preview } - assert_equal(@sv.view, :page_break_preview) + assert_equal(:page_break_preview, @sv.view) end def test_window_protection assert_raise(ArgumentError) { @sv.window_protection = "foo" } assert_nothing_raised { @sv.window_protection = false } - assert_equal(@sv.window_protection, false) + refute(@sv.window_protection) end def test_workbook_view_id assert_raise(ArgumentError) { @sv.workbook_view_id = "1" } assert_nothing_raised { @sv.workbook_view_id = 1 } - assert_equal(@sv.workbook_view_id, 1) + assert_equal(1, @sv.workbook_view_id) end def test_zoom_scale assert_raise(ArgumentError) { @sv.zoom_scale = "50" } assert_nothing_raised { @sv.zoom_scale = 50 } - assert_equal(@sv.zoom_scale, 50) + assert_equal(50, @sv.zoom_scale) end def test_zoom_scale_normal assert_raise(ArgumentError) { @sv.zoom_scale_normal = "50" } assert_nothing_raised { @sv.zoom_scale_normal = 50 } - assert_equal(@sv.zoom_scale_normal, 50) + assert_equal(50, @sv.zoom_scale_normal) end def test_zoom_scale_page_layout_view assert_raise(ArgumentError) { @sv.zoom_scale_page_layout_view = "50" } assert_nothing_raised { @sv.zoom_scale_page_layout_view = 50 } - assert_equal(@sv.zoom_scale_page_layout_view, 50) + assert_equal(50, @sv.zoom_scale_page_layout_view) end def test_zoom_scale_sheet_layout_view assert_raise(ArgumentError) { @sv.zoom_scale_sheet_layout_view = "50" } assert_nothing_raised { @sv.zoom_scale_sheet_layout_view = 50 } - assert_equal(@sv.zoom_scale_sheet_layout_view, 50) + assert_equal(50, @sv.zoom_scale_sheet_layout_view) end def test_to_xml @@ -206,6 +206,7 @@ class TestSheetView < Test::Unit::TestCase def test_add_selection @sv.add_selection(:top_left, :active_cell => "A1") + assert_equal('A1', @sv.selections[:top_left].active_cell) end end diff --git a/test/workbook/worksheet/tc_table.rb b/test/workbook/worksheet/tc_table.rb index 7a2e5987..0ea0166f 100644 --- a/test/workbook/worksheet/tc_table.rb +++ b/test/workbook/worksheet/tc_table.rb @@ -10,19 +10,21 @@ class TestTable < Test::Unit::TestCase end def test_initialization - assert(@ws.workbook.tables.empty?) - assert(@ws.tables.empty?) + assert_empty(@ws.workbook.tables) + assert_empty(@ws.tables) end def test_table_style_info table = @ws.add_table('A1:D5', :name => 'foo', :style_info => { :show_row_stripes => true, :name => "TableStyleMedium25" }) + assert_equal('TableStyleMedium25', table.table_style_info.name) - assert_equal(true, table.table_style_info.show_row_stripes) + assert(table.table_style_info.show_row_stripes) end def test_add_table name = "test" table = @ws.add_table("A1:D5", :name => name) + assert(table.is_a?(Axlsx::Table), "must create a table") assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection") assert_equal(@ws.tables.last, table, "must be added to worksheet table collection") @@ -31,25 +33,30 @@ class TestTable < Test::Unit::TestCase def test_pn @ws.add_table("A1:D5") - assert_equal(@ws.tables.first.pn, "tables/table1.xml") + + assert_equal("tables/table1.xml", @ws.tables.first.pn) end def test_rId table = @ws.add_table("A1:D5") + assert_equal @ws.relationships.for(table).Id, table.rId end def test_index @ws.add_table("A1:D5") + assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first)) end def test_relationships - assert(@ws.relationships.empty?) + assert_empty(@ws.relationships) @ws.add_table("A1:D5") - assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship") + + assert_equal(1, @ws.relationships.size, "adding a table adds a relationship") @ws.add_table("F1:J5") - assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship") + + assert_equal(2, @ws.relationships.size, "adding a table adds a relationship") end def test_to_xml_string @@ -61,7 +68,8 @@ class TestTable < Test::Unit::TestCase errors.push error puts error.message end - assert(errors.empty?, "error free validation") + + assert_empty(errors, "error free validation") end def test_to_xml_string_for_special_characters @@ -71,6 +79,7 @@ class TestTable < Test::Unit::TestCase table = @ws.add_table("A1:D5") doc = Nokogiri::XML(table.to_xml_string) errors = doc.errors - assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}") + + assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}") end end diff --git a/test/workbook/worksheet/tc_table_style_info.rb b/test/workbook/worksheet/tc_table_style_info.rb index f6606225..794073ef 100644 --- a/test/workbook/worksheet/tc_table_style_info.rb +++ b/test/workbook/worksheet/tc_table_style_info.rb @@ -17,6 +17,7 @@ class TestTableStyleInfo < Test::Unit::TestCase def test_initialize table_style = Axlsx::TableStyleInfo.new @options + @options.each do |key, value| assert_equal(value, table_style.send(key.to_sym)) end diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index fde0611d..103d1641 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -8,14 +8,16 @@ class TestWorksheet < Test::Unit::TestCase end def test_pn - assert_equal(@ws.pn, "worksheets/sheet1.xml") + assert_equal("worksheets/sheet1.xml", @ws.pn) ws = @ws.workbook.add_worksheet - assert_equal(ws.pn, "worksheets/sheet2.xml") + + assert_equal("worksheets/sheet2.xml", ws.pn) end def test_name_is_html_encoded @ws.name = '<foo> & <bar>' - assert_equal(@ws.name, '<foo> & <bar>') + + assert_equal('<foo> & <bar>', @ws.name) end def test_name_exception_on_invalid_character @@ -59,7 +61,7 @@ class TestWorksheet < Test::Unit::TestCase def test_page_margins_yeild @ws.page_margins do |pm| assert(pm.is_a?(Axlsx::PageMargins)) - assert(@ws.page_margins == pm) + assert_equal(@ws.page_margins, pm) end end @@ -70,7 +72,7 @@ class TestWorksheet < Test::Unit::TestCase def test_page_setup_yield @ws.page_setup do |ps| assert(ps.is_a?(Axlsx::PageSetup)) - assert(@ws.page_setup == ps) + assert_equal(@ws.page_setup, ps) end end @@ -81,7 +83,7 @@ class TestWorksheet < Test::Unit::TestCase def test_print_options_yield @ws.print_options do |po| assert(po.is_a?(Axlsx::PrintOptions)) - assert(@ws.print_options == po) + assert_equal(@ws.print_options, po) end end @@ -92,7 +94,7 @@ class TestWorksheet < Test::Unit::TestCase def test_header_footer_yield @ws.header_footer do |hf| assert(hf.is_a?(Axlsx::HeaderFooter)) - assert(@ws.header_footer == hf) + assert_equal(@ws.header_footer, hf) end end @@ -108,7 +110,8 @@ class TestWorksheet < Test::Unit::TestCase def test_no_autowidth @ws.workbook.use_autowidth = false @ws.add_row [1, 2, 3, 4] - assert_equal(@ws.column_info[0].width, nil) + + assert_nil(@ws.column_info[0].width) end def test_initialization_options @@ -117,6 +120,7 @@ class TestWorksheet < Test::Unit::TestCase print_options = { :grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true } header_footer = { :different_first => false, :different_odd_even => false, :odd_header => 'Header' } optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :page_setup => page_setup, :print_options => print_options, :header_footer => header_footer) + page_margins.each_key do |key| assert_equal(page_margins[key], optioned.page_margins.send(key)) end @@ -129,7 +133,7 @@ class TestWorksheet < Test::Unit::TestCase header_footer.each_key do |key| assert_equal(header_footer[key], optioned.header_footer.send(key)) end - assert_equal(optioned.name, 'bob') + assert_equal('bob', optioned.name) end # def test_use_gridlines @@ -145,9 +149,10 @@ class TestWorksheet < Test::Unit::TestCase # end def test_rels_pn - assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels") + assert_equal("worksheets/_rels/sheet1.xml.rels", @ws.rels_pn) ws = @ws.workbook.add_worksheet - assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels") + + assert_equal("worksheets/_rels/sheet2.xml.rels", ws.rels_pn) end def test_rId @@ -161,11 +166,13 @@ class TestWorksheet < Test::Unit::TestCase def test_dimension @ws.add_row [1, 2, 3] @ws.add_row [4, 5, 6] - assert_equal @ws.dimension.sqref, "A1:C2" + + assert_equal("A1:C2", @ws.dimension.sqref) end def test_dimension_with_empty_row @ws.add_row + assert_equal "A1:AA200", @ws.dimension.sqref end @@ -175,30 +182,34 @@ class TestWorksheet < Test::Unit::TestCase range = @ws["A1:C2"] first_row = @ws[0] last_row = @ws[1] + assert_equal(@ws.rows[0], first_row) assert_equal(@ws.rows[1], last_row) - assert_equal(range.size, 6) + assert_equal(6, range.size) assert_equal(range.first, @ws.rows.first.cells.first) assert_equal(range.last, @ws.rows.last.cells.last) end def test_add_row - assert(@ws.rows.empty?, "sheet has no rows by default") + assert_empty(@ws.rows, "sheet has no rows by default") r = @ws.add_row([1, 2, 3]) - assert_equal(@ws.rows.size, 1, "add_row adds a row") + + assert_equal(1, @ws.rows.size, "add_row adds a row") assert_equal(@ws.rows.first, r, "the row returned is the row added") end def test_add_chart - assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default") + assert_empty(@ws.workbook.charts, "the sheet's workbook should not have any charts by default") @ws.add_chart Axlsx::Pie3DChart - assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook") + + assert_equal(1, @ws.workbook.charts.size, "add_chart adds a chart to the workbook") end def test_add_page_break_with_string_cell_ref - assert(@ws.row_breaks.empty?) - assert(@ws.col_breaks.empty?) + assert_empty(@ws.row_breaks) + assert_empty(@ws.col_breaks) @ws.add_page_break("B1") + assert_equal(1, @ws.row_breaks.size) assert_equal(1, @ws.col_breaks.size) end @@ -207,23 +218,26 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [1, 2, 3, 4] @ws.add_row [1, 2, 3, 4] - assert(@ws.row_breaks.empty?) - assert(@ws.col_breaks.empty?) + assert_empty(@ws.row_breaks) + assert_empty(@ws.col_breaks) @ws.add_page_break(@ws.rows.last.cells[1]) + assert_equal(1, @ws.row_breaks.size) assert_equal(1, @ws.col_breaks.size) end def test_drawing - assert @ws.drawing.nil? + assert_nil @ws.drawing @ws.add_chart(Axlsx::Pie3DChart) + assert @ws.drawing.is_a?(Axlsx::Drawing) end def test_add_pivot_table - assert(@ws.workbook.pivot_tables.empty?, "the sheet's workbook should not have any pivot tables by default") + assert_empty(@ws.workbook.pivot_tables, "the sheet's workbook should not have any pivot tables by default") @ws.add_pivot_table 'G5:G6', 'A1:D:10' - assert_equal(@ws.workbook.pivot_tables.size, 1, "add_pivot_tables adds a pivot_table to the workbook") + + assert_equal(1, @ws.workbook.pivot_tables.size, "add_pivot_tables adds a pivot_table to the workbook") end def test_col_style @@ -233,11 +247,11 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [1, 2, 3, 4] @ws.col_style((1..2), 1, :row_offset => 1) @ws.rows[(1..-1)].each do |r| - assert_equal(r.cells[1].style, 1) - assert_equal(r.cells[2].style, 1) + assert_equal(1, r.cells[1].style) + assert_equal(1, r.cells[2].style) end - assert_equal(@ws.rows.first.cells[1].style, 0) - assert_equal(@ws.rows.first.cells[0].style, 0) + assert_equal(0, @ws.rows.first.cells[1].style) + assert_equal(0, @ws.rows.first.cells[0].style) end def test_col_style_with_empty_column @@ -253,14 +267,16 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [1, 2, 3] @ws.add_row [1, 2, 3, 4] c = @ws.cols[1] - assert_equal(c.size, 4) - assert_equal(c[0].value, 2) + + assert_equal(4, c.size) + assert_equal(2, c[0].value) end def test_cols_with_block @ws.add_row [1, 2, 3] @ws.add_row [1] cols = @ws.cols { |_row, _column| :foo } + assert_equal(:foo, cols[1][1]) end @@ -270,15 +286,16 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [1, 2, 3, 4] @ws.add_row [1, 2, 3, 4] @ws.row_style 1, 1, :col_offset => 1 + @ws.rows[1].cells[(1..-1)].each do |c| - assert_equal(c.style, 1) + assert_equal(1, c.style) end - assert_equal(@ws.rows[1].cells[0].style, 0) - assert_equal(@ws.rows[2].cells[1].style, 0) + assert_equal(0, @ws.rows[1].cells[0].style) + assert_equal(0, @ws.rows[2].cells[1].style) @ws.row_style(1..2, 1, :col_offset => 2) @ws.rows[(1..2)].each do |r| r.cells[(2..-1)].each do |c| - assert_equal(c.style, 1) + assert_equal(1, c.style) end end end @@ -292,7 +309,8 @@ class TestWorksheet < Test::Unit::TestCase def test_to_xml_string_dimensions @ws.add_row [1, 2, 3] doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size) end # def test_fit_to_page_assignation_does_nothing @@ -315,20 +333,23 @@ class TestWorksheet < Test::Unit::TestCase def test_to_xml_string_auto_fit_data @ws.add_row [1, "two"] doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size, 2) + + assert_equal(2, doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size) end def test_to_xml_string_sheet_data @ws.add_row [1, "two"] doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size) end def test_to_xml_string_auto_filter @ws.add_row [1, "two"] @ws.auto_filter.range = "A1:B1" doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size) end def test_to_xml_string_merge_cells @@ -336,26 +357,30 @@ class TestWorksheet < Test::Unit::TestCase @ws.merge_cells "A1:D1" @ws.merge_cells "E1:F1" doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size) + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size) end def test_to_xml_string_merge_cells_row row = @ws.add_row [1, "two"] @ws.merge_cells row doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size) end def test_to_xml_string_row_breaks @ws.add_page_break("A1") doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:rowBreaks/xmlns:brk[@id="0"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:rowBreaks/xmlns:brk[@id="0"]').size) end def test_to_xml_string_sheet_protection @ws.sheet_protection.password = 'fish' doc = Nokogiri::XML(@ws.to_xml_string) + assert(doc.xpath('//xmlns:sheetProtection')) end @@ -365,7 +390,8 @@ class TestWorksheet < Test::Unit::TestCase pm.right = 7 end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size) end def test_to_xml_string_page_setup @@ -374,7 +400,8 @@ class TestWorksheet < Test::Unit::TestCase ps.scale = 80 end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageSetup[@paperWidth="210mm"][@scale="80"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:pageSetup[@paperWidth="210mm"][@scale="80"]').size) end def test_to_xml_string_print_options @@ -383,7 +410,8 @@ class TestWorksheet < Test::Unit::TestCase po.horizontal_centered = true end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines=1][@horizontalCentered=1]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines=1][@horizontalCentered=1]').size) end def test_to_xml_string_header_footer @@ -393,12 +421,14 @@ class TestWorksheet < Test::Unit::TestCase hf.odd_header = 'Test Header' end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst=0][@differentOddEven=0]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst=0][@differentOddEven=0]').size) end def test_to_xml_string_drawing @ws.add_chart Axlsx::Pie3DChart doc = Nokogiri::XML(@ws.to_xml_string) + assert_equal @ws.send(:worksheet_drawing).relationship.Id, doc.xpath('//xmlns:worksheet/xmlns:drawing').first["r:id"] end @@ -407,14 +437,16 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [1, 2] table = @ws.add_table "A1:B2" doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size) assert_equal table.rId, doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart').first["r:id"] end def test_to_xml_string schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) - assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, "error free validation") + + assert_empty(schema.validate(doc).map { |e| puts e.message; e }, "error free validation") end def test_styles @@ -426,14 +458,16 @@ class TestWorksheet < Test::Unit::TestCase Axlsx::trust_input = false nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f" @ws.add_row [nasties] + assert_equal(0, @ws.rows.last.cells.last.value.index("\v")) - assert_equal(nil, @ws.to_xml_string.index("\v")) + assert_nil(@ws.to_xml_string.index("\v")) Axlsx::trust_input = old end def test_to_xml_string_with_newlines cell_with_newline = "foo\n\r\nbar" @ws.add_row [cell_with_newline] + assert_equal("foo\n\r\nbar", @ws.rows.last.cells.last.value) assert_not_nil(@ws.to_xml_string.index("foo\n\r\nbar")) end @@ -451,40 +485,50 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_pivot_table 'G5:G6', 'A1:D10' schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) - assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, schema.validate(doc).map(&:message).join('\n')) + + assert_empty(schema.validate(doc).map { |e| puts e.message; e }, schema.validate(doc).map(&:message).join('\n')) end def test_relationships @ws.add_row [1, 2, 3] - assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart") + + assert_empty(@ws.relationships, "No Drawing relationship until you add a chart") @ws.add_chart Axlsx::Pie3DChart - assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship") + + assert_equal(1, @ws.relationships.size, "adding a chart creates the relationship") @ws.add_chart Axlsx::Pie3DChart - assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship") + + assert_equal(1, @ws.relationships.size, "multiple charts still only result in one relationship") @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last - assert_equal(@ws.relationships.size, 3, "adding a comment adds 2 relationships") + + assert_equal(3, @ws.relationships.size, "adding a comment adds 2 relationships") @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1" - assert_equal(@ws.relationships.size, 3, "adding multiple comments in the same worksheet should not add any additional comment relationships") + + assert_equal(3, @ws.relationships.size, "adding multiple comments in the same worksheet should not add any additional comment relationships") @ws.add_pivot_table 'G5:G6', 'A1:D10' - assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship") + + assert_equal(4, @ws.relationships.size, "adding a pivot table adds 1 relationship") end def test_set_fixed_width_column @ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil] - assert(@ws.column_info.size == 3, "a data item for each column") + + assert_equal(3, @ws.column_info.size, "a data item for each column") assert_equal(20, @ws.column_info[0].width, "adding a row with fixed width updates :fixed attribute") - assert_equal(@ws.column_info[1].width, nil, ":ignore does not set any data") + assert_nil(@ws.column_info[1].width, ":ignore does not set any data") end def test_fixed_height @ws.add_row [1, 2, 3], :height => 40 + assert_equal(40, @ws.rows[-1].height) end def test_set_column_width @ws.add_row ["chasing windmills", "penut"] @ws.column_widths nil, 0.5 - assert_equal(@ws.column_info[1].width, 0.5, 'eat my width') + + assert_in_delta(@ws.column_info[1].width, 0.5, 0.001, 'eat my width') assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 } assert_raise(ArgumentError, 'only accept Integer or Float') { @ws.column_widths 2, 7, "-1" } end @@ -524,6 +568,7 @@ class TestWorksheet < Test::Unit::TestCase assert(@ws.send(:protected_ranges).is_a?(Axlsx::SimpleTypedList)) assert_equal(0, @ws.send(:protected_ranges).size) @ws.protect_range('A1:A3') + assert_equal('A1:A3', @ws.send(:protected_ranges).last.sqref) end @@ -540,8 +585,9 @@ class TestWorksheet < Test::Unit::TestCase @ws.merge_cells "A1:A2" @ws.merge_cells "B2:C3" @ws.merge_cells @ws.rows.last.cells[(0..1)] - assert_equal(@ws.send(:merged_cells).size, 3) - assert_equal(@ws.send(:merged_cells).last, "A3:B3") + + assert_equal(3, @ws.send(:merged_cells).size) + assert_equal("A3:B3", @ws.send(:merged_cells).last) end def test_merge_cells_sorts_correctly_by_row_when_given_array @@ -549,37 +595,43 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row [i] end @ws.merge_cells [@ws.rows[8].cells.first, @ws.rows[9].cells.first] + assert_equal "A9:A10", @ws.send(:merged_cells).first end def test_auto_filter - assert(@ws.auto_filter.range.nil?) + assert_nil(@ws.auto_filter.range) assert(@wb.defined_names.none? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }) assert_raise(ArgumentError) { @ws.auto_filter = 123 } @ws.auto_filter.range = "A1:D9" - assert_equal(@ws.auto_filter.range, "A1:D9") + + assert_equal("A1:D9", @ws.auto_filter.range) @ws.to_xml_string + assert(@wb.defined_names.any? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }) end def test_auto_filter_assign other_ws = @wb.add_worksheet - assert(@ws.auto_filter.range.nil?) - assert(other_ws.auto_filter.range.nil?) + assert_nil(@ws.auto_filter.range) + assert_nil(other_ws.auto_filter.range) assert(@wb.defined_names.none? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }) assert_raise(ArgumentError) { @ws.auto_filter = 123 } @ws.auto_filter = "A1:D9" - assert_equal(@ws.auto_filter.range, "A1:D9") + + assert_equal("A1:D9", @ws.auto_filter.range) other_ws.auto_filter = "A1:D2" - assert_equal(other_ws.auto_filter.range, "A1:D2") + + assert_equal("A1:D2", other_ws.auto_filter.range) @ws.to_xml_string other_ws.to_xml_string filter_database = @wb.defined_names.select { |defined_name| defined_name.name == '_xlnm._FilterDatabase' } + assert_equal(2, filter_database.size) assert_equal(@ws.index, filter_database[0].local_sheet_id) assert_equal(other_ws.index, filter_database[1].local_sheet_id) @@ -589,23 +641,26 @@ class TestWorksheet < Test::Unit::TestCase @ws.auto_filter.range = 'A1:D9' @ws.auto_filter.add_column 0, :filters, :filter_items => [1] doc = Nokogiri::XML(@ws.to_xml_string) + assert(doc.xpath('//sheetPr[@filterMode=1]')) end def test_outline_level_rows 3.times { @ws.add_row [1, 2, 3] } @ws.outline_level_rows 0, 2 + assert_equal(1, @ws.rows[0].outline_level) - assert_equal(true, @ws.rows[2].hidden) - assert_equal(true, @ws.sheet_view.show_outline_symbols) + assert(@ws.rows[2].hidden) + assert(@ws.sheet_view.show_outline_symbols) end def test_outline_level_columns 3.times { @ws.add_row [1, 2, 3] } @ws.outline_level_columns 0, 2 + assert_equal(1, @ws.column_info[0].outline_level) - assert_equal(true, @ws.column_info[2].hidden) - assert_equal(true, @ws.sheet_view.show_outline_symbols) + assert(@ws.column_info[2].hidden) + assert(@ws.sheet_view.show_outline_symbols) end def test_worksheet_does_not_get_added_to_workbook_on_initialize_failure @@ -616,13 +671,15 @@ class TestWorksheet < Test::Unit::TestCase def test_worksheet_only_includes_outline_pr_when_set doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 0) + + assert_equal(0, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size) @ws.sheet_pr.outline_pr.summary_below = false @ws.sheet_pr.outline_pr.summary_right = true doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 1) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr[@summaryBelow=0][@summaryRight=1]').size, 1) + + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size) + assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr[@summaryBelow=0][@summaryRight=1]').size) end def test_merge_styles_1 @@ -706,7 +763,7 @@ class TestWorksheet < Test::Unit::TestCase wb.apply_styles - assert_equal true, wb.styles_applied + assert wb.styles_applied assert_equal 12, wb.styles.style_index.count assert_equal 12 + 2, wb.styles.style_index.keys.max end @@ -731,7 +788,7 @@ class TestWorksheet < Test::Unit::TestCase wb.apply_styles - assert_equal true, wb.styles_applied + assert wb.styles_applied assert_equal 17, wb.styles.style_index.count end @@ -751,7 +808,7 @@ class TestWorksheet < Test::Unit::TestCase wb.apply_styles - assert_equal true, wb.styles_applied + assert wb.styles_applied assert_equal 8, wb.styles.style_index.count assert_equal 8, wb.styled_cells.count end @@ -771,7 +828,7 @@ class TestWorksheet < Test::Unit::TestCase wb.apply_styles - assert_equal true, wb.styles_applied + assert wb.styles_applied assert_equal 6, wb.styles.style_index.count assert_equal 6, wb.styled_cells.count @@ -786,6 +843,7 @@ class TestWorksheet < Test::Unit::TestCase sz: 11, family: 1 } + assert_equal b2_cell_style, (wb.styles.style_index.values.find { |x| x == b2_cell_style }) d3_cell_style = { @@ -799,6 +857,7 @@ class TestWorksheet < Test::Unit::TestCase sz: 11, family: 1 } + assert_equal d3_cell_style, (wb.styles.style_index.values.find { |x| x == d3_cell_style }) end @@ -895,6 +954,7 @@ class TestWorksheet < Test::Unit::TestCase def test_escape_formulas @wb.escape_formulas = false @ws = @wb.add_worksheet + assert_false @ws.escape_formulas assert_false @ws.add_row(['']).cells.first.escape_formulas assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas @@ -902,10 +962,12 @@ class TestWorksheet < Test::Unit::TestCase assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas) @ws = Axlsx::Worksheet.new(@wb) + assert_false @ws.escape_formulas @wb.escape_formulas = true @ws = @wb.add_worksheet + assert @ws.escape_formulas assert @ws.add_row(['']).cells.first.escape_formulas assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas @@ -913,9 +975,11 @@ class TestWorksheet < Test::Unit::TestCase assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas) @ws = Axlsx::Worksheet.new(@wb) + assert @ws.escape_formulas @ws.escape_formulas = false + assert_false @ws.escape_formulas assert_false @ws.add_row(['']).cells.first.escape_formulas assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas @@ -923,6 +987,7 @@ class TestWorksheet < Test::Unit::TestCase assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas) @ws.escape_formulas = true + assert @ws.escape_formulas assert @ws.add_row(['']).cells.first.escape_formulas assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas diff --git a/test/workbook/worksheet/tc_worksheet_hyperlink.rb b/test/workbook/worksheet/tc_worksheet_hyperlink.rb index 98b6937b..29e302a0 100644 --- a/test/workbook/worksheet/tc_worksheet_hyperlink.rb +++ b/test/workbook/worksheet/tc_worksheet_hyperlink.rb @@ -35,20 +35,22 @@ class TestWorksheetHyperlink < Test::Unit::TestCase def test_to_xml_string_with_non_external doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@r:id]").size, 0) + + assert_equal(1, doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size) + assert_equal(0, doc.xpath("//xmlns:hyperlink[@r:id]").size) end def test_to_xml_stirng_with_external @a.target = :external doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1) - assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 0) - assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size, 1) + + assert_equal(1, doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size) + assert_equal(0, doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size) + assert_equal(1, doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size) end end |
