diff options
Diffstat (limited to 'test')
112 files changed, 816 insertions, 1046 deletions
diff --git a/test/benchmark.rb b/test/benchmark.rb index 8d90cdf5..3c0ebc95 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -6,10 +6,9 @@ require 'benchmark' Axlsx::trust_input = true row = [] input = (32..126).to_a.pack('U*').chars.to_a -20.times { row << input.shuffle.join} +20.times { row << input.shuffle.join } times = 3000 Benchmark.bmbm(30) do |x| - x.report('axlsx_noautowidth') { p = Axlsx::Package.new p.workbook do |wb| diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb index e0dd0a5e..c79352ff 100644 --- a/test/content_type/tc_content_type.rb +++ b/test/content_type/tc_content_type.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 require 'tc_helper.rb' class TestContentType < Test::Unit::TestCase @@ -9,24 +8,23 @@ class TestContentType < Test::Unit::TestCase def test_valid_document schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD)) - assert(schema.validate(@doc).map{ |e| puts e.message; e.message }.empty?) + assert(schema.validate(@doc).map { |e| puts e.message; e.message }.empty?) end def test_pre_built_types - o_path = "//xmlns:Override[@ContentType='%s']" d_path = "//xmlns:Default[@ContentType='%s']" - #default + # default assert_equal(@doc.xpath("//xmlns:Default").size, 2, "There should be 2 default types") node = @doc.xpath(d_path % Axlsx::XML_CT).first assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid") node = @doc.xpath(d_path % Axlsx::RELS_CT).first - assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid") + assert_equal(node["Extension"], "#{Axlsx::RELS_EX}", "relationships content type invalid") - #overrride + # overrride assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types") node = @doc.xpath(o_path % Axlsx::APP_CT).first @@ -54,7 +52,6 @@ class TestContentType < Test::Unit::TestCase doc = Nokogiri::XML(@package.send(:content_types).to_xml_string) assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type") assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid") - end def test_drawings_and_charts_need_content_types @@ -72,5 +69,4 @@ class TestContentType < Test::Unit::TestCase assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}") assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid") end - end diff --git a/test/content_type/tc_default.rb b/test/content_type/tc_default.rb index d765a904..096a117a 100644 --- a/test/content_type/tc_default.rb +++ b/test/content_type/tc_default.rb @@ -1,14 +1,12 @@ -# encoding: UTF-8 require 'tc_helper.rb' class TestDefault < Test::Unit::TestCase - def test_content_type_restriction - assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" } + assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType => "asdf" } end def test_to_xml_string - type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT + type = Axlsx::Default.new :Extension => "xml", :ContentType => Axlsx::XML_CT doc = Nokogiri::XML(type.to_xml_string) assert_equal(doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size, 1) assert_equal(doc.xpath("Default[@Extension='xml']").size, 1) diff --git a/test/content_type/tc_override.rb b/test/content_type/tc_override.rb index d9bec90c..952f40d8 100644 --- a/test/content_type/tc_override.rb +++ b/test/content_type/tc_override.rb @@ -1,12 +1,11 @@ require 'tc_helper.rb' class TestOverride < Test::Unit::TestCase - def test_content_type_restriction - assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" } + assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType => "asdf" } end def test_to_xml - type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT + type = Axlsx::Override.new :PartName => "somechart.xml", :ContentType => Axlsx::CHART_CT doc = Nokogiri::XML(type.to_xml_string) assert_equal(doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size, 1) assert_equal(doc.xpath("Override[@PartName='somechart.xml']").size, 1) diff --git a/test/doc_props/tc_app.rb b/test/doc_props/tc_app.rb index ec862c37..a7124be1 100644 --- a/test/doc_props/tc_app.rb +++ b/test/doc_props/tc_app.rb @@ -22,15 +22,15 @@ class TestApp < Test::Unit::TestCase :'CharactersWithSpaces' => 9, :'SharedDoc' => false, :'HyperlinkBase' => 'foo', - :'HyperlInksChanged' => false, + :'HyperlInksChanged' => false, :'Application' => 'axlsx', :'AppVersion' => '1.1.5', :'DocSecurity' => 0 - } + } @app = Axlsx::App.new options - end + def test_valid_document schema = Nokogiri::XML::Schema(File.open(Axlsx::APP_XSD)) doc = Nokogiri::XML(@app.to_xml_string) @@ -38,6 +38,6 @@ class TestApp < Test::Unit::TestCase schema.validate(doc).each do |error| errors << error end - assert_equal(errors.size, 0, "app.xml invalid" + errors.map{ |e| e.message }.to_s) + assert_equal(errors.size, 0, "app.xml invalid" + errors.map { |e| e.message }.to_s) end end diff --git a/test/doc_props/tc_core.rb b/test/doc_props/tc_core.rb index 0eddfed7..b225266a 100644 --- a/test/doc_props/tc_core.rb +++ b/test/doc_props/tc_core.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestCore < Test::Unit::TestCase - def setup @core = Axlsx::Core.new # could still see some false positives if the second changes between the next two calls @@ -16,7 +15,7 @@ class TestCore < Test::Unit::TestCase puts error.message errors << error end - assert_equal(errors.size, 0, "core.xml Invalid" + errors.map{ |e| e.message }.to_s) + assert_equal(errors.size, 0, "core.xml Invalid" + errors.map { |e| e.message }.to_s) end def test_populates_created diff --git a/test/drawing/tc_area_chart.rb b/test/drawing/tc_area_chart.rb index b3013c12..fc928db9 100644 --- a/test/drawing/tc_area_chart.rb +++ b/test/drawing/tc_area_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestAreaChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -35,5 +34,4 @@ class TestAreaChart < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_area_series.rb b/test/drawing/tc_area_series.rb index 00229a39..250c6e13 100644 --- a/test/drawing/tc_area_series.rb +++ b/test/drawing/tc_area_series.rb @@ -1,13 +1,12 @@ require 'tc_helper.rb' class TestAreaSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" chart = @ws.add_chart Axlsx::AreaChart, :title => "fishery" @series = chart.add_series( - :data => [0,1,2], + :data => [0, 1, 2], :labels => ["zero", "one", "two"], :title => "bob", :color => "#FF0000", diff --git a/test/drawing/tc_axes.rb b/test/drawing/tc_axes.rb index e3c26936..eabf9a8d 100644 --- a/test/drawing/tc_axes.rb +++ b/test/drawing/tc_axes.rb @@ -5,4 +5,4 @@ class TestAxes < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx::Axes.new(:val_axis => Axlsx::ValAxis, :cat_axis => Axlsx::CatAxis) } assert_nothing_raised { Axlsx::Axes.new(:cat_axis => Axlsx::CatAxis, :val_axis => Axlsx::ValAxis) } end -end
\ No newline at end of file +end diff --git a/test/drawing/tc_axis.rb b/test/drawing/tc_axis.rb index 5a9fa5a3..0f7108eb 100644 --- a/test/drawing/tc_axis.rb +++ b/test/drawing/tc_axis.rb @@ -5,7 +5,6 @@ class TestAxis < Test::Unit::TestCase @axis = Axlsx::Axis.new :gridlines => false, :title => 'Foo' end - def test_initialization assert_equal(@axis.ax_pos, :b, "axis position default incorrect") assert_equal(@axis.tick_lbl_pos, :nextTo, "tick label position default incorrect") @@ -18,15 +17,15 @@ class TestAxis < Test::Unit::TestCase def test_color @axis.color = "00FF00" @axis.cross_axis = Axlsx::CatAxis.new - str = '<?xml version="1.0" encoding="UTF-8"?>' + str = '<?xml version="1.0" encoding="UTF-8"?>' str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">' - doc = Nokogiri::XML(@axis.to_xml_string(str)) + doc = Nokogiri::XML(@axis.to_xml_string(str)) assert(doc.xpath("//a:srgbClr[@val='00FF00']")) end def test_cell_based_axis_title p = Axlsx::Package.new - p.workbook.add_worksheet(:name=>'foosheet') do |sheet| + p.workbook.add_worksheet(:name => 'foosheet') do |sheet| sheet.add_row ['battle victories'] sheet.add_row ['bird', 1, 2, 1] sheet.add_row ['cat', 7, 9, 10] @@ -58,14 +57,14 @@ class TestAxis < Test::Unit::TestCase def test_format_code assert_raise(ArgumentError, "requires valid format code") { @axis.format_code = :high } - assert_nothing_raised("accepts valid format code") { @axis.format_code = "00.##" } + assert_nothing_raised("accepts valid format code") { @axis.format_code = "00.##" } end - def create_chart_with_formatting(format_string=nil) + def create_chart_with_formatting(format_string = nil) p = Axlsx::Package.new p.workbook.add_worksheet(:name => "Formatting Test") do |sheet| sheet.add_row(['test', 20]) - sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "Test Formatting") do |chart| + sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0, 5], :end_at => [10, 20], :title => "Test Formatting") do |chart| chart.add_series :data => sheet["B1:B1"], :labels => sheet["A1:A1"] chart.val_axis.format_code = format_string if format_string doc = Nokogiri::XML(chart.to_xml_string) @@ -97,12 +96,12 @@ class TestAxis < Test::Unit::TestCase assert_raise(ArgumentError, "requires valid gridlines") { @axis.gridlines = 'alice' } assert_nothing_raised("accepts valid crosses") { @axis.gridlines = false } end - + def test_to_xml_string @axis.cross_axis = Axlsx::CatAxis.new - str = '<?xml version="1.0" encoding="UTF-8"?>' + str = '<?xml version="1.0" encoding="UTF-8"?>' str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">' - doc = Nokogiri::XML(@axis.to_xml_string(str)) + doc = Nokogiri::XML(@axis.to_xml_string(str)) assert(doc.xpath('//a:noFill')) assert(doc.xpath("//c:crosses[@val='#{@axis.crosses.to_s}']")) assert(doc.xpath("//c:crossAx[@val='#{@axis.cross_axis.to_s}']")) diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb index b7a1eca4..3c22e191 100644 --- a/test/drawing/tc_bar_3D_chart.rb +++ b/test/drawing/tc_bar_3D_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestBar3DChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -26,11 +25,11 @@ class TestBar3DChart < Test::Unit::TestCase assert(@chart.bar_dir == :col) end - def test_grouping - assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } - assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard } - assert(@chart.grouping == :standard) - end + def test_grouping + assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } + assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard } + assert(@chart.grouping == :standard) + end def test_gap_width assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = -1 } diff --git a/test/drawing/tc_bar_chart.rb b/test/drawing/tc_bar_chart.rb index c8bdc8d0..5106d266 100644 --- a/test/drawing/tc_bar_chart.rb +++ b/test/drawing/tc_bar_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestBarChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -26,11 +25,11 @@ class TestBarChart < Test::Unit::TestCase assert(@chart.bar_dir == :col) end - def test_grouping - assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } - assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard } - assert(@chart.grouping == :standard) - end + def test_grouping + assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } + assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard } + assert(@chart.grouping == :standard) + end def test_gap_width assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = -1 } diff --git a/test/drawing/tc_bar_series.rb b/test/drawing/tc_bar_series.rb index f076fae0..39d39b96 100644 --- a/test/drawing/tc_bar_series.rb +++ b/test/drawing/tc_bar_series.rb @@ -1,10 +1,9 @@ require 'tc_helper.rb' class TestBarSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" @chart = @ws.add_chart Axlsx::Bar3DChart, :title => "fishery" @series = @chart.add_series( data: [0, 1, 2], @@ -38,8 +37,8 @@ class TestBarSeries < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@chart.to_xml_string) @series.colors.each_with_index do |color, index| - assert_equal(doc.xpath("//c:dPt/c:idx[@val='#{index}']").size,1) - assert_equal(doc.xpath("//c:dPt/c:spPr/a:solidFill/a:srgbClr[@val='#{@series.colors[index]}']").size,1) + assert_equal(doc.xpath("//c:dPt/c:idx[@val='#{index}']").size, 1) + assert_equal(doc.xpath("//c:dPt/c:spPr/a:solidFill/a:srgbClr[@val='#{@series.colors[index]}']").size, 1) end assert_equal(doc.xpath('//c:spPr[not(ancestor::c:dPt)]/a:solidFill/a:srgbClr').first.get_attribute('val'), '5A5A5A', 'series color has been applied') end diff --git a/test/drawing/tc_bubble_chart.rb b/test/drawing/tc_bubble_chart.rb index 7adad218..02745f92 100644 --- a/test/drawing/tc_bubble_chart.rb +++ b/test/drawing/tc_bubble_chart.rb @@ -5,10 +5,10 @@ class TestBubbleChart < Test::Unit::TestCase @p = Axlsx::Package.new @chart = nil @p.workbook.add_worksheet do |sheet| - sheet.add_row ["First", 1, 5, 7, 9] + sheet.add_row ["First", 1, 5, 7, 9] sheet.add_row ["", 1, 25, 49, 81] sheet.add_row ["", 1, 42, 60, 75] - sheet.add_row ["Second", 5, 2, 14, 9] + sheet.add_row ["Second", 5, 2, 14, 9] sheet.add_row ["", 5, 10, 15, 20] sheet.add_row ["", 5, 28, 92, 13] sheet.add_chart(Axlsx::BubbleChart, :title => "example: Bubble Chart") do |chart| @@ -40,5 +40,4 @@ class TestBubbleChart < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_bubble_series.rb b/test/drawing/tc_bubble_series.rb index e601912f..af051d11 100644 --- a/test/drawing/tc_bubble_series.rb +++ b/test/drawing/tc_bubble_series.rb @@ -1,12 +1,11 @@ require 'tc_helper.rb' class TestBubbleSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" @chart = @ws.add_chart Axlsx::BubbleChart, :title => "Bubble Chart" - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :bubbleSize=>[1,5,7], :title=>"GDP", :color => 'FF0000' + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :bubbleSize => [1, 5, 7], :title => "GDP", :color => 'FF0000' end def test_initialize @@ -15,7 +14,6 @@ class TestBubbleSeries < Test::Unit::TestCase def test_to_xml_string doc = Nokogiri::XML(@chart.to_xml_string) - assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,2) + assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size, 2) end - end diff --git a/test/drawing/tc_cat_axis.rb b/test/drawing/tc_cat_axis.rb index ac690336..79c0f8db 100644 --- a/test/drawing/tc_cat_axis.rb +++ b/test/drawing/tc_cat_axis.rb @@ -4,6 +4,7 @@ class TestCatAxis < Test::Unit::TestCase def setup @axis = Axlsx::CatAxis.new end + def teardown end @@ -27,5 +28,4 @@ class TestCatAxis < Test::Unit::TestCase assert_raise(ArgumentError, "requires valid label offset") { @axis.lbl_offset = 'foo' } assert_nothing_raised("accepts valid label offset") { @axis.lbl_offset = "20" } end - end diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb index 65d7877c..4f60db17 100644 --- a/test/drawing/tc_chart.rb +++ b/test/drawing/tc_chart.rb @@ -3,7 +3,6 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../" require 'tc_helper.rb' class TestChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -15,7 +14,7 @@ class TestChart < Test::Unit::TestCase end def test_initialization - assert_equal(@p.workbook.charts.last,@chart, "the chart is in the workbook") + assert_equal(@p.workbook.charts.last, @chart, "the chart is in the workbook") assert_equal(@chart.title.text, "fishery", "the title option has been applied") assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty") end @@ -46,7 +45,6 @@ class TestChart < Test::Unit::TestCase assert_raise(ArgumentError) { @chart.bg_color = 2 } assert_nothing_raised { @chart.bg_color = "FFFFFF" } assert_equal(@chart.bg_color, "FFFFFF") - end def test_title_size @@ -77,10 +75,9 @@ class TestChart < Test::Unit::TestCase @chart.start_at @row.cells.first assert_equal(@chart.graphic_frame.anchor.from.col, 0) assert_equal(@chart.graphic_frame.anchor.from.row, 0) - @chart.start_at [5,6] + @chart.start_at [5, 6] assert_equal(@chart.graphic_frame.anchor.from.col, 5) assert_equal(@chart.graphic_frame.anchor.from.row, 6) - end def test_end_at @@ -90,14 +87,13 @@ class TestChart < Test::Unit::TestCase @chart.end_at @row.cells.last assert_equal(@chart.graphic_frame.anchor.to.col, 2) assert_equal(@chart.graphic_frame.anchor.to.row, 0) - @chart.end_at [10,11] + @chart.end_at [10, 11] assert_equal(@chart.graphic_frame.anchor.to.col, 10) assert_equal(@chart.graphic_frame.anchor.to.row, 11) - end def test_add_series - s = @chart.add_series :data=>[0,1,2,3], :labels => ["one", 1, "anything"], :title=>"bob" + s = @chart.add_series :data => [0, 1, 2, 3], :labels => ["one", 1, "anything"], :title => "bob" assert_equal(@chart.series.last, s, "series has been added to chart series collection") assert_equal(s.title.text, "bob", "series title has been applied") end @@ -107,7 +103,6 @@ class TestChart < Test::Unit::TestCase end def test_d_lbls - assert_equal(nil, Axlsx.instance_values_for(@chart)[:d_lbls]) @chart.d_lbls.d_lbl_pos = :t assert(@chart.d_lbls.is_a?(Axlsx::DLbls), 'DLbls instantiated on access') diff --git a/test/drawing/tc_d_lbls.rb b/test/drawing/tc_d_lbls.rb index dddde3a1..a8647f9c 100644 --- a/test/drawing/tc_d_lbls.rb +++ b/test/drawing/tc_d_lbls.rb @@ -1,16 +1,15 @@ require 'tc_helper' class TestDLbls < Test::Unit::TestCase - def setup @d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart) - @boolean_attributes =[:show_legend_key, - :show_val, - :show_cat_name, - :show_ser_name, - :show_percent, - :show_bubble_size, - :show_leader_lines] + @boolean_attributes = [:show_legend_key, + :show_val, + :show_cat_name, + :show_ser_name, + :show_percent, + :show_bubble_size, + :show_leader_lines] end def test_initialization @@ -21,16 +20,16 @@ class TestDLbls < Test::Unit::TestCase end def test_initialization_with_optoins - - options_hash = Hash[*[@boolean_attributes.map { |name| [name, true] }] ] + options_hash = Hash[*[@boolean_attributes.map { |name| [name, true] }]] + + d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart, options_hash.merge({ :d_lbl_pos => :t })) - d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart, options_hash.merge( { :d_lbl_pos => :t })) - @boolean_attributes.each do |attr| assert_equal(true, d_lbls.send(attr), "boolean attributes set by options") end assert_equal(:t, d_lbls.d_lbl_pos, "d_lbl_pos set by options") end + def test_d_lbl_pos assert_raise(ArgumentError, 'invlaid label positions are rejected') { @d_lbls.d_lbl_pos = :upside_down } assert_nothing_raised('accepts valid label position') { @d_lbls.d_lbl_pos = :ctr } @@ -45,13 +44,13 @@ class TestDLbls < Test::Unit::TestCase end def test_to_xml_string - str = '<?xml version="1.0" encoding="UTF-8"?>' - str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '" xmlns:r="' << Axlsx::XML_NS_R << '">' - @d_lbls.to_xml_string(str) - str << '</c:chartSpace>' - doc = Nokogiri::XML(str) - Axlsx.instance_values_for(@d_lbls).each do |name, value| - assert(doc.xpath("//c:#{Axlsx::camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized") - end + str = '<?xml version="1.0" encoding="UTF-8"?>' + str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '" xmlns:r="' << Axlsx::XML_NS_R << '">' + @d_lbls.to_xml_string(str) + str << '</c:chartSpace>' + doc = Nokogiri::XML(str) + Axlsx.instance_values_for(@d_lbls).each do |name, value| + assert(doc.xpath("//c:#{Axlsx::camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized") + end end end diff --git a/test/drawing/tc_data_source.rb b/test/drawing/tc_data_source.rb index e9bed095..b635d56e 100644 --- a/test/drawing/tc_data_source.rb +++ b/test/drawing/tc_data_source.rb @@ -1,7 +1,6 @@ - require 'tc_helper.rb' - - class TestNumDataSource < Test::Unit::TestCase +require 'tc_helper.rb' +class TestNumDataSource < Test::Unit::TestCase def setup @data_source = Axlsx::NumDataSource.new :data => ["1", "2", "3"] end @@ -19,5 +18,4 @@ doc = Nokogiri::XML(str) assert_equal(doc.xpath("//c:val").size, 1) end - - end +end diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb index 05ffee98..282a03da 100644 --- a/test/drawing/tc_drawing.rb +++ b/test/drawing/tc_drawing.rb @@ -4,7 +4,6 @@ class TestDrawing < Test::Unit::TestCase def setup p = Axlsx::Package.new @ws = p.workbook.add_worksheet - end def test_initialization @@ -12,34 +11,36 @@ class TestDrawing < Test::Unit::TestCase end def test_add_chart - chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) + chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1]) assert(chart.is_a?(Axlsx::Pie3DChart), "must create a chart") assert_equal(@ws.workbook.charts.last, chart, "must be added to workbook charts collection") assert_equal(@ws.drawing.anchors.last.object.chart, chart, "an anchor has been created and holds a reference to this chart") anchor = @ws.drawing.anchors.last - assert_equal([anchor.from.row, anchor.from.col], [0,0], "options for start at are applied") - assert_equal([anchor.to.row, anchor.to.col], [1,1], "options for start at are applied") + assert_equal([anchor.from.row, anchor.from.col], [0, 0], "options for start at are applied") + assert_equal([anchor.to.row, anchor.to.col], [1, 1], "options for start at are applied") assert_equal(chart.title.text, "bob", "option for title is applied") end def test_add_image src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" - image = @ws.add_image(:image_src => src, :start_at=>[0,0], :width=>600, :height=>400) + image = @ws.add_image(:image_src => src, :start_at => [0, 0], :width => 600, :height => 400) assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor)) assert(image.is_a?(Axlsx::Pic)) assert_equal(600, image.width) assert_equal(400, image.height) end + def test_add_two_cell_anchor_image - src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" - image = @ws.add_image(:image_src => src, :start_at=>[0,0], :end_at => [15,0]) + src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + image = @ws.add_image(:image_src => src, :start_at => [0, 0], :end_at => [15, 0]) assert(@ws.drawing.anchors.last.is_a?(Axlsx::TwoCellAnchor)) assert(image.is_a?(Axlsx::Pic)) end + def test_charts - chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) + chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1]) assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") - chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10]) + chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "nancy", :start_at => [1, 5], :end_at => [5, 10]) assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") end @@ -59,9 +60,9 @@ class TestDrawing < Test::Unit::TestCase end def test_relationships - @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) + @ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1]) assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship") - @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10]) + @ws.add_chart(Axlsx::Pie3DChart, :title => "nancy", :start_at => [1, 5], :end_at => [5, 10]) assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship") end @@ -76,5 +77,4 @@ class TestDrawing < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_hyperlink.rb b/test/drawing/tc_hyperlink.rb index 3a95886a..f9deb5b8 100644 --- a/test/drawing/tc_hyperlink.rb +++ b/test/drawing/tc_hyperlink.rb @@ -1,11 +1,10 @@ require 'tc_helper.rb' class TestHyperlink < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet - @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" @image = ws.add_image :image_src => @test_img, :hyperlink => "http://axlsx.blogspot.com" @hyperlink = @image.hyperlink end @@ -13,7 +12,6 @@ class TestHyperlink < Test::Unit::TestCase def teardown end - def test_href assert_nothing_raised { @hyperlink.href = "http://axlsx.blogspot.com" } assert_equal(@hyperlink.href, "http://axlsx.blogspot.com") @@ -41,20 +39,20 @@ class TestHyperlink < Test::Unit::TestCase def test_endSnd assert_nothing_raised { @hyperlink.endSnd = "true" } - assert_raise(ArgumentError) {@hyperlink.endSnd = "bob"} + assert_raise(ArgumentError) { @hyperlink.endSnd = "bob" } assert_equal(@hyperlink.endSnd, "true") end def test_highlightClick assert_nothing_raised { @hyperlink.highlightClick = false } - assert_raise(ArgumentError) {@hyperlink.highlightClick = "bob"} - assert_equal(@hyperlink.highlightClick, false ) + assert_raise(ArgumentError) { @hyperlink.highlightClick = "bob" } + assert_equal(@hyperlink.highlightClick, false) end def test_history assert_nothing_raised { @hyperlink.history = false } - assert_raise(ArgumentError) {@hyperlink.history = "bob"} - assert_equal(@hyperlink.history, false ) + assert_raise(ArgumentError) { @hyperlink.history = "bob" } + assert_equal(@hyperlink.history, false) end def test_to_xml_string diff --git a/test/drawing/tc_line_3d_chart.rb b/test/drawing/tc_line_3d_chart.rb index b419e00a..c91e9216 100644 --- a/test/drawing/tc_line_3d_chart.rb +++ b/test/drawing/tc_line_3d_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestLine3DChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -20,18 +19,17 @@ class TestLine3DChart < Test::Unit::TestCase assert(@chart.serAxis.is_a?(Axlsx::SerAxis), "value access not created") end - def test_grouping - assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } - assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked } - assert(@chart.grouping == :stacked) - end - - def test_gapDepth - assert_raise(ArgumentError, "require valid gapDepth") { @chart.gapDepth = 200 } - assert_nothing_raised("allow valid gapDepth") { @chart.gapDepth = "200%" } - assert(@chart.gapDepth == "200%") - end + def test_grouping + assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted } + assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked } + assert(@chart.grouping == :stacked) + end + def test_gapDepth + assert_raise(ArgumentError, "require valid gapDepth") { @chart.gapDepth = 200 } + assert_nothing_raised("allow valid gapDepth") { @chart.gapDepth = "200%" } + assert(@chart.gapDepth == "200%") + end def test_to_xml schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) @@ -43,5 +41,4 @@ class TestLine3DChart < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_line_chart.rb b/test/drawing/tc_line_chart.rb index 0783edae..113ef844 100644 --- a/test/drawing/tc_line_chart.rb +++ b/test/drawing/tc_line_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestLineChart < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet @@ -35,5 +34,4 @@ class TestLineChart < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_line_series.rb b/test/drawing/tc_line_series.rb index d939096f..80643c4e 100644 --- a/test/drawing/tc_line_series.rb +++ b/test/drawing/tc_line_series.rb @@ -1,13 +1,12 @@ require 'tc_helper.rb' class TestLineSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" chart = @ws.add_chart Axlsx::Line3DChart, :title => "fishery" @series = chart.add_series( - :data => [0,1,2], + :data => [0, 1, 2], :labels => ["zero", "one", "two"], :title => "bob", :color => "#FF0000", diff --git a/test/drawing/tc_marker.rb b/test/drawing/tc_marker.rb index 05137ae7..ccfb76fe 100644 --- a/test/drawing/tc_marker.rb +++ b/test/drawing/tc_marker.rb @@ -16,23 +16,23 @@ class TestMarker < Test::Unit::TestCase end def test_col - assert_raise(ArgumentError) { @marker.col = -1} - assert_nothing_raised {@marker.col = 10} + assert_raise(ArgumentError) { @marker.col = -1 } + assert_nothing_raised { @marker.col = 10 } end def test_colOff - assert_raise(ArgumentError) { @marker.colOff = "1"} - assert_nothing_raised {@marker.colOff = -10} + assert_raise(ArgumentError) { @marker.colOff = "1" } + assert_nothing_raised { @marker.colOff = -10 } end def test_row - assert_raise(ArgumentError) { @marker.row = -1} - assert_nothing_raised {@marker.row = 10} + assert_raise(ArgumentError) { @marker.row = -1 } + assert_nothing_raised { @marker.row = 10 } end def test_rowOff - assert_raise(ArgumentError) { @marker.rowOff = "1"} - assert_nothing_raised {@marker.rowOff = -10} + assert_raise(ArgumentError) { @marker.rowOff = "1" } + assert_nothing_raised { @marker.rowOff = -10 } end def test_coord @@ -40,5 +40,4 @@ class TestMarker < Test::Unit::TestCase assert_equal(@marker.col, 5) assert_equal(@marker.row, 10) end - end diff --git a/test/drawing/tc_num_data.rb b/test/drawing/tc_num_data.rb index 2549af4d..7e7e12e3 100644 --- a/test/drawing/tc_num_data.rb +++ b/test/drawing/tc_num_data.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestNumData < Test::Unit::TestCase - def setup @num_data = Axlsx::NumData.new :data => [1, 2, 3] end @@ -9,14 +8,13 @@ class TestNumData < Test::Unit::TestCase def test_initialize assert_equal(@num_data.format_code, "General") end - + def test_formula_based_cell - end - + def test_format_code - assert_raise(ArgumentError) {@num_data.format_code = 7} - assert_nothing_raised {@num_data.format_code = 'foo_bar'} + assert_raise(ArgumentError) { @num_data.format_code = 7 } + assert_nothing_raised { @num_data.format_code = 'foo_bar' } end def test_to_xml_string @@ -27,5 +25,4 @@ class TestNumData < Test::Unit::TestCase assert_equal(doc.xpath("//c:numLit/c:ptCount[@val=3]").size, 1) assert_equal(doc.xpath("//c:numLit/c:pt/c:v[text()='1']").size, 1) end - end diff --git a/test/drawing/tc_num_val.rb b/test/drawing/tc_num_val.rb index ef27deb9..2123ea92 100644 --- a/test/drawing/tc_num_val.rb +++ b/test/drawing/tc_num_val.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestNumVal < Test::Unit::TestCase - def setup @num_val = Axlsx::NumVal.new :v => 1 end @@ -12,8 +11,8 @@ class TestNumVal < Test::Unit::TestCase end def test_format_code - assert_raise(ArgumentError) {@num_val.format_code = 7} - assert_nothing_raised {@num_val.format_code = 'foo_bar'} + assert_raise(ArgumentError) { @num_val.format_code = 7 } + assert_nothing_raised { @num_val.format_code = 'foo_bar' } end def test_to_xml_string @@ -23,7 +22,5 @@ class TestNumVal < Test::Unit::TestCase doc = Nokogiri::XML(str) # lets see if this works? assert_equal(doc.xpath("//c:pt/c:v[text()='1']").size, 1) - end - end diff --git a/test/drawing/tc_one_cell_anchor.rb b/test/drawing/tc_one_cell_anchor.rb index 3c1db55f..1b18f12e 100644 --- a/test/drawing/tc_one_cell_anchor.rb +++ b/test/drawing/tc_one_cell_anchor.rb @@ -1,11 +1,10 @@ require 'tc_helper.rb' class TestOneCellAnchor < Test::Unit::TestCase - def setup @p = Axlsx::Package.new @ws = @p.workbook.add_worksheet - @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" @image = @ws.add_image :image_src => @test_img @anchor = @image.anchor end @@ -51,8 +50,8 @@ class TestOneCellAnchor < Test::Unit::TestCase end def test_options - assert_raise(ArgumentError, 'invalid start_at') { @ws.add_image :image_src=>@test_img, :start_at=>[1] } - i = @ws.add_image :image_src=>@test_img, :start_at => [1,2], :width=>100, :height=>200, :name=>"someimage", :descr=>"a neat image" + assert_raise(ArgumentError, 'invalid start_at') { @ws.add_image :image_src => @test_img, :start_at => [1] } + i = @ws.add_image :image_src => @test_img, :start_at => [1, 2], :width => 100, :height => 200, :name => "someimage", :descr => "a neat image" assert_equal("a neat image", i.descr) assert_equal("someimage", i.name) @@ -62,5 +61,4 @@ class TestOneCellAnchor < Test::Unit::TestCase assert_equal(2, i.anchor.from.row) assert_equal(@test_img, i.image_src) end - end diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index 8c2088d4..56042de5 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -1,14 +1,13 @@ require 'tc_helper.rb' class TestPic < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet - @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" @test_img_png = File.dirname(__FILE__) + "/../fixtures/image1.png" @test_img_gif = File.dirname(__FILE__) + "/../fixtures/image1.gif" - @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg" + @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg" @image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?", :opacity => 5 end @@ -19,23 +18,22 @@ class TestPic < Test::Unit::TestCase end def test_anchor_swapping - #swap from one cell to two cell when end_at is specified + # swap from one cell to two cell when end_at is specified assert(@image.anchor.is_a?(Axlsx::OneCellAnchor)) start_at = @image.anchor.from - @image.end_at 10,5 + @image.end_at 10, 5 assert(@image.anchor.is_a?(Axlsx::TwoCellAnchor)) assert_equal(start_at.col, @image.anchor.from.col) assert_equal(start_at.row, @image.anchor.from.row) - assert_equal(10,@image.anchor.to.col) + assert_equal(10, @image.anchor.to.col) assert_equal(5, @image.anchor.to.row) - #swap from two cell to one cell when width or height are specified + # swap from two cell to one cell when width or height are specified @image.width = 200 assert(@image.anchor.is_a?(Axlsx::OneCellAnchor)) assert_equal(start_at.col, @image.anchor.from.col) assert_equal(start_at.row, @image.anchor.from.row) assert_equal(200, @image.width) - end def test_hyperlink diff --git a/test/drawing/tc_picture_locking.rb b/test/drawing/tc_picture_locking.rb index c0a828aa..6e5de47b 100644 --- a/test/drawing/tc_picture_locking.rb +++ b/test/drawing/tc_picture_locking.rb @@ -4,6 +4,7 @@ class TestPictureLocking < Test::Unit::TestCase def setup @item = Axlsx::PictureLocking.new end + def teardown end @@ -15,58 +16,54 @@ class TestPictureLocking < Test::Unit::TestCase def test_noGrp assert_raise(ArgumentError) { @item.noGrp = -1 } assert_nothing_raised { @item.noGrp = false } - assert_equal(@item.noGrp, false ) + assert_equal(@item.noGrp, false) end def test_noRot assert_raise(ArgumentError) { @item.noRot = -1 } assert_nothing_raised { @item.noRot = false } - assert_equal(@item.noRot, false ) + assert_equal(@item.noRot, false) end def test_noChangeAspect assert_raise(ArgumentError) { @item.noChangeAspect = -1 } assert_nothing_raised { @item.noChangeAspect = false } - assert_equal(@item.noChangeAspect, false ) + assert_equal(@item.noChangeAspect, false) end def test_noMove assert_raise(ArgumentError) { @item.noMove = -1 } assert_nothing_raised { @item.noMove = false } - assert_equal(@item.noMove, false ) + assert_equal(@item.noMove, false) end def test_noResize assert_raise(ArgumentError) { @item.noResize = -1 } assert_nothing_raised { @item.noResize = false } - assert_equal(@item.noResize, false ) + assert_equal(@item.noResize, false) end def test_noEditPoints assert_raise(ArgumentError) { @item.noEditPoints = -1 } assert_nothing_raised { @item.noEditPoints = false } - assert_equal(@item.noEditPoints, false ) + assert_equal(@item.noEditPoints, false) end def test_noAdjustHandles assert_raise(ArgumentError) { @item.noAdjustHandles = -1 } assert_nothing_raised { @item.noAdjustHandles = false } - assert_equal(@item.noAdjustHandles, false ) + assert_equal(@item.noAdjustHandles, false) end def test_noChangeArrowheads assert_raise(ArgumentError) { @item.noChangeArrowheads = -1 } assert_nothing_raised { @item.noChangeArrowheads = false } - assert_equal(@item.noChangeArrowheads, false ) + assert_equal(@item.noChangeArrowheads, false) end def test_noChangeShapeType assert_raise(ArgumentError) { @item.noChangeShapeType = -1 } assert_nothing_raised { @item.noChangeShapeType = false } - assert_equal(@item.noChangeShapeType, false ) + assert_equal(@item.noChangeShapeType, false) end - - - - end diff --git a/test/drawing/tc_pie_3D_chart.rb b/test/drawing/tc_pie_3D_chart.rb index a941eacd..f536f086 100644 --- a/test/drawing/tc_pie_3D_chart.rb +++ b/test/drawing/tc_pie_3D_chart.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestPie3DChart < Test::Unit::TestCase - def setup p = Axlsx::Package.new ws = p.workbook.add_worksheet @@ -21,8 +20,7 @@ class TestPie3DChart < Test::Unit::TestCase def test_to_xml schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) doc = Nokogiri::XML(@chart.to_xml_string) - errors = schema.validate(doc).map {|error| puts error.message; error } + errors = schema.validate(doc).map { |error| puts error.message; error } assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_pie_series.rb b/test/drawing/tc_pie_series.rb index 18e4bbd0..c3f5bb3a 100644 --- a/test/drawing/tc_pie_series.rb +++ b/test/drawing/tc_pie_series.rb @@ -1,12 +1,11 @@ require 'tc_helper.rb' class TestPieSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" chart = @ws.add_chart Axlsx::Pie3DChart, :title => "fishery" - @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :colors => ["FF0000", "00FF00", "0000FF"] + @series = chart.add_series :data => [0, 1, 2], :labels => ["zero", "one", "two"], :title => "bob", :colors => ["FF0000", "00FF00", "0000FF"] end def test_initialize @@ -28,6 +27,5 @@ class TestPieSeries < Test::Unit::TestCase doc = Nokogiri::XML(@series.to_xml_string) assert(doc.xpath("//srgbClr[@val='#{@series.colors[0]}']")) end - #TODO test unique serialization parts - + # TODO test unique serialization parts end diff --git a/test/drawing/tc_scaling.rb b/test/drawing/tc_scaling.rb index 01e21a5d..8f92a024 100644 --- a/test/drawing/tc_scaling.rb +++ b/test/drawing/tc_scaling.rb @@ -13,24 +13,22 @@ class TestScaling < Test::Unit::TestCase end def test_logBase - assert_raise(ArgumentError) { @scaling.logBase = 1} - assert_nothing_raised {@scaling.logBase = 10} + assert_raise(ArgumentError) { @scaling.logBase = 1 } + assert_nothing_raised { @scaling.logBase = 10 } end def test_orientation - assert_raise(ArgumentError) { @scaling.orientation = "1"} - assert_nothing_raised {@scaling.orientation = :maxMin} + assert_raise(ArgumentError) { @scaling.orientation = "1" } + assert_nothing_raised { @scaling.orientation = :maxMin } end - def test_max - assert_raise(ArgumentError) { @scaling.max = 1} - assert_nothing_raised {@scaling.max = 10.5} + assert_raise(ArgumentError) { @scaling.max = 1 } + assert_nothing_raised { @scaling.max = 10.5 } end def test_min - assert_raise(ArgumentError) { @scaling.min = 1} - assert_nothing_raised {@scaling.min = 10.5} + assert_raise(ArgumentError) { @scaling.min = 1 } + assert_nothing_raised { @scaling.min = 10.5 } end - end diff --git a/test/drawing/tc_scatter_chart.rb b/test/drawing/tc_scatter_chart.rb index 15b1f0a0..359f7206 100644 --- a/test/drawing/tc_scatter_chart.rb +++ b/test/drawing/tc_scatter_chart.rb @@ -5,9 +5,9 @@ class TestScatterChart < Test::Unit::TestCase @p = Axlsx::Package.new @chart = nil @p.workbook.add_worksheet do |sheet| - sheet.add_row ["First", 1, 5, 7, 9] + sheet.add_row ["First", 1, 5, 7, 9] sheet.add_row ["", 1, 25, 49, 81] - sheet.add_row ["Second", 5, 2, 14, 9] + sheet.add_row ["Second", 5, 2, 14, 9] sheet.add_row ["", 5, 10, 15, 20] sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart| chart.start_at 0, 4 @@ -27,6 +27,7 @@ class TestScatterChart < Test::Unit::TestCase assert(@chart.scatterStyle == :marker) assert_raise(ArgumentError) { @chart.scatterStyle = :buckshot } end + def test_initialization assert_equal(@chart.scatterStyle, :lineMarker, "scatterStyle defualt incorrect") assert_equal(@chart.series_type, Axlsx::ScatterSeries, "series type incorrect") @@ -44,5 +45,4 @@ class TestScatterChart < Test::Unit::TestCase end assert(errors.empty?, "error free validation") end - end diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb index 3d1d294d..5ca126a2 100644 --- a/test/drawing/tc_scatter_series.rb +++ b/test/drawing/tc_scatter_series.rb @@ -1,12 +1,11 @@ require 'tc_helper.rb' class TestScatterSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Scatter Chart" - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000', :smooth => true + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "exponents", :color => 'FF0000', :smooth => true end def test_initialize @@ -15,31 +14,31 @@ class TestScatterSeries < Test::Unit::TestCase def test_smoothed_chart_default_smoothing @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart", :scatter_style => :smoothMarker - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents" + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "smoothed exponents" assert(@series.smooth, "series is smooth by default on smooth charts") end def test_unsmoothed_chart_default_smoothing @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents" + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "unsmoothed exponents" assert([email protected], "series is not smooth by default on non-smooth charts") end def test_explicit_smoothing @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents", :smooth => true + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "smoothed exponents", :smooth => true assert(@series.smooth, "series is smooth when overriding chart default") end def test_explicit_unsmoothing @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents", :smooth => false + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "unsmoothed exponents", :smooth => false assert([email protected], "series is not smooth when overriding chart default") end def test_ln_width @chart = @ws.add_chart Axlsx::ScatterChart, :title => "ln width", :scatter_style => :line - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"ln_width" + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "ln_width" @series.ln_width = 12700 assert_equal(@series.ln_width, 12700, 'line width assigment is allowed') end @@ -49,26 +48,25 @@ class TestScatterSeries < Test::Unit::TestCase @series.ln_width = 12700 doc = Nokogiri::XML(@chart.to_xml_string) assert_equal(12700, @series.ln_width) - assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,4) + assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size, 4) assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1) end def test_false_show_marker @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Smooth Chart', :scatter_style => :smoothMarker - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9] + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9] assert(@series.show_marker, 'markers are enabled for marker-related styles') end def test_true_show_marker @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9] + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9] assert([email protected]_marker, 'markers are disabled for markerless scatter styles') end def test_marker_symbol @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :marker_symbol => :diamond + @series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :marker_symbol => :diamond assert_equal(@series.marker_symbol, :diamond, 'series could have own custom marker symbol') end - end diff --git a/test/drawing/tc_ser_axis.rb b/test/drawing/tc_ser_axis.rb index 7febafce..4b498a12 100644 --- a/test/drawing/tc_ser_axis.rb +++ b/test/drawing/tc_ser_axis.rb @@ -14,18 +14,15 @@ class TestSerAxis < Test::Unit::TestCase assert_equal(a.tick_mark_skip, 7) end - def test_tick_lbl_skip assert_raise(ArgumentError, "requires valid tick_lbl_skip") { @axis.tick_lbl_skip = -1 } assert_nothing_raised("accepts valid tick_lbl_skip") { @axis.tick_lbl_skip = 1 } assert_equal(@axis.tick_lbl_skip, 1) end - def test_tick_mark_skip assert_raise(ArgumentError, "requires valid tick_mark_skip") { @axis.tick_mark_skip = :my_eyes } assert_nothing_raised("accepts valid tick_mark_skip") { @axis.tick_mark_skip = 2 } assert_equal(@axis.tick_mark_skip, 2) end - end diff --git a/test/drawing/tc_series.rb b/test/drawing/tc_series.rb index b32595a7..80f4b7cb 100644 --- a/test/drawing/tc_series.rb +++ b/test/drawing/tc_series.rb @@ -1,12 +1,11 @@ require 'tc_helper.rb' class TestSeries < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" chart = @ws.add_chart Axlsx::Chart, :title => "fishery" - @series = chart.add_series :title=>"bob" + @series = chart.add_series :title => "bob" end def test_initialize @@ -19,5 +18,4 @@ class TestSeries < Test::Unit::TestCase @series.order = 2 assert_equal(@series.order, 2) end - end diff --git a/test/drawing/tc_str_data.rb b/test/drawing/tc_str_data.rb index a116965b..f964a7b3 100644 --- a/test/drawing/tc_str_data.rb +++ b/test/drawing/tc_str_data.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestStrData < Test::Unit::TestCase - def setup @str_data = Axlsx::StrData.new :data => ["1", "2", "3"] end @@ -14,5 +13,4 @@ class TestStrData < Test::Unit::TestCase assert_equal(doc.xpath("//c:strLit/c:ptCount[@val=3]").size, 1) assert_equal(doc.xpath("//c:strLit/c:pt/c:v[text()='1']").size, 1) end - end diff --git a/test/drawing/tc_str_val.rb b/test/drawing/tc_str_val.rb index e4547f62..03b0b32a 100644 --- a/test/drawing/tc_str_val.rb +++ b/test/drawing/tc_str_val.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestStrVal < Test::Unit::TestCase - def setup @str_val = Axlsx::StrVal.new :v => "1" @str_val_with_special_characters = Axlsx::StrVal.new :v => "a & b <c>" @@ -26,5 +25,4 @@ class TestStrVal < Test::Unit::TestCase doc = Nokogiri::XML(str) assert_equal(doc.xpath("//c:pt/c:v[text()='a & b <c>']").size, 1) end - end diff --git a/test/drawing/tc_two_cell_anchor.rb b/test/drawing/tc_two_cell_anchor.rb index db84521d..f2067c23 100644 --- a/test/drawing/tc_two_cell_anchor.rb +++ b/test/drawing/tc_two_cell_anchor.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestTwoCellAnchor < Test::Unit::TestCase - def setup p = Axlsx::Package.new @ws = p.workbook.add_worksheet @@ -22,8 +21,8 @@ class TestTwoCellAnchor < Test::Unit::TestCase end def test_options - assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at=>"1" } - assert_raise(ArgumentError, 'invalid end_at') { @ws.add_chart Axlsx::Chart, :start_at=>[1,2], :end_at => ["a", 4] } + assert_raise(ArgumentError, 'invalid start_at') { @ws.add_chart Axlsx::Chart, :start_at => "1" } + assert_raise(ArgumentError, 'invalid end_at') { @ws.add_chart Axlsx::Chart, :start_at => [1, 2], :end_at => ["a", 4] } # this is actually raised in the graphic frame assert_raise(ArgumentError, 'invalid Chart') { @ws.add_chart Axlsx::TwoCellAnchor } a = @ws.add_chart Axlsx::Chart, :start_at => [15, 35], :end_at => [90, 45] @@ -32,5 +31,4 @@ class TestTwoCellAnchor < Test::Unit::TestCase assert_equal(a.graphic_frame.anchor.to.col, 90) assert_equal(a.graphic_frame.anchor.to.row, 45) end - end diff --git a/test/drawing/tc_val_axis.rb b/test/drawing/tc_val_axis.rb index aa1cb23a..a607ddb1 100644 --- a/test/drawing/tc_val_axis.rb +++ b/test/drawing/tc_val_axis.rb @@ -4,6 +4,7 @@ class TestValAxis < Test::Unit::TestCase def setup @axis = Axlsx::ValAxis.new end + def teardown end @@ -20,5 +21,4 @@ class TestValAxis < Test::Unit::TestCase assert_raise(ArgumentError, "requires valid crossBetween") { @axis.cross_between = :my_eyes } assert_nothing_raised("accepts valid crossBetween") { @axis.cross_between = :midCat } end - end diff --git a/test/drawing/tc_view_3D.rb b/test/drawing/tc_view_3D.rb index 5f6809ef..43116023 100644 --- a/test/drawing/tc_view_3D.rb +++ b/test/drawing/tc_view_3D.rb @@ -2,7 +2,7 @@ require 'tc_helper.rb' class TestView3D < Test::Unit::TestCase def setup - @view = Axlsx::View3D.new + @view = Axlsx::View3D.new end def teardown @@ -19,36 +19,32 @@ class TestView3D < Test::Unit::TestCase end def test_rot_x - assert_raise(ArgumentError) {@view.rot_x = "bob"} - assert_nothing_raised {@view.rot_x = -90} + assert_raise(ArgumentError) { @view.rot_x = "bob" } + assert_nothing_raised { @view.rot_x = -90 } end def test_rot_y - assert_raise(ArgumentError) {@view.rot_y = "bob"} - assert_nothing_raised {@view.rot_y = 90} + assert_raise(ArgumentError) { @view.rot_y = "bob" } + assert_nothing_raised { @view.rot_y = 90 } end def test_h_percent - assert_raise(ArgumentError) {@view.h_percent = "bob"} - assert_nothing_raised {@view.h_percent = "500%"} + assert_raise(ArgumentError) { @view.h_percent = "bob" } + assert_nothing_raised { @view.h_percent = "500%" } end def test_depth_percent - assert_raise(ArgumentError) {@view.depth_percent = "bob"} - assert_nothing_raised {@view.depth_percent = "20%"} + assert_raise(ArgumentError) { @view.depth_percent = "bob" } + assert_nothing_raised { @view.depth_percent = "20%" } end - def test_rAngAx - assert_raise(ArgumentError) {@view.rAngAx = "bob"} - assert_nothing_raised {@view.rAngAx = true} + assert_raise(ArgumentError) { @view.rAngAx = "bob" } + assert_nothing_raised { @view.rAngAx = true } end def test_perspective - assert_raise(ArgumentError) {@view.perspective = "bob"} - assert_nothing_raised {@view.perspective = 30} + assert_raise(ArgumentError) { @view.perspective = "bob" } + assert_nothing_raised { @view.perspective = 30 } end - - - end diff --git a/test/drawing/tc_vml_drawing.rb b/test/drawing/tc_vml_drawing.rb index ac95a2f3..debba561 100644 --- a/test/drawing/tc_vml_drawing.rb +++ b/test/drawing/tc_vml_drawing.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestVmlDrawing < Test::Unit::TestCase - def setup p = Axlsx::Package.new wb = p.workbook @@ -19,7 +18,6 @@ class TestVmlDrawing < Test::Unit::TestCase str = @vml_drawing.to_xml_string() doc = Nokogiri::XML(str) assert_equal(doc.xpath("//v:shape").size, 2) - assert(doc.xpath("//o:idmap[@o:data='#{@ws.index+1}']")) + assert(doc.xpath("//o:idmap[@o:data='#{@ws.index + 1}']")) end - end diff --git a/test/drawing/tc_vml_shape.rb b/test/drawing/tc_vml_shape.rb index 94ad6e9f..b8344a92 100644 --- a/test/drawing/tc_vml_shape.rb +++ b/test/drawing/tc_vml_shape.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestVmlShape < Test::Unit::TestCase - def setup p = Axlsx::Package.new wb = p.workbook @@ -84,12 +83,14 @@ class TestVmlShape < Test::Unit::TestCase assert(shape.top_row == 3) assert_raise(ArgumentError) { shape.top_row = [] } end + def test_visible shape = @comments.first.vml_shape shape.visible = false assert(shape.visible == false) assert_raise(ArgumentError) { shape.visible = 'foo' } end + def test_to_xml_string str = @comments.vml_drawing.to_xml_string() doc = Nokogiri::XML(str) @@ -102,5 +103,4 @@ class TestVmlShape < Test::Unit::TestCase assert(doc.xpath("//v:shape/x:ClientData/x:Anchor[text()='#{shape.left_column}, #{shape.left_offset}, #{shape.top_row}, #{shape.top_offset}, #{shape.right_column}, #{shape.right_offset}, #{shape.bottom_row}, #{shape.bottom_offset}']").size == 1) end end - end diff --git a/test/profile.rb b/test/profile.rb index de00b32b..ef42c2f8 100644 --- a/test/profile.rb +++ b/test/profile.rb @@ -3,12 +3,12 @@ $:.unshift "#{File.dirname(__FILE__)}/../lib" require 'axlsx' require 'ruby-prof' -#RubyProf.measure_mode = RubyProf::MEMORY +# RubyProf.measure_mode = RubyProf::MEMORY # row = [] # Taking worst case scenario of all string data input = (32..126).to_a.pack('U*').chars.to_a -20.times { row << input.shuffle.join} +20.times { row << input.shuffle.join } profile = RubyProf.profile do p = Axlsx::Package.new diff --git a/test/rels/tc_relationship.rb b/test/rels/tc_relationship.rb index f47b6a4d..1a9df27a 100644 --- a/test/rels/tc_relationship.rb +++ b/test/rels/tc_relationship.rb @@ -1,13 +1,12 @@ require 'tc_helper.rb' class TestRelationships < Test::Unit::TestCase - def test_instances_with_different_attributes_have_unique_ids rel_1 = Axlsx::Relationship.new(Object.new, Axlsx::WORKSHEET_R, 'target') rel_2 = Axlsx::Relationship.new(Object.new, Axlsx::COMMENT_R, 'foobar') assert_not_equal rel_1.Id, rel_2.Id end - + def test_instances_with_same_attributes_share_id source_obj = Object.new instance = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target') @@ -21,18 +20,18 @@ class TestRelationships < Test::Unit::TestCase [t1, t2].each(&:join) assert_not_same(cache1, cache2) end - + def test_target_is_only_considered_for_same_attributes_check_if_target_mode_is_external source_obj = Object.new rel_1 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target') rel_2 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, '../target') assert_equal rel_1.Id, rel_2.Id - + rel_3 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, 'target', :target_mode => :External) rel_4 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, '../target', :target_mode => :External) assert_not_equal rel_3.Id, rel_4.Id end - + def test_type assert_raise(ArgumentError) { Axlsx::Relationship.new nil, 'type', 'target' } assert_nothing_raised { Axlsx::Relationship.new nil, Axlsx::WORKSHEET_R, 'target' } @@ -41,7 +40,7 @@ class TestRelationships < Test::Unit::TestCase def test_target_mode assert_raise(ArgumentError) { Axlsx::Relationship.new nil, 'type', 'target', :target_mode => "FISH" } - assert_nothing_raised { Axlsx::Relationship.new( nil, Axlsx::WORKSHEET_R, 'target', :target_mode => :External) } + assert_nothing_raised { Axlsx::Relationship.new(nil, Axlsx::WORKSHEET_R, 'target', :target_mode => :External) } end def test_ampersand_escaping_in_target diff --git a/test/rels/tc_relationships.rb b/test/rels/tc_relationships.rb index fe5a1ce5..43e413cd 100644 --- a/test/rels/tc_relationships.rb +++ b/test/rels/tc_relationships.rb @@ -1,18 +1,17 @@ require 'tc_helper.rb' class TestRelationships < Test::Unit::TestCase - def test_for source_obj_1, source_obj_2 = Object.new, Object.new rel_1 = Axlsx::Relationship.new(source_obj_1, Axlsx::WORKSHEET_R, "bar") rel_2 = Axlsx::Relationship.new(source_obj_2, Axlsx::WORKSHEET_R, "bar") rels = Axlsx::Relationships.new - rels << rel_1 + rels << rel_1 rels << rel_2 assert_equal rel_1, rels.for(source_obj_1) assert_equal rel_2, rels.for(source_obj_2) end - + def test_valid_document @rels = Axlsx::Relationships.new schema = Nokogiri::XML::Schema(File.open(Axlsx::RELS_XSD)) @@ -33,5 +32,4 @@ class TestRelationships < Test::Unit::TestCase assert(errors.size == 0) end - end diff --git a/test/stylesheet/tc_border.rb b/test/stylesheet/tc_border.rb index ae191dd0..9e29dda4 100644 --- a/test/stylesheet/tc_border.rb +++ b/test/stylesheet/tc_border.rb @@ -4,8 +4,10 @@ class TestBorder < Test::Unit::TestCase def setup @b = Axlsx::Border.new end + def teardown end + def test_initialiation assert_equal(@b.diagonalUp, nil) assert_equal(@b.diagonalDown, nil) @@ -16,22 +18,22 @@ class TestBorder < Test::Unit::TestCase def test_diagonalUp assert_raise(ArgumentError) { @b.diagonalUp = :red } assert_nothing_raised { @b.diagonalUp = true } - assert_equal(@b.diagonalUp, true ) + assert_equal(@b.diagonalUp, true) end def test_diagonalDown assert_raise(ArgumentError) { @b.diagonalDown = :red } assert_nothing_raised { @b.diagonalDown = true } - assert_equal(@b.diagonalDown, true ) + assert_equal(@b.diagonalDown, true) end def test_outline assert_raise(ArgumentError) { @b.outline = :red } assert_nothing_raised { @b.outline = true } - assert_equal(@b.outline, true ) + assert_equal(@b.outline, true) end def test_prs - assert_nothing_raised { @b.prs << Axlsx::BorderPr.new(:name=>:top, :style=>:thin, :color => Axlsx::Color.new(:rgb=>"FF0000FF")) } + assert_nothing_raised { @b.prs << Axlsx::BorderPr.new(:name => :top, :style => :thin, :color => Axlsx::Color.new(:rgb => "FF0000FF")) } end end diff --git a/test/stylesheet/tc_border_pr.rb b/test/stylesheet/tc_border_pr.rb index dc0fa9da..3b25575b 100644 --- a/test/stylesheet/tc_border_pr.rb +++ b/test/stylesheet/tc_border_pr.rb @@ -4,8 +4,10 @@ class TestBorderPr < Test::Unit::TestCase def setup @bpr = Axlsx::BorderPr.new end + def teardown end + def test_initialiation assert_equal(@bpr.color, nil) assert_equal(@bpr.style, nil) @@ -14,7 +16,7 @@ class TestBorderPr < Test::Unit::TestCase def test_color assert_raise(ArgumentError) { @bpr.color = :red } - assert_nothing_raised { @bpr.color = Axlsx::Color.new :rgb=>"FF000000" } + assert_nothing_raised { @bpr.color = Axlsx::Color.new :rgb => "FF000000" } assert(@bpr.color.is_a?(Axlsx::Color)) end diff --git a/test/stylesheet/tc_cell_alignment.rb b/test/stylesheet/tc_cell_alignment.rb index 6b8cd5cd..0b514bf4 100644 --- a/test/stylesheet/tc_cell_alignment.rb +++ b/test/stylesheet/tc_cell_alignment.rb @@ -15,67 +15,66 @@ class TestCellAlignment < Test::Unit::TestCase assert_equal(@item.justifyLastLine, nil) assert_equal(@item.shrinkToFit, nil) assert_equal(@item.readingOrder, nil) - options = { :horizontal => :left, :vertical => :top, :textRotation => 3, - :wrapText => true, :indent => 2, :relativeIndent => 5, - :justifyLastLine => true, :shrinkToFit => true, :readingOrder => 2 } + options = { :horizontal => :left, :vertical => :top, :textRotation => 3, + :wrapText => true, :indent => 2, :relativeIndent => 5, + :justifyLastLine => true, :shrinkToFit => true, :readingOrder => 2 } ca = Axlsx::CellAlignment.new options options.each do |key, value| - assert_equal(ca.send(key.to_sym),value) + assert_equal(ca.send(key.to_sym), value) end end def test_horizontal assert_raise(ArgumentError) { @item.horizontal = :red } assert_nothing_raised { @item.horizontal = :left } - assert_equal(@item.horizontal, :left ) + assert_equal(@item.horizontal, :left) end def test_vertical assert_raise(ArgumentError) { @item.vertical = :red } assert_nothing_raised { @item.vertical = :top } - assert_equal(@item.vertical, :top ) + assert_equal(@item.vertical, :top) end def test_textRotation assert_raise(ArgumentError) { @item.textRotation = -1 } assert_nothing_raised { @item.textRotation = 5 } - assert_equal(@item.textRotation, 5 ) + assert_equal(@item.textRotation, 5) end def test_wrapText assert_raise(ArgumentError) { @item.wrapText = -1 } assert_nothing_raised { @item.wrapText = false } - assert_equal(@item.wrapText, false ) + assert_equal(@item.wrapText, false) end def test_indent assert_raise(ArgumentError) { @item.indent = -1 } assert_nothing_raised { @item.indent = 5 } - assert_equal(@item.indent, 5 ) + assert_equal(@item.indent, 5) end def test_relativeIndent assert_raise(ArgumentError) { @item.relativeIndent = :symbol } assert_nothing_raised { @item.relativeIndent = 5 } - assert_equal(@item.relativeIndent, 5 ) + assert_equal(@item.relativeIndent, 5) end def test_justifyLastLine assert_raise(ArgumentError) { @item.justifyLastLine = -1 } assert_nothing_raised { @item.justifyLastLine = true } - assert_equal(@item.justifyLastLine, true ) + assert_equal(@item.justifyLastLine, true) end def test_shrinkToFit assert_raise(ArgumentError) { @item.shrinkToFit = -1 } assert_nothing_raised { @item.shrinkToFit = true } - assert_equal(@item.shrinkToFit, true ) + assert_equal(@item.shrinkToFit, true) end def test_readingOrder assert_raise(ArgumentError) { @item.readingOrder = -1 } assert_nothing_raised { @item.readingOrder = 2 } - assert_equal(@item.readingOrder, 2 ) + assert_equal(@item.readingOrder, 2) end - end diff --git a/test/stylesheet/tc_cell_protection.rb b/test/stylesheet/tc_cell_protection.rb index b2161fa6..a1fc59b2 100644 --- a/test/stylesheet/tc_cell_protection.rb +++ b/test/stylesheet/tc_cell_protection.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestCellProtection < Test::Unit::TestCase - def setup @item = Axlsx::CellProtection.new end @@ -17,13 +16,12 @@ class TestCellProtection < Test::Unit::TestCase def test_hidden assert_raise(ArgumentError) { @item.hidden = -1 } assert_nothing_raised { @item.hidden = false } - assert_equal(@item.hidden, false ) + assert_equal(@item.hidden, false) end def test_locked assert_raise(ArgumentError) { @item.locked = -1 } assert_nothing_raised { @item.locked = false } - assert_equal(@item.locked, false ) + assert_equal(@item.locked, false) end - end diff --git a/test/stylesheet/tc_cell_style.rb b/test/stylesheet/tc_cell_style.rb index 8700d8c3..18e7a1ab 100644 --- a/test/stylesheet/tc_cell_style.rb +++ b/test/stylesheet/tc_cell_style.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestCellStyle < Test::Unit::TestCase - def setup @item = Axlsx::CellStyle.new end @@ -21,37 +20,36 @@ class TestCellStyle < Test::Unit::TestCase def test_name assert_raise(ArgumentError) { @item.name = -1 } assert_nothing_raised { @item.name = "stylin" } - assert_equal(@item.name, "stylin" ) + assert_equal(@item.name, "stylin") end def test_xfId assert_raise(ArgumentError) { @item.xfId = -1 } assert_nothing_raised { @item.xfId = 5 } - assert_equal(@item.xfId, 5 ) + assert_equal(@item.xfId, 5) end def test_builtinId assert_raise(ArgumentError) { @item.builtinId = -1 } assert_nothing_raised { @item.builtinId = 5 } - assert_equal(@item.builtinId, 5 ) + assert_equal(@item.builtinId, 5) end def test_iLevel assert_raise(ArgumentError) { @item.iLevel = -1 } assert_nothing_raised { @item.iLevel = 5 } - assert_equal(@item.iLevel, 5 ) + assert_equal(@item.iLevel, 5) end def test_hidden assert_raise(ArgumentError) { @item.hidden = -1 } assert_nothing_raised { @item.hidden = true } - assert_equal(@item.hidden, true ) + assert_equal(@item.hidden, true) end def test_customBuiltin assert_raise(ArgumentError) { @item.customBuiltin = -1 } assert_nothing_raised { @item.customBuiltin = true } - assert_equal(@item.customBuiltin, true ) + assert_equal(@item.customBuiltin, true) end - end diff --git a/test/stylesheet/tc_color.rb b/test/stylesheet/tc_color.rb index dd8e98d2..8f87111e 100644 --- a/test/stylesheet/tc_color.rb +++ b/test/stylesheet/tc_color.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestColor < Test::Unit::TestCase - def setup @item = Axlsx::Color.new end @@ -18,13 +17,13 @@ class TestColor < Test::Unit::TestCase def test_auto assert_raise(ArgumentError) { @item.auto = -1 } assert_nothing_raised { @item.auto = true } - assert_equal(@item.auto, true ) + assert_equal(@item.auto, true) end def test_rgb assert_raise(ArgumentError) { @item.rgb = -1 } assert_nothing_raised { @item.rgb = "FF00FF00" } - assert_equal(@item.rgb, "FF00FF00" ) + assert_equal(@item.rgb, "FF00FF00") end def test_rgb_writer_doesnt_mutate_its_argument @@ -36,8 +35,6 @@ class TestColor < Test::Unit::TestCase def test_tint assert_raise(ArgumentError) { @item.tint = -1 } assert_nothing_raised { @item.tint = -1.0 } - assert_equal(@item.tint, -1.0 ) + assert_equal(@item.tint, -1.0) end - - end diff --git a/test/stylesheet/tc_dxf.rb b/test/stylesheet/tc_dxf.rb index e94a1614..9e87007d 100644 --- a/test/stylesheet/tc_dxf.rb +++ b/test/stylesheet/tc_dxf.rb @@ -1,10 +1,9 @@ require 'tc_helper.rb' class TestDxf < Test::Unit::TestCase - def setup @item = Axlsx::Dxf.new - @styles = Axlsx::Styles.new + @styles = Axlsx::Styles.new end def teardown @@ -38,15 +37,15 @@ class TestDxf < Test::Unit::TestCase end def test_fill - assert_raise(ArgumentError) { @item.fill = 1 } - assert_nothing_raised { @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType =>:solid, :fgColor=> Axlsx::Color.new(:rgb => "FF000000"))) } + assert_raise(ArgumentError) { @item.fill = 1 } + assert_nothing_raised { @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType => :solid, :fgColor => Axlsx::Color.new(:rgb => "FF000000"))) } assert @item.fill.is_a? Axlsx::Fill end def test_font assert_raise(ArgumentError) { @item.font = 1 } assert_nothing_raised { @item.font = Axlsx::Font.new } - assert @item.font.is_a? Axlsx::Font + assert @item.font.is_a? Axlsx::Font end def test_border @@ -59,23 +58,23 @@ class TestDxf < Test::Unit::TestCase @item.border = Axlsx::Border.new doc = Nokogiri::XML.parse(@item.to_xml_string) assert_equal(1, doc.xpath(".//dxf//border").size) - assert_equal(0, doc.xpath(".//dxf//font").size) + assert_equal(0, doc.xpath(".//dxf//font").size) end def test_many_options_xml @item.border = Axlsx::Border.new @item.alignment = Axlsx::CellAlignment.new - @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType =>:solid, :fgColor=> Axlsx::Color.new(:rgb => "FF000000"))) + @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType => :solid, :fgColor => Axlsx::Color.new(:rgb => "FF000000"))) @item.font = Axlsx::Font.new @item.protection = Axlsx::CellProtection.new @item.numFmt = Axlsx::NumFmt.new - + doc = Nokogiri::XML.parse(@item.to_xml_string) assert_equal(1, doc.xpath(".//dxf//fill//patternFill[@patternType='solid']//fgColor[@rgb='FF000000']").size) assert_equal(1, doc.xpath(".//dxf//font").size) assert_equal(1, doc.xpath(".//dxf//protection").size) assert_equal(1, doc.xpath(".//dxf//numFmt[@numFmtId='0'][@formatCode='']").size) assert_equal(1, doc.xpath(".//dxf//alignment").size) - assert_equal(1, doc.xpath(".//dxf//border").size) + assert_equal(1, doc.xpath(".//dxf//border").size) end end diff --git a/test/stylesheet/tc_fill.rb b/test/stylesheet/tc_fill.rb index 9aadef29..dd61204f 100644 --- a/test/stylesheet/tc_fill.rb +++ b/test/stylesheet/tc_fill.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestFill < Test::Unit::TestCase - def setup @item = Axlsx::Fill.new Axlsx::PatternFill.new end @@ -14,5 +13,4 @@ class TestFill < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx::Fill.new } assert_nothing_raised { Axlsx::Fill.new(Axlsx::GradientFill.new) } end - end diff --git a/test/stylesheet/tc_font.rb b/test/stylesheet/tc_font.rb index 4d548d7c..821e8820 100644 --- a/test/stylesheet/tc_font.rb +++ b/test/stylesheet/tc_font.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestFont < Test::Unit::TestCase - def setup @item = Axlsx::Font.new end @@ -9,7 +8,6 @@ class TestFont < Test::Unit::TestCase def teardown end - def test_initialiation assert_equal(@item.name, nil) assert_equal(@item.charset, nil) @@ -26,43 +24,42 @@ class TestFont < Test::Unit::TestCase assert_equal(@item.sz, nil) end - - - # def name=(v) Axlsx::validate_string v; @name = v end + # def name=(v) Axlsx::validate_string v; @name = v end def test_name assert_raise(ArgumentError) { @item.name = 7 } assert_nothing_raised { @item.name = "bob" } assert_equal(@item.name, "bob") end - # def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end + + # def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end def test_charset assert_raise(ArgumentError) { @item.charset = -7 } assert_nothing_raised { @item.charset = 5 } assert_equal(@item.charset, 5) end - # def family=(v) Axlsx::validate_unsigned_int v; @family = v end + # def family=(v) Axlsx::validate_unsigned_int v; @family = v end def test_family assert_raise(ArgumentError) { @item.family = -7 } assert_nothing_raised { @item.family = 5 } assert_equal(@item.family, 5) end - # def b=(v) Axlsx::validate_boolean v; @b = v end + # def b=(v) Axlsx::validate_boolean v; @b = v end def test_b assert_raise(ArgumentError) { @item.b = -7 } assert_nothing_raised { @item.b = true } assert_equal(@item.b, true) end - # def i=(v) Axlsx::validate_boolean v; @i = v end + # def i=(v) Axlsx::validate_boolean v; @i = v end def test_i assert_raise(ArgumentError) { @item.i = -7 } assert_nothing_raised { @item.i = true } assert_equal(@item.i, true) end - # def u=(v) Axlsx::validate_cell_u v; @u = v end + # def u=(v) Axlsx::validate_cell_u v; @u = v end def test_u assert_raise(ArgumentError) { @item.u = -7 } assert_nothing_raised { @item.u = :single } @@ -81,53 +78,52 @@ class TestFont < Test::Unit::TestCase assert_equal(@item.u, :none) end - # def strike=(v) Axlsx::validate_boolean v; @strike = v end + # def strike=(v) Axlsx::validate_boolean v; @strike = v end def test_strike assert_raise(ArgumentError) { @item.strike = -7 } assert_nothing_raised { @item.strike = true } assert_equal(@item.strike, true) end - # def outline=(v) Axlsx::validate_boolean v; @outline = v end + # def outline=(v) Axlsx::validate_boolean v; @outline = v end def test_outline assert_raise(ArgumentError) { @item.outline = -7 } assert_nothing_raised { @item.outline = true } assert_equal(@item.outline, true) end - # def shadow=(v) Axlsx::validate_boolean v; @shadow = v end + # def shadow=(v) Axlsx::validate_boolean v; @shadow = v end def test_shadow assert_raise(ArgumentError) { @item.shadow = -7 } assert_nothing_raised { @item.shadow = true } assert_equal(@item.shadow, true) end - # def condense=(v) Axlsx::validate_boolean v; @condense = v end + # def condense=(v) Axlsx::validate_boolean v; @condense = v end def test_condense assert_raise(ArgumentError) { @item.condense = -7 } assert_nothing_raised { @item.condense = true } assert_equal(@item.condense, true) end - # def extend=(v) Axlsx::validate_boolean v; @extend = v end + # def extend=(v) Axlsx::validate_boolean v; @extend = v end def test_extend assert_raise(ArgumentError) { @item.extend = -7 } assert_nothing_raised { @item.extend = true } assert_equal(@item.extend, true) end - # def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end + # def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end def test_color assert_raise(ArgumentError) { @item.color = -7 } - assert_nothing_raised { @item.color = Axlsx::Color.new(:rgb=>"00000000") } + assert_nothing_raised { @item.color = Axlsx::Color.new(:rgb => "00000000") } assert(@item.color.is_a?(Axlsx::Color)) end - # def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end + # def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end def test_sz assert_raise(ArgumentError) { @item.sz = -7 } assert_nothing_raised { @item.sz = 5 } assert_equal(@item.sz, 5) end - end diff --git a/test/stylesheet/tc_gradient_fill.rb b/test/stylesheet/tc_gradient_fill.rb index 546941d7..3950fcf7 100644 --- a/test/stylesheet/tc_gradient_fill.rb +++ b/test/stylesheet/tc_gradient_fill.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestGradientFill < Test::Unit::TestCase - def setup @item = Axlsx::GradientFill.new end @@ -9,7 +8,6 @@ class TestGradientFill < Test::Unit::TestCase def teardown end - def test_initialiation assert_equal(@item.type, :linear) assert_equal(@item.degree, nil) @@ -57,7 +55,7 @@ class TestGradientFill < Test::Unit::TestCase end def test_stop - @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb=>"00000000"), 0.5) + @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "00000000"), 0.5) assert(@item.stop.size == 1) assert(@item.stop.last.is_a?(Axlsx::GradientStop)) end diff --git a/test/stylesheet/tc_gradient_stop.rb b/test/stylesheet/tc_gradient_stop.rb index f1cf5183..6dc140e0 100644 --- a/test/stylesheet/tc_gradient_stop.rb +++ b/test/stylesheet/tc_gradient_stop.rb @@ -1,15 +1,13 @@ require 'tc_helper.rb' class TestGradientStop < Test::Unit::TestCase - def setup - @item = Axlsx::GradientStop.new(Axlsx::Color.new(:rgb=>"FFFF0000"), 1.0) + @item = Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "FFFF0000"), 1.0) end def teardown end - def test_initialiation assert_equal(@item.color.rgb, "FFFF0000") assert_equal(@item.position, 1.0) @@ -23,9 +21,8 @@ class TestGradientStop < Test::Unit::TestCase def test_color assert_raise(ArgumentError) { @item.color = nil } - color = Axlsx::Color.new(:rgb=>"FF0000FF") + color = Axlsx::Color.new(:rgb => "FF0000FF") @item.color = color assert_equal(@item.color.rgb, "FF0000FF") end - end diff --git a/test/stylesheet/tc_num_fmt.rb b/test/stylesheet/tc_num_fmt.rb index b5b73929..7c34be28 100644 --- a/test/stylesheet/tc_num_fmt.rb +++ b/test/stylesheet/tc_num_fmt.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestNumFmt < Test::Unit::TestCase - def setup @item = Axlsx::NumFmt.new end @@ -9,7 +8,6 @@ class TestNumFmt < Test::Unit::TestCase def teardown end - def test_initialiation assert_equal(@item.numFmtId, 0) assert_equal(@item.formatCode, "") @@ -26,5 +24,4 @@ class TestNumFmt < Test::Unit::TestCase assert_nothing_raised { @item.formatCode = "0" } assert_equal(@item.formatCode, "0") end - end diff --git a/test/stylesheet/tc_pattern_fill.rb b/test/stylesheet/tc_pattern_fill.rb index 3895cffb..1126e919 100644 --- a/test/stylesheet/tc_pattern_fill.rb +++ b/test/stylesheet/tc_pattern_fill.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestPatternFill < Test::Unit::TestCase - def setup @item = Axlsx::PatternFill.new end @@ -9,7 +8,6 @@ class TestPatternFill < Test::Unit::TestCase def teardown end - def test_initialiation assert_equal(@item.patternType, :none) assert_equal(@item.bgColor, nil) @@ -33,9 +31,9 @@ class TestPatternFill < Test::Unit::TestCase assert_nothing_raised { @item.patternType = :lightUp } assert_equal(@item.patternType, :lightUp) end - + def test_to_xml_string - @item = Axlsx::PatternFill.new :bgColor => Axlsx::Color.new(:rgb => "FF0000"), :fgColor => Axlsx::Color.new(:rgb=>"00FF00") + @item = Axlsx::PatternFill.new :bgColor => Axlsx::Color.new(:rgb => "FF0000"), :fgColor => Axlsx::Color.new(:rgb => "00FF00") doc = Nokogiri::XML(@item.to_xml_string) assert(doc.xpath('//color[@rgb="FFFF0000"]')) assert(doc.xpath('//color[@rgb="FF00FF00"]')) diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index 503068c0..1598a658 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -4,6 +4,7 @@ class TestStyles < Test::Unit::TestCase def setup @styles = Axlsx::Styles.new end + def teardown end @@ -20,10 +21,10 @@ class TestStyles < Test::Unit::TestCase def test_add_style_border_hash border_count = @styles.borders.size - @styles.add_style :border => {:style => :thin, :color => "FFFF0000"} + @styles.add_style :border => { :style => :thin, :color => "FFFF0000" } assert_equal(@styles.borders.size, border_count + 1) assert_equal(@styles.borders.last.prs.last.color.rgb, "FFFF0000") - assert_raise(ArgumentError) { @styles.add_style :border => {:color => "FFFF0000"} } + assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" } } assert_equal @styles.borders.last.prs.size, 4 end @@ -31,23 +32,23 @@ class TestStyles < Test::Unit::TestCase prev_border_count = @styles.borders.size borders_array = [ - {:style => :thin, :color => "DDDDDD"}, - {:edges => [:top], :style => :thin, :color => "000000"}, - {:edges => [:bottom], :style => :thick, :color => "FF0000"}, - {:edges => [:left], :style => :dotted, :color => "FFFF00"}, - {:edges => [:right], :style => :dashed, :color => "FFFFFF"}, - {:style => :thick, :color => "CCCCCC"}, + { :style => :thin, :color => "DDDDDD" }, + { :edges => [:top], :style => :thin, :color => "000000" }, + { :edges => [:bottom], :style => :thick, :color => "FF0000" }, + { :edges => [:left], :style => :dotted, :color => "FFFF00" }, + { :edges => [:right], :style => :dashed, :color => "FFFFFF" }, + { :style => :thick, :color => "CCCCCC" } ] @styles.add_style(border: borders_array) - assert_equal(@styles.borders.size, (prev_border_count+1)) + assert_equal(@styles.borders.size, (prev_border_count + 1)) current_border = @styles.borders.last - + borders_array.each do |b_opts| if b_opts[:edges] - border_pr = current_border.prs.detect{|x| x.name == b_opts[:edges].first } + border_pr = current_border.prs.detect { |x| x.name == b_opts[:edges].first } assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}") end end @@ -61,40 +62,40 @@ class TestStyles < Test::Unit::TestCase end def test_do_not_alter_options_in_add_style - #This should test all options, but for now - just the bits that we know caused some pain - options = { :border => { :style => :thin, :color =>"FF000000" } } + # This should test all options, but for now - just the bits that we know caused some pain + options = { :border => { :style => :thin, :color => "FF000000" } } @styles.add_style options assert_equal options[:border][:style], :thin, 'thin style is stil in option' assert_equal options[:border][:color], "FF000000", 'color is stil in option' end def test_parse_num_fmt - f_code = {:format_code => "YYYY/MM"} - num_fmt = {:num_fmt => 5} + f_code = { :format_code => "YYYY/MM" } + num_fmt = { :num_fmt => 5 } assert_equal(@styles.parse_num_fmt_options, nil, 'noop if neither :format_code or :num_fmt exist') - max = @styles.numFmts.map{ |nf| nf.numFmtId }.max + max = @styles.numFmts.map { |nf| nf.numFmtId }.max @styles.parse_num_fmt_options(f_code) assert_equal(@styles.numFmts.last.numFmtId, max + 1, "new numfmts gets next available id") assert(@styles.parse_num_fmt_options(num_fmt).is_a?(Integer), "Should return the provided num_fmt if not dxf") - assert(@styles.parse_num_fmt_options(num_fmt.merge({:type => :dxf})).is_a?(Axlsx::NumFmt), "Makes a new NumFmt if dxf") + assert(@styles.parse_num_fmt_options(num_fmt.merge({ :type => :dxf })).is_a?(Axlsx::NumFmt), "Makes a new NumFmt if dxf") end def test_parse_border_options_hash_required_keys assert_raise(ArgumentError, "Require color key") { @styles.parse_border_options(:border => { :style => :thin }) } assert_raise(ArgumentError, "Require style key") { @styles.parse_border_options(:border => { :color => "FF0d0d0d" }) } - assert_nothing_raised { @styles.parse_border_options(:border => { :style => :thin, :color => "FF000000"} ) } + assert_nothing_raised { @styles.parse_border_options(:border => { :style => :thin, :color => "FF000000" }) } end def test_parse_border_basic_options - b_opts = {:border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } } + b_opts = { :border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } } b = @styles.parse_border_options b_opts assert(b.is_a? Integer) - assert_equal(@styles.parse_border_options(b_opts.merge({:type => :dxf})).class,Axlsx::Border) + assert_equal(@styles.parse_border_options(b_opts.merge({ :type => :dxf })).class, Axlsx::Border) assert(@styles.borders.last.diagonalUp == 1, "border options are passed in to the initializer") end def test_parse_border_options_edges - b_opts = {:border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } } + b_opts = { :border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } } @styles.parse_border_options b_opts b = @styles.borders.last left = b.prs.select { |bpr| bpr.name == :left }[0] @@ -105,10 +106,10 @@ class TestStyles < Test::Unit::TestCase assert_equal(bottom, nil, "unspecified bottom edge should not be created") assert(left.is_a?(Axlsx::BorderPr), "specified left edge is set") assert(right.is_a?(Axlsx::BorderPr), "specified right edge is set") - assert_equal(left.style,right.style, "edge parts have the same style") + assert_equal(left.style, right.style, "edge parts have the same style") assert_equal(left.style, :thick, "the style is THICK") - assert_equal(right.color.rgb,left.color.rgb, "edge parts are colors are the same") - assert_equal(right.color.rgb,"FFDADADA", "edge color rgb is correct") + assert_equal(right.color.rgb, left.color.rgb, "edge parts are colors are the same") + assert_equal(right.color.rgb, "FFDADADA", "edge color rgb is correct") end def test_parse_border_options_noop @@ -117,11 +118,11 @@ class TestStyles < Test::Unit::TestCase def test_parse_border_options_integer_xf assert_equal(@styles.parse_border_options(:border => 1), 1) - assert_raise(ArgumentError, "unknown border index") {@styles.parse_border_options(:border => 100) } + assert_raise(ArgumentError, "unknown border index") { @styles.parse_border_options(:border => 100) } end def test_parse_border_options_integer_dxf - b_opts = { :border => { :edges => [:left, :right], :color => "FFFFFFFF", :style=> :thick } } + b_opts = { :border => { :edges => [:left, :right], :color => "FFFFFFFF", :style => :thick } } b = @styles.parse_border_options(b_opts) b2 = @styles.parse_border_options(:border => b, :type => :dxf) assert(b2.is_a?(Axlsx::Border), "Cloned existing border object") @@ -139,7 +140,7 @@ class TestStyles < Test::Unit::TestCase original_attributes = Axlsx.instance_values_for(original) assert_equal(1, created.b) assert_equal(99, created.sz) - copied = original_attributes.reject{ |key, value| %w(b sz).include? key } + copied = original_attributes.reject { |key, value| %w(b sz).include? key } instance_vals = Axlsx.instance_values_for(created) copied.each do |key, value| assert_equal(instance_vals[key], value) @@ -161,8 +162,8 @@ class TestStyles < Test::Unit::TestCase :font_name => "woot font" } assert_equal(@styles.parse_font_options {}, nil, "noop if no font keys are set") - assert(@styles.parse_font_options(:b=>1).is_a?(Integer), "return index of font if not :dxf type") - assert_equal(@styles.parse_font_options(:b=>1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type") + assert(@styles.parse_font_options(:b => 1).is_a?(Integer), "return index of font if not :dxf type") + assert_equal(@styles.parse_font_options(:b => 1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type") f = @styles.parse_font_options(options.merge(:type => :dxf)) color = options.delete(:fg_color) @@ -191,15 +192,15 @@ class TestStyles < Test::Unit::TestCase font_count = @styles.fonts.size xf_count = @styles.cellXfs.size - @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :num_fmt=>Axlsx::NUM_FMT_PERCENT, :alignment=>{:horizontal=>:left}, :border=>Axlsx::STYLE_THIN_BORDER, :hidden=>true, :locked=>true - assert_equal(@styles.fills.size, fill_count+1) - assert_equal(@styles.fonts.size, font_count+1) - assert_equal(@styles.cellXfs.size, xf_count+1) + @styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :num_fmt => Axlsx::NUM_FMT_PERCENT, :alignment => { :horizontal => :left }, :border => Axlsx::STYLE_THIN_BORDER, :hidden => true, :locked => true + assert_equal(@styles.fills.size, fill_count + 1) + assert_equal(@styles.fonts.size, font_count + 1) + assert_equal(@styles.cellXfs.size, xf_count + 1) xf = @styles.cellXfs.last - assert_equal(xf.fillId, (@styles.fills.size-1), "points to the last created fill") + assert_equal(xf.fillId, (@styles.fills.size - 1), "points to the last created fill") assert_equal(@styles.fills.last.fill_type.fgColor.rgb, "FF000000", "fill created with color") - assert_equal(xf.fontId, (@styles.fonts.size-1), "points to the last created font") + assert_equal(xf.fontId, (@styles.fonts.size - 1), "points to the last created font") assert_equal(@styles.fonts.last.sz, 13, "font sz applied") assert_equal(@styles.fonts.last.color.rgb, "FFFFFFFF", "font color applied") @@ -212,19 +213,18 @@ class TestStyles < Test::Unit::TestCase assert_equal(xf.protection.locked, true, "cell locking set") assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 } - assert_equal(xf.applyProtection, true, "protection applied") assert_equal(xf.applyBorder, true, "border applied") - assert_equal(xf.applyNumberFormat,true, "number format applied") + assert_equal(xf.applyNumberFormat, true, "number format applied") assert_equal(xf.applyAlignment, true, "alignment applied") end def test_basic_add_style_dxf border_count = @styles.borders.size - @styles.add_style :border => {:style => :thin, :color => "FFFF0000"}, :type => :dxf + @styles.add_style :border => { :style => :thin, :color => "FFFF0000" }, :type => :dxf assert_equal(@styles.borders.size, border_count, "styles borders not affected") assert_equal(@styles.dxfs.last.border.prs.last.color.rgb, "FFFF0000") - assert_raise(ArgumentError) { @styles.add_style :border => {:color => "FFFF0000"}, :type => :dxf } + assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" }, :type => :dxf } assert_equal @styles.borders.last.prs.size, 4 end @@ -233,8 +233,8 @@ class TestStyles < Test::Unit::TestCase font_count = @styles.fonts.size dxf_count = @styles.dxfs.size - style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf - assert_equal(@styles.dxfs.size, dxf_count+1) + style = @styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf + assert_equal(@styles.dxfs.size, dxf_count + 1) assert_equal(0, style, "returns the zero-based dxfId") dxf = @styles.dxfs.last @@ -255,9 +255,9 @@ class TestStyles < Test::Unit::TestCase def test_multiple_dxf # add a second style - style = @styles.add_style :bg_color=>"00000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf + style = @styles.add_style :bg_color => "00000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf assert_equal(0, style, "returns the first dxfId") - style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf + style = @styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf assert_equal(1, style, "returns the second dxfId") end @@ -289,7 +289,7 @@ class TestStyles < Test::Unit::TestCase def test_border_top_without_border_regression ### https://github.com/axlsx-styler-gem/axlsx_styler/issues/31 - + borders = { top: { style: :double, color: '0000FF' }, right: { style: :thick, color: 'FF0000' }, @@ -302,9 +302,8 @@ class TestStyles < Test::Unit::TestCase current_border = @styles.borders.last - border_pr = current_border.prs.detect{|x| x.name == edge } + border_pr = current_border.prs.detect { |x| x.name == edge } assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}") end - end end diff --git a/test/stylesheet/tc_table_style.rb b/test/stylesheet/tc_table_style.rb index f58a7a0d..f86cc54c 100644 --- a/test/stylesheet/tc_table_style.rb +++ b/test/stylesheet/tc_table_style.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestTableStyle < Test::Unit::TestCase - def setup @item = Axlsx::TableStyle.new "fisher" end diff --git a/test/stylesheet/tc_table_style_element.rb b/test/stylesheet/tc_table_style_element.rb index 9ef54e2f..021d4fca 100644 --- a/test/stylesheet/tc_table_style_element.rb +++ b/test/stylesheet/tc_table_style_element.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestTableStyleElement < Test::Unit::TestCase - def setup @item = Axlsx::TableStyleElement.new end @@ -36,10 +35,10 @@ class TestTableStyleElement < Test::Unit::TestCase assert_nothing_raised { @item.dxfId = 7 } assert_equal(@item.dxfId, 7) end - + def test_to_xml_string doc = Nokogiri::XML(@item.to_xml_string) - @item.type = :headerRow + @item.type = :headerRow assert(doc.xpath("//tableStyleElement[@type='#{@item.type.to_s}']")) end end diff --git a/test/stylesheet/tc_table_styles.rb b/test/stylesheet/tc_table_styles.rb index cc8da9d5..751874b1 100644 --- a/test/stylesheet/tc_table_styles.rb +++ b/test/stylesheet/tc_table_styles.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestTableStyles < Test::Unit::TestCase - def setup @item = Axlsx::TableStyles.new end @@ -25,5 +24,4 @@ class TestTableStyles < Test::Unit::TestCase assert_nothing_raised { @item.defaultPivotStyle = "anyones guess" } assert_equal(@item.defaultPivotStyle, "anyones guess") end - end diff --git a/test/stylesheet/tc_xf.rb b/test/stylesheet/tc_xf.rb index fdaef970..00e2a8a3 100644 --- a/test/stylesheet/tc_xf.rb +++ b/test/stylesheet/tc_xf.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestXf < Test::Unit::TestCase - def setup @item = Axlsx::Xf.new end @@ -116,5 +115,4 @@ class TestXf < Test::Unit::TestCase assert_nothing_raised { @item.applyProtection = false } assert_equal(@item.applyProtection, false) end - end diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb index 3903fc42..c214f8e2 100644 --- a/test/tc_axlsx.rb +++ b/test/tc_axlsx.rb @@ -1,9 +1,9 @@ require 'tc_helper.rb' class TestAxlsx < Test::Unit::TestCase - def setup_wide - @wide_test_points = { "A3" => 0, + @wide_test_points = { + "A3" => 0, "Z3" => 25, "B3" => 1, "AA3" => 1 * 26 + 0, @@ -22,7 +22,6 @@ class TestAxlsx < Test::Unit::TestCase assert_equal false, Axlsx.trust_input end - def test_trust_input_can_be_set_to_true # Class variables like this are not reset between test runs, so we have # to save and restore the original value manually. @@ -33,6 +32,7 @@ class TestAxlsx < Test::Unit::TestCase Axlsx.trust_input = old end + def test_cell_range_relative p = Axlsx::Package.new ws = p.workbook.add_worksheet @@ -64,7 +64,7 @@ class TestAxlsx < Test::Unit::TestCase def test_name_to_indices setup_wide @wide_test_points.each do |key, value| - assert_equal(Axlsx.name_to_indices(key), [value,2]) + assert_equal(Axlsx.name_to_indices(key), [value, 2]) end end @@ -106,9 +106,9 @@ class TestAxlsx < Test::Unit::TestCase assert_equal(sanitized_str, legit_str, 'should preserve value') assert_equal(sanitized_str.object_id, legit_str.object_id, 'should preserve object') end - + class InstanceValuesSubject - def initialize(args={}) + def initialize(args = {}) args.each do |key, v| instance_variable_set("@#{key}".to_sym, v) end @@ -120,24 +120,23 @@ class TestAxlsx < Test::Unit::TestCase assert_equal({}, Axlsx.instance_values_for(empty), 'should generate with no ivars') single = InstanceValuesSubject.new(a: 2) - assert_equal({"a" => 2}, Axlsx.instance_values_for(single), 'should generate for a single ivar') + assert_equal({ "a" => 2 }, Axlsx.instance_values_for(single), 'should generate for a single ivar') double = InstanceValuesSubject.new(a: 2, b: "c") - assert_equal({"a" => 2, "b" => "c"}, Axlsx.instance_values_for(double), 'should generate for multiple ivars') + assert_equal({ "a" => 2, "b" => "c" }, Axlsx.instance_values_for(double), 'should generate for multiple ivars') inner_obj = Object.new complex = InstanceValuesSubject.new(obj: inner_obj) - assert_equal({"obj" => inner_obj}, Axlsx.instance_values_for(complex), 'should pass value of ivar directly') + assert_equal({ "obj" => inner_obj }, Axlsx.instance_values_for(complex), 'should pass value of ivar directly') nil_subject = InstanceValuesSubject.new(nil_obj: nil) - assert_equal({"nil_obj" => nil}, Axlsx.instance_values_for(nil_subject), 'should return nil ivars') + assert_equal({ "nil_obj" => nil }, Axlsx.instance_values_for(nil_subject), 'should return nil ivars') end def test_hash_deep_merge - h1 = {foo: {bar: true}} - h2 = {foo: {baz: true}} - assert_equal({foo: {baz: true}}, h1.merge(h2)) - assert_equal({foo: {bar: true, baz: true}}, Axlsx.hash_deep_merge(h1, h2)) + h1 = { foo: { bar: true } } + h2 = { foo: { baz: true } } + assert_equal({ foo: { baz: true } }, h1.merge(h2)) + assert_equal({ foo: { bar: true, baz: true } }, Axlsx.hash_deep_merge(h1, h2)) end - end diff --git a/test/tc_package.rb b/test/tc_package.rb index 0788d029..cc40a6e0 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 require 'tc_helper.rb' require 'support/capture_warnings' @@ -40,8 +39,8 @@ class TestPackage < Test::Unit::TestCase vs.add_selection(:bottom_right, { :active_cell => 'I57', :sqref => 'I57' }) end - ws.add_chart(Axlsx::Pie3DChart, :title => "これは?", :start_at => [0,3]) do |chart| - chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"] + ws.add_chart(Axlsx::Pie3DChart, :title => "これは?", :start_at => [0, 3]) do |chart| + chart.add_series :data => [1, 2, 3], :labels => ["a", "b", "c"] chart.d_lbls.show_val = true chart.d_lbls.d_lbl_pos = :outEnd chart.d_lbls.show_percent = true @@ -53,33 +52,33 @@ class TestPackage < Test::Unit::TestCase end ws.add_chart(Axlsx::Bar3DChart, :title => 'bar chart') do |chart| - chart.add_series :data => [1,4,5], :labels => %w(A B C) + chart.add_series :data => [1, 4, 5], :labels => %w(A B C) chart.d_lbls.show_percent = true end ws.add_chart(Axlsx::ScatterChart, :title => 'scat man') do |chart| - chart.add_series :xData => [1,2,3,4], :yData => [4,3,2,1] + chart.add_series :xData => [1, 2, 3, 4], :yData => [4, 3, 2, 1] chart.d_lbls.show_val = true end ws.add_chart(Axlsx::BubbleChart, :title => 'bubble chart') do |chart| - chart.add_series :xData => [1,2,3,4], :yData => [1,3,2,4] + chart.add_series :xData => [1, 2, 3, 4], :yData => [1, 3, 2, 4] chart.d_lbls.show_val = true end @fname = 'axlsx_test_serialization.xlsx' img = File.expand_path('../fixtures/image1.jpeg', __FILE__) - ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image| - image.width=720 - image.height=666 + ws.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink => "http://axlsx.blogspot.com") do |image| + image.width = 720 + image.height = 666 image.hyperlink.tooltip = "Labeled Link" image.start_at 5, 5 image.end_at 10, 10 end ws.add_image :image_src => File.expand_path('../fixtures/image1.gif', __FILE__) do |image| image.start_at 0, 20 - image.width=360 - image.height=333 + image.width = 360 + image.height = 333 end ws.add_image :image_src => File.expand_path('../fixtures/image1.png', __FILE__) do |image| image.start_at 9, 20 @@ -91,7 +90,6 @@ class TestPackage < Test::Unit::TestCase ws.add_pivot_table 'G5:G6', 'A1:B3' ws.add_page_break "B2" - end def test_use_autowidth @@ -101,18 +99,18 @@ class TestPackage < Test::Unit::TestCase def test_core_accessor assert_equal(@package.core, Axlsx.instance_values_for(@package)["core"]) - assert_raise(NoMethodError) {@package.core = nil } + assert_raise(NoMethodError) { @package.core = nil } end def test_app_accessor assert_equal(@package.app, Axlsx.instance_values_for(@package)["app"]) - assert_raise(NoMethodError) {@package.app = nil } + assert_raise(NoMethodError) { @package.app = nil } end def test_use_shared_strings assert_equal(@package.use_shared_strings, nil) - assert_raise(ArgumentError) {@package.use_shared_strings 9} - assert_nothing_raised {@package.use_shared_strings = true} + assert_raise(ArgumentError) { @package.use_shared_strings 9 } + assert_nothing_raised { @package.use_shared_strings = true } assert_equal(@package.use_shared_strings, @package.workbook.use_shared_strings) end @@ -179,7 +177,7 @@ class TestPackage < Test::Unit::TestCase def assert_zip_file_matches_package(fname, package) zf = Zip::File.open(fname) - package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } + package.send(:parts).each { |part| zf.get_entry(part[:entry]) } end def assert_created_with_rubyzip(fname, package) @@ -251,29 +249,28 @@ class TestPackage < Test::Unit::TestCase def test_parts p = @package.send(:parts) - #all parts have an entry - assert_equal(p.select{ |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /docProps\/core\.xml/ }.size, 1, "core missing") - assert_equal(p.select{ |part| part[:entry] =~ /docProps\/app\.xml/ }.size, 1, "app missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/_rels\/workbook\.xml\.rels/ }.size, 1, "workbook rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/workbook\.xml/ }.size, 1, "workbook missing") - assert_equal(p.select{ |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, 1, "content types missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/styles\.xml/ }.size, 1, "styles missin") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/_rels\/drawing\d\.xml\.rels/ }.size, @package.workbook.drawings.size, "one or more drawing rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/drawings\/drawing\d\.xml/ }.size, @package.workbook.drawings.size, "one or more drawings missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/charts\/chart\d\.xml/ }.size, @package.workbook.charts.size, "one or more charts missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/sheet\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/worksheets\/_rels\/sheet\d\.xml\.rels/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/comments\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/pivotTables\/pivotTable\d\.xml/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/pivotTables\/_rels\/pivotTable\d\.xml.rels/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables rels missing") - assert_equal(p.select{ |part| part[:entry] =~ /xl\/pivotCache\/pivotCacheDefinition\d\.xml/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables missing") - - - #no mystery parts + # all parts have an entry + assert_equal(p.select { |part| part[:entry] =~ /_rels\/\.rels/ }.size, 1, "rels missing") + assert_equal(p.select { |part| part[:entry] =~ /docProps\/core\.xml/ }.size, 1, "core missing") + assert_equal(p.select { |part| part[:entry] =~ /docProps\/app\.xml/ }.size, 1, "app missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/_rels\/workbook\.xml\.rels/ }.size, 1, "workbook rels missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/workbook\.xml/ }.size, 1, "workbook missing") + assert_equal(p.select { |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, 1, "content types missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/styles\.xml/ }.size, 1, "styles missin") + assert_equal(p.select { |part| part[:entry] =~ /xl\/drawings\/_rels\/drawing\d\.xml\.rels/ }.size, @package.workbook.drawings.size, "one or more drawing rels missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/drawings\/drawing\d\.xml/ }.size, @package.workbook.drawings.size, "one or more drawings missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/charts\/chart\d\.xml/ }.size, @package.workbook.charts.size, "one or more charts missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/worksheets\/sheet\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/worksheets\/_rels\/sheet\d\.xml\.rels/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/comments\d\.xml/ }.size, @package.workbook.worksheets.size, "one or more sheet rels missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/pivotTables\/pivotTable\d\.xml/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/pivotTables\/_rels\/pivotTable\d\.xml.rels/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables rels missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/pivotCache\/pivotCacheDefinition\d\.xml/ }.size, @package.workbook.worksheets.first.pivot_tables.size, "one or more pivot tables missing") + + # no mystery parts assert_equal(25, p.size) - #sorted for correct MIME detection + # sorted for correct MIME detection assert_equal("[Content_Types].xml", p[0][:entry], "first entry should be `[Content_Types].xml`") assert_equal("_rels/.rels", p[1][:entry], "second entry should be `_rels/.rels`") assert_match(/\Axl\//, p[2][:entry], "third entry should begin with `xl/`") @@ -281,9 +278,9 @@ class TestPackage < Test::Unit::TestCase def test_shared_strings_requires_part @package.use_shared_strings = true - @package.to_stream #ensure all cell_serializer paths are hit + @package.to_stream # ensure all cell_serializer paths are hit p = @package.send(:parts) - assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing") + assert_equal(p.select { |part| part[:entry] =~ /xl\/sharedStrings.xml/ }.size, 1, "shared strings table missing") end def test_workbook_is_a_workbook @@ -308,8 +305,8 @@ class TestPackage < Test::Unit::TestCase end def test_name_to_indices - assert(Axlsx::name_to_indices('A1') == [0,0]) - assert(Axlsx::name_to_indices('A100') == [0,99], 'needs to axcept rows that contain 0') + assert(Axlsx::name_to_indices('A1') == [0, 0]) + assert(Axlsx::name_to_indices('A100') == [0, 99], 'needs to axcept rows that contain 0') end def test_to_stream diff --git a/test/util/tc_simple_typed_list.rb b/test/util/tc_simple_typed_list.rb index 72bd6246..fc1ab0a2 100644 --- a/test/util/tc_simple_typed_list.rb +++ b/test/util/tc_simple_typed_list.rb @@ -9,14 +9,14 @@ class TestSimpleTypedList < Test::Unit::TestCase def test_type_is_a_class_or_array_of_class assert_nothing_raised { Axlsx::SimpleTypedList.new Integer } - assert_nothing_raised { Axlsx::SimpleTypedList.new [Integer,String] } + assert_nothing_raised { Axlsx::SimpleTypedList.new [Integer, String] } assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new } assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new "1" } assert_raise(ArgumentError) { Axlsx::SimpleTypedList.new [Integer, "Class"] } end def test_indexed_based_assignment - #should not allow nil assignment + # should not allow nil assignment assert_raise(ArgumentError) { @list[0] = nil } assert_raise(ArgumentError) { @list[0] = "1" } assert_nothing_raised { @list[0] = 1 } @@ -29,20 +29,20 @@ class TestSimpleTypedList < Test::Unit::TestCase end def test_concat_should_return_index - assert( @list.size == 0 ) - assert( @list << 1 == 0 ) - assert( @list << 2 == 1 ) + assert(@list.size == 0) + assert(@list << 1 == 0) + assert(@list << 2 == 1) @list.delete_at 0 - assert( @list << 3 == 1 ) - assert( @list.index(2) == 0 ) + assert(@list << 3 == 1) + assert(@list.index(2) == 0) end def test_push_should_return_index - assert( @list.push(1) == 0 ) - assert( @list.push(2) == 1 ) + assert(@list.push(1) == 0) + assert(@list.push(2) == 1) @list.delete_at 0 - assert( @list.push(3) == 1 ) - assert( @list.index(2) == 0 ) + assert(@list.push(3) == 1) + assert(@list.index(2) == 0) end def test_locking @@ -57,11 +57,11 @@ class TestSimpleTypedList < Test::Unit::TestCase @list.push 4 assert_nothing_raised { @list.delete_at 3 } @list.unlock - #ignore garbage + # ignore garbage assert_nothing_raised { @list.delete 0 } assert_nothing_raised { @list.delete 9 } end - + def test_delete @list.push 1 assert(@list.size == 1) @@ -72,6 +72,6 @@ class TestSimpleTypedList < Test::Unit::TestCase def test_equality @list.push 1 @list.push 2 - assert_equal(@list.to_ary, [1,2]) + assert_equal(@list.to_ary, [1, 2]) end end diff --git a/test/util/tc_validators.rb b/test/util/tc_validators.rb index d6936496..7df2e41b 100644 --- a/test/util/tc_validators.rb +++ b/test/util/tc_validators.rb @@ -2,75 +2,76 @@ require 'tc_helper.rb' class TestValidators < Test::Unit::TestCase def setup end + def teardown end def test_validators - #unsigned_int + # unsigned_int assert_nothing_raised { Axlsx.validate_unsigned_int 1 } assert_nothing_raised { Axlsx.validate_unsigned_int(+1) } - assert_raise(ArgumentError) { Axlsx.validate_unsigned_int(-1)} + assert_raise(ArgumentError) { Axlsx.validate_unsigned_int(-1) } assert_raise(ArgumentError) { Axlsx.validate_unsigned_int('1') } - #int + # int assert_nothing_raised { Axlsx.validate_int(1) } assert_nothing_raised { Axlsx.validate_int(-1) } - assert_raise(ArgumentError) { Axlsx.validate_int('a')} + assert_raise(ArgumentError) { Axlsx.validate_int('a') } assert_raise(ArgumentError) { Axlsx.validate_int(Array) } - #boolean (as 0 or 1, :true, :false, true, false, or "true," "false") - [0,1,:true, :false, true, false, "true", "false"].each do |v| + # boolean (as 0 or 1, :true, :false, true, false, or "true," "false") + [0, 1, :true, :false, true, false, "true", "false"].each do |v| assert_nothing_raised { Axlsx.validate_boolean 0 } end assert_raise(ArgumentError) { Axlsx.validate_boolean 2 } - #string + # string assert_nothing_raised { Axlsx.validate_string "1" } assert_raise(ArgumentError) { Axlsx.validate_string 2 } assert_raise(ArgumentError) { Axlsx.validate_string false } - #float + # float assert_nothing_raised { Axlsx.validate_float 1.0 } assert_raise(ArgumentError) { Axlsx.validate_float 2 } assert_raise(ArgumentError) { Axlsx.validate_float false } - #pattern_type + # pattern_type assert_nothing_raised { Axlsx.validate_pattern_type :none } assert_raise(ArgumentError) { Axlsx.validate_pattern_type "none" } assert_raise(ArgumentError) { Axlsx.validate_pattern_type "crazy_pattern" } assert_raise(ArgumentError) { Axlsx.validate_pattern_type false } - #gradient_type + # gradient_type assert_nothing_raised { Axlsx.validate_gradient_type :path } assert_raise(ArgumentError) { Axlsx.validate_gradient_type nil } assert_raise(ArgumentError) { Axlsx.validate_gradient_type "fractal" } assert_raise(ArgumentError) { Axlsx.validate_gradient_type false } - #horizontal alignment + # horizontal alignment assert_nothing_raised { Axlsx.validate_horizontal_alignment :general } assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment nil } assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment "wavy" } assert_raise(ArgumentError) { Axlsx.validate_horizontal_alignment false } - #vertical alignment + # vertical alignment assert_nothing_raised { Axlsx.validate_vertical_alignment :top } assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment nil } assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment "dynamic" } assert_raise(ArgumentError) { Axlsx.validate_vertical_alignment false } - #contentType + # contentType assert_nothing_raised { Axlsx.validate_content_type Axlsx::WORKBOOK_CT } assert_raise(ArgumentError) { Axlsx.validate_content_type nil } assert_raise(ArgumentError) { Axlsx.validate_content_type "http://some.url" } assert_raise(ArgumentError) { Axlsx.validate_content_type false } - #relationshipType + # relationshipType assert_nothing_raised { Axlsx.validate_relationship_type Axlsx::WORKBOOK_R } assert_raise(ArgumentError) { Axlsx.validate_relationship_type nil } assert_raise(ArgumentError) { Axlsx.validate_relationship_type "http://some.url" } assert_raise(ArgumentError) { Axlsx.validate_relationship_type false } - #number_with_unit + # number_with_unit assert_nothing_raised { Axlsx.validate_number_with_unit "210mm" } assert_nothing_raised { Axlsx.validate_number_with_unit "8.5in" } assert_nothing_raised { Axlsx.validate_number_with_unit "29.7cm" } @@ -83,7 +84,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "mm" } assert_raise(ArgumentError) { Axlsx.validate_number_with_unit "-29cm" } - #scale_10_400 + # scale_10_400 assert_nothing_raised { Axlsx.validate_scale_10_400 10 } assert_nothing_raised { Axlsx.validate_scale_10_400 100 } assert_nothing_raised { Axlsx.validate_scale_10_400 400 } @@ -92,7 +93,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 } assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" } - #scale_0_10_400 + # scale_0_10_400 assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 } assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 } assert_nothing_raised { Axlsx.validate_scale_0_10_400 100 } @@ -102,7 +103,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 } assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" } - #page_orientation + # page_orientation assert_nothing_raised { Axlsx.validate_page_orientation :default } assert_nothing_raised { Axlsx.validate_page_orientation :landscape } assert_nothing_raised { Axlsx.validate_page_orientation :portrait } @@ -110,7 +111,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 } assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" } - #data_validation_error_style + # data_validation_error_style [:information, :stop, :warning].each do |sym| assert_nothing_raised { Axlsx.validate_data_validation_error_style sym } end @@ -118,7 +119,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' } assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 } - #data_validation_operator + # data_validation_operator [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym| assert_nothing_raised { Axlsx.validate_data_validation_operator sym } end @@ -126,7 +127,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' } assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 } - #data_validation_type + # data_validation_type [:custom, :data, :decimal, :list, :none, :textLength, :date, :time, :whole].each do |sym| assert_nothing_raised { Axlsx.validate_data_validation_type sym } end @@ -134,7 +135,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' } assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 } - #sheet_view_type + # sheet_view_type [:normal, :page_break_preview, :page_layout].each do |sym| assert_nothing_raised { Axlsx.validate_sheet_view_type sym } end @@ -142,7 +143,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' } assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 } - #active_pane_type + # active_pane_type [:bottom_left, :bottom_right, :top_left, :top_right].each do |sym| assert_nothing_raised { Axlsx.validate_pane_type sym } end @@ -150,7 +151,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' } assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 } - #split_state_type + # split_state_type [:frozen, :frozen_split, :split].each do |sym| assert_nothing_raised { Axlsx.validate_split_state_type sym } end @@ -158,7 +159,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' } assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 } - #display_blanks_as + # display_blanks_as [:gap, :span, :zero].each do |sym| assert_nothing_raised { Axlsx.validate_display_blanks_as sym } end @@ -166,7 +167,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 'other_blank' } assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 0 } - #view_visibility + # view_visibility [:visible, :hidden, :very_hidden].each do |sym| assert_nothing_raised { Axlsx.validate_view_visibility sym } end @@ -174,7 +175,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_view_visibility 'other_visibility' } assert_raise(ArgumentError) { Axlsx.validate_view_visibility 0 } - #marker_symbol + # marker_symbol [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x].each do |sym| assert_nothing_raised { Axlsx.validate_marker_symbol sym } end @@ -187,6 +188,7 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_integerish Axlsx } [1, 1.4, "a"].each { |test_value| assert_nothing_raised { Axlsx.validate_integerish test_value } } end + def test_validate_family assert_raise(ArgumentError) { Axlsx.validate_family 0 } (1..5).each do |item| @@ -202,9 +204,9 @@ class TestValidators < Test::Unit::TestCase end def test_range_validation - # exclusive - assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) } - # inclusive by default - assert_nothing_raised { Axlsx::RangeValidator.validate('foo', 1, 10, 10) } + # exclusive + assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) } + # inclusive by default + assert_nothing_raised { Axlsx::RangeValidator.validate('foo', 1, 10, 10) } end end diff --git a/test/workbook/tc_defined_name.rb b/test/workbook/tc_defined_name.rb index 2d3ff0d9..e7fbe6b5 100644 --- a/test/workbook/tc_defined_name.rb +++ b/test/workbook/tc_defined_name.rb @@ -17,11 +17,10 @@ class TestDefinedNames < Test::Unit::TestCase end def test_boolean_attributes - %w(workbook_parameter publish_to_server xlm vb_proceedure function hidden).each do |attr| + %w(workbook_parameter publish_to_server xlm vb_proceedure function hidden).each do |attr| assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @dn.send("#{attr}=", 'foo') } assert_nothing_raised { @dn.send("#{attr}=", 1) } end - end def test_local_sheet_id @@ -45,5 +44,4 @@ class TestDefinedNames < Test::Unit::TestCase assert_equal(doc.xpath("//definedName[@hidden='1']").size, 1) assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text) end - end diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb index b9347903..cb7557c6 100644 --- a/test/workbook/tc_shared_strings_table.rb +++ b/test/workbook/tc_shared_strings_table.rb @@ -1,9 +1,8 @@ require 'tc_helper.rb' class TestSharedStringsTable < Test::Unit::TestCase - def setup - @p = Axlsx::Package.new :use_shared_strings=>true + @p = Axlsx::Package.new :use_shared_strings => true ws = @p.workbook.add_worksheet ws.add_row ['a', 1, 'b'] @@ -40,11 +39,11 @@ class TestSharedStringsTable < Test::Unit::TestCase puts error.message errors << error end - assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s) + assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map { |e| e.message }.to_s) end def test_remove_control_characters_in_xml_serialization - nasties = "hello\x10\x00\x1C\x1Eworld" + nasties = "hello\x10\x00\x1C\x1Eworld" @p.workbook.worksheets[0].add_row [nasties] # test that the nasty string was added to the shared strings diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb index f8d0b1f7..c085ed91 100644 --- a/test/workbook/tc_workbook.rb +++ b/test/workbook/tc_workbook.rb @@ -28,27 +28,26 @@ class TestWorkbook < Test::Unit::TestCase def test_no_autowidth assert_equal(@wb.use_autowidth, true) - assert_raise(ArgumentError) {@wb.use_autowidth = 0.1} - assert_nothing_raised {@wb.use_autowidth = false} + assert_raise(ArgumentError) { @wb.use_autowidth = 0.1 } + assert_nothing_raised { @wb.use_autowidth = false } assert_equal(@wb.use_autowidth, false) end def test_is_reversed assert_equal(@wb.is_reversed, nil) - assert_raise(ArgumentError) {@wb.is_reversed = 0.1} - assert_nothing_raised {@wb.is_reversed = true } + assert_raise(ArgumentError) { @wb.is_reversed = 0.1 } + assert_nothing_raised { @wb.is_reversed = true } assert_equal(@wb.use_autowidth, true) end def test_sheet_by_name_retrieval - @wb.add_worksheet(:name=>'foo') - @wb.add_worksheet(:name=>'bar') + @wb.add_worksheet(:name => 'foo') + @wb.add_worksheet(:name => 'bar') assert_equal('foo', @wb.sheet_by_name('foo').name) - end def test_worksheet_empty_name - assert_raise(ArgumentError) {@wb.add_worksheet(:name=>'')} + assert_raise(ArgumentError) { @wb.add_worksheet(:name => '') } end def test_date1904 @@ -71,13 +70,13 @@ class TestWorkbook < Test::Unit::TestCase def test_shared_strings assert_equal(@wb.use_shared_strings, nil) - assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'} - assert_nothing_raised {@wb.use_shared_strings = :true} + assert_raise(ArgumentError) { @wb.use_shared_strings = 'bpb' } + assert_nothing_raised { @wb.use_shared_strings = :true } end def test_add_worksheet assert(@wb.worksheets.empty?, "worbook has no worksheets by default") - ws = @wb.add_worksheet(:name=>"bob") + ws = @wb.add_worksheet(:name => "bob") assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!") assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added") assert_equal(ws.name, "bob", "name option gets passed to worksheet") @@ -91,7 +90,7 @@ class TestWorkbook < Test::Unit::TestCase end def test_relationships - #current relationship size is 1 due to style relation + # current relationship size is 1 due to style relation assert(@wb.relationships.size == 1) @wb.add_worksheet assert(@wb.relationships.size == 2) @@ -119,10 +118,10 @@ class TestWorkbook < Test::Unit::TestCase end def test_range_requires_valid_sheet - ws = @wb.add_worksheet :name=>'fish' - ws.add_row [1,2,3] - ws.add_row [4,5,6] - assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"]} + ws = @wb.add_worksheet :name => 'fish' + ws.add_row [1, 2, 3] + ws.add_row [4, 5, 6] + assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"] } assert_equal @wb['fish!A1:C2'].size, 6 end diff --git a/test/workbook/tc_workbook_view.rb b/test/workbook/tc_workbook_view.rb index 2aa6521a..8829924f 100644 --- a/test/workbook/tc_workbook_view.rb +++ b/test/workbook/tc_workbook_view.rb @@ -1,11 +1,10 @@ require 'tc_helper' class TestWorkbookView < Test::Unit::TestCase - def setup @options = { visibility: :hidden, minimized: true, show_horizontal_scroll: true, show_vertical_scroll: true, - show_sheet_tabs: true, tab_ratio: 750, first_sheet: 0, active_tab: 1, x_window: 500, y_window: 400, - window_width: 800, window_height: 600, auto_filter_date_grouping: true } + show_sheet_tabs: true, tab_ratio: 750, first_sheet: 0, active_tab: 1, x_window: 500, y_window: 400, + window_width: 800, window_height: 600, auto_filter_date_grouping: true } @book_view = Axlsx::WorkbookView.new @options end @@ -18,14 +17,14 @@ class TestWorkbookView < Test::Unit::TestCase def test_boolean_attribute_validation %w(minimized show_horizontal_scroll show_vertical_scroll show_sheet_tabs auto_filter_date_grouping).each do |attr| assert_raise(ArgumentError, 'only booleanish allowed in boolean attributes') { @book_view.send("#{attr}=", "banana") } - assert_nothing_raised { @book_view.send("#{attr}=", false )} + assert_nothing_raised { @book_view.send("#{attr}=", false) } end end def test_integer_attribute_validation %w(tab_ratio first_sheet active_tab x_window y_window window_width window_height).each do |attr| assert_raise(ArgumentError, 'only integer allowed in integer attributes') { @book_view.send("#{attr}=", "b") } - assert_nothing_raised { @book_view.send("#{attr}=", 7 )} + assert_nothing_raised { @book_view.send("#{attr}=", 7) } end end diff --git a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb index d7d3b47c..eb561554 100644 --- a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +++ b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb @@ -1,10 +1,9 @@ require 'tc_helper.rb' class TestAutoFilter < Test::Unit::TestCase - def setup ws = Axlsx::Package.new.workbook.add_worksheet - 3.times { |index| ws.add_row [1*index,2*index,3*index] } + 3.times { |index| ws.add_row [1 * index, 2 * index, 3 * index] } @auto_filter = ws.auto_filter @auto_filter.range = 'A1:C3' @auto_filter.add_column 0, :filters, :filter_items => [1] diff --git a/test/workbook/worksheet/auto_filter/tc_filter_column.rb b/test/workbook/worksheet/auto_filter/tc_filter_column.rb index ec74316c..88f73e0d 100644 --- a/test/workbook/worksheet/auto_filter/tc_filter_column.rb +++ b/test/workbook/worksheet/auto_filter/tc_filter_column.rb @@ -1,19 +1,17 @@ require 'tc_helper.rb' class TestFilterColumn < Test::Unit::TestCase - def setup @filter_column = Axlsx::FilterColumn.new(0, :filters, :filter_items => [200]) end - def test_initialize_col_id assert_raise ArgumentError do Axlsx::FilterColumn.new(0, :bobs_house_of_filter) - end - assert_raise ArgumentError do + end + assert_raise ArgumentError do Axlsx::FilterColumn.new(:penut, :filters) - end + end end def test_initailize_filter_type @@ -44,7 +42,7 @@ class TestFilterColumn < Test::Unit::TestCase def test_show_button assert_raise ArgumentError do - @filter_column.show_button = :foo + @filter_column.show_button = :foo end assert_nothing_raised { @filter_column.show_button = false } end @@ -52,15 +50,15 @@ class TestFilterColumn < Test::Unit::TestCase def test_hidden_button assert_raise ArgumentError do @filter_column.hidden_button = :hoge - end + end assert_nothing_raised { @filter_column.hidden_button = true } end def test_col_id= - assert_raise ArgumentError do - @filter_column.col_id = :bar - end - assert_nothing_raised { @filter_column.col_id = 7 } + assert_raise ArgumentError do + @filter_column.col_id = :bar + end + assert_nothing_raised { @filter_column.col_id = 7 } end def test_to_xml_string @@ -69,8 +67,6 @@ class TestFilterColumn < Test::Unit::TestCase assert doc.xpath("//filterColumn[@hiddenButton=#{@filter_column.hidden_button}]") assert doc.xpath("//filterColumn[@showButton=#{@filter_column.show_button}]") - - assert doc.xpath("//filterColumn/filters") end end diff --git a/test/workbook/worksheet/auto_filter/tc_filters.rb b/test/workbook/worksheet/auto_filter/tc_filters.rb index 3a8759aa..8e853772 100644 --- a/test/workbook/worksheet/auto_filter/tc_filters.rb +++ b/test/workbook/worksheet/auto_filter/tc_filters.rb @@ -2,8 +2,8 @@ require 'tc_helper.rb' class TestFilters < Test::Unit::TestCase def setup - @filters = Axlsx::Filters.new(:filter_items => [1, 'a'], - :date_group_items =>[ { :date_time_grouping => :year, :year => 2011, :month => 11, :day => 11, :hour => 0, :minute => 0, :second => 0 } ] , + @filters = Axlsx::Filters.new(:filter_items => [1, 'a'], + :date_group_items => [{ :date_time_grouping => :year, :year => 2011, :month => 11, :day => 11, :hour => 0, :minute => 0, :second => 0 }], :blank => true) end @@ -29,15 +29,15 @@ class TestFilters < Test::Unit::TestCase assert @filters.date_group_items.is_a?(Array) assert_equal 1, @filters.date_group_items.size end - + def test_apply_is_false_for_matching_values keeper = Object.new - def keeper.value; 'a'; end + def keeper.value; 'a'; end assert_equal false, @filters.apply(keeper) end def test_apply_is_true_for_non_matching_values - hidden = Object.new + hidden = Object.new def hidden.value; 'b'; end assert_equal true, @filters.apply(hidden) end @@ -47,4 +47,3 @@ class TestFilters < Test::Unit::TestCase 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 0a72cc84..c9f3df8f 100644 --- a/test/workbook/worksheet/tc_border_creator.rb +++ b/test/workbook/worksheet/tc_border_creator.rb @@ -8,7 +8,7 @@ class TestBorderCreator < Test::Unit::TestCase end def test_initialize - @ws.add_row [1,2,3] + @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 @@ -22,7 +22,7 @@ class TestBorderCreator < Test::Unit::TestCase end def test_initialize_edges - @ws.add_row [1,2,3] + @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 @@ -48,7 +48,7 @@ class TestBorderCreator < Test::Unit::TestCase def test_draw 5.times do - @ws.add_row [1,2,3,4,5] + @ws.add_row [1, 2, 3, 4, 5] end bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:C3"], edges: ["top", :left], style: :thick, color: "ffffff") @@ -66,7 +66,6 @@ class TestBorderCreator < Test::Unit::TestCase assert_equal [:thick], @ws.styles.borders[2].prs.map(&:style).uniq assert_equal [:left, :top], @ws.styles.borders[2].prs.map(&:name) - assert_equal 1, @ws.styles.borders[3].prs.size assert_equal ["FFFFFFFF"], @ws.styles.borders[3].prs.map(&:color).map(&:rgb).uniq assert_equal [:thick], @ws.styles.borders[3].prs.map(&:style).uniq @@ -77,5 +76,4 @@ class TestBorderCreator < Test::Unit::TestCase assert_equal [:thick], @ws.styles.borders[4].prs.map(&:style).uniq assert_equal [:left], @ws.styles.borders[4].prs.map(&:name) end - end diff --git a/test/workbook/worksheet/tc_break.rb b/test/workbook/worksheet/tc_break.rb index bf440b0b..2c67fed7 100644 --- a/test/workbook/worksheet/tc_break.rb +++ b/test/workbook/worksheet/tc_break.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestBreak < Test::Unit::TestCase - def setup @break = Axlsx::Break.new(:id => 1, :min => 1, :max => 10, :man => true, :pt => false) end @@ -9,7 +8,7 @@ class TestBreak < Test::Unit::TestCase def test_id assert_equal(1, @break.id) assert_raises ArgumentError do - Axlsx::Break.new(:hoge, {:id => -1}) + Axlsx::Break.new(:hoge, { :id => -1 }) end end @@ -27,7 +26,6 @@ class TestBreak < Test::Unit::TestCase end end - def test_man assert_equal(true, @break.man) assert_raises ArgumentError do diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index bdbfd59d..f5264115 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -1,14 +1,13 @@ require 'tc_helper.rb' class TestCell < Test::Unit::TestCase - def setup p = Axlsx::Package.new p.use_shared_strings = true - @ws = p.workbook.add_worksheet :name=>"hmmm" - p.workbook.styles.add_style :sz=>20 + @ws = p.workbook.add_worksheet :name => "hmmm" + p.workbook.styles.add_style :sz => 20 @row = @ws.add_row - @c = @row.add_cell 1, :type=>:float, :style=>1, :escape_formulas=>true + @c = @row.add_cell 1, :type => :float, :style => 1, :escape_formulas => true data = (0..26).map { |index| index } @ws.add_row data @cAA = @ws["AA2"] @@ -48,8 +47,8 @@ class TestCell < Test::Unit::TestCase 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(@c.r_abs, "$A$1", "calculate absolute cell reference") + assert_equal(@cAA.r_abs, "$AA$2", "needs to accept multi-digit columns") end def test_name @@ -59,7 +58,7 @@ class TestCell < Test::Unit::TestCase end def test_autowidth - style = @c.row.worksheet.workbook.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} ) + 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 @@ -91,8 +90,8 @@ class TestCell < Test::Unit::TestCase end def test_style - assert_raise(ArgumentError, "must reject invalid style indexes") { @[email protected] } - assert_nothing_raised("must allow valid style index changes") {@c.style=1} + 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) end @@ -100,7 +99,7 @@ class TestCell < Test::Unit::TestCase 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(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type') + 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') @@ -113,7 +112,7 @@ class TestCell < Test::Unit::TestCase end def test_col_ref - #TODO move to axlsx spec + # TODO move to axlsx spec assert_equal(Axlsx.col_ref(0), "A") end @@ -134,7 +133,7 @@ class TestCell < Test::Unit::TestCase 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, 1.0 / 10**6), :float) assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext) assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00')) end @@ -256,7 +255,7 @@ class TestCell < Test::Unit::TestCase assert_raise(ArgumentError) { @c.u = -1.1 } assert_nothing_raised { @c.u = :single } assert_equal(@c.u, :single) - doc = Nokogiri::XML(@c.to_xml_string(1,1)) + doc = Nokogiri::XML(@c.to_xml_string(1, 1)) assert(doc.xpath('//u[@val="single"]')) end @@ -340,13 +339,13 @@ class TestCell < Test::Unit::TestCase end def test_to_xml_string - c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) + c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) assert_equal(c_xml.xpath("/c[@s=1]").size, 1) end def test_to_xml_string_nil @c.value = nil - c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) + c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) assert_equal(c_xml.xpath("/c[@s=1]").size, 1) end @@ -358,7 +357,7 @@ class TestCell < Test::Unit::TestCase @c.value = "a" @c.font_name = 'arial' @c.color = 'FF0000' - c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) + c_xml = Nokogiri::XML(@c.to_xml_string(1, 1)) assert(c_xml.xpath("//b").any?) end diff --git a/test/workbook/worksheet/tc_cfvo.rb b/test/workbook/worksheet/tc_cfvo.rb index d846f57d..71ba6bbc 100644 --- a/test/workbook/worksheet/tc_cfvo.rb +++ b/test/workbook/worksheet/tc_cfvo.rb @@ -27,5 +27,4 @@ class TestCfvo < Test::Unit::TestCase 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 00c5f058..908e9931 100644 --- a/test/workbook/worksheet/tc_col.rb +++ b/test/workbook/worksheet/tc_col.rb @@ -1,16 +1,15 @@ require 'tc_helper.rb' class TestCol < Test::Unit::TestCase - def setup @col = Axlsx::Col.new 1, 1 end def test_initialize - options = { :width => 12, :collapsed => true, :hidden => true, :outline_level => 1, :phonetic => true, :style => 1} + 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) } + options.each { |key, value| assert_equal(col.send(key.to_sym), value) } end def test_min_max_required @@ -87,7 +86,6 @@ class TestCol < Test::Unit::TestCase assert_equal(@col.style, nil) @col.style = 1 assert_equal(@col.style, 1) - #TODO check that the style specified is actually in the styles xfs collection + # 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 a0d75fab..073cd71f 100644 --- a/test/workbook/worksheet/tc_color_scale.rb +++ b/test/workbook/worksheet/tc_color_scale.rb @@ -16,11 +16,12 @@ class TestColorScale < Test::Unit::TestCase assert_equal 2, color_scale.value_objects.size assert_equal 2, color_scale.colors.size end + 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 :min, first[:type] assert_equal 0, first[:val] assert_equal 'FFFFEF9C', second[:color] @@ -29,7 +30,7 @@ class TestColorScale < Test::Unit::TestCase end def test_partial_default_cfvo_override - first_def = {:type => :percent, :val => "10.0", :color => 'FF00FF00'} + 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] @@ -38,15 +39,15 @@ 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(@color_scale.value_objects.size, 3) + assert_equal(@color_scale.colors.size, 3) 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_nothing_raised { @color_scale.delete_at 2 } + assert_equal(@color_scale.value_objects.size, 2) + assert_equal(@color_scale.colors.size, 2) end def test_to_xml_string @@ -54,5 +55,4 @@ class TestColorScale < Test::Unit::TestCase assert_equal(doc.xpath(".//colorScale//cfvo").size, 2) assert_equal(doc.xpath(".//colorScale//color").size, 2) end - end diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb index e66abb9a..cbd93f01 100644 --- a/test/workbook/worksheet/tc_comment.rb +++ b/test/workbook/worksheet/tc_comment.rb @@ -32,6 +32,7 @@ class TestComment < Test::Unit::TestCase assert_equal(false, @c1.visible) assert_equal(true, @c2.visible) end + def test_ref assert(@c1.ref == 'A1') assert(@c2.ref == 'C3') @@ -45,8 +46,8 @@ class TestComment < Test::Unit::TestCase assert(@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(pos[0] + 2 , @c1.vml_shape.right_column) - assert(@c1.vml_shape.bottom_row == pos[1]+4) + assert_equal(pos[0] + 2, @c1.vml_shape.right_column) + assert(@c1.vml_shape.bottom_row == pos[1] + 4) end def test_to_xml_string @@ -69,4 +70,3 @@ class TestComment < Test::Unit::TestCase 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 acadf73d..276dd3b0 100644 --- a/test/workbook/worksheet/tc_comments.rb +++ b/test/workbook/worksheet/tc_comments.rb @@ -19,19 +19,21 @@ class TestComments < Test::Unit::TestCase 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_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) 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) @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(@ws.comments.authors.size, 3, 'only unique authors are returned') end + def test_pn - assert_equal(@ws.comments.pn, Axlsx::COMMENT_PN % (@ws.index+1).to_s) + assert_equal(@ws.comments.pn, Axlsx::COMMENT_PN % (@ws.index + 1).to_s) end def test_index @@ -53,5 +55,3 @@ class TestComments < Test::Unit::TestCase # assert_equal(doc.xpath("//comment").size, @ws.comments.size) end end - - diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb index bbf92e21..e6fc6324 100644 --- a/test/workbook/worksheet/tc_conditional_formatting.rb +++ b/test/workbook/worksheet/tc_conditional_formatting.rb @@ -1,22 +1,21 @@ require 'tc_helper.rb' class TestConditionalFormatting < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" - @cfs = @ws.add_conditional_formatting( "A1:A1", [{ :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :greaterThan, :formula => "0.5" }]) + @ws = p.workbook.add_worksheet :name => "hmmm" + @cfs = @ws.add_conditional_formatting("A1:A1", [{ :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :greaterThan, :formula => "0.5" }]) @cf = @cfs.first @cfr = @cf.rules.first end def test_initialize_with_options - optioned = Axlsx::ConditionalFormatting.new( :sqref => "AA1:AB100", :rules => [1, 2] ) + optioned = Axlsx::ConditionalFormatting.new(:sqref => "AA1:AB100", :rules => [1, 2]) assert_equal("AA1:AB100", optioned.sqref) assert_equal([1, 2], optioned.rules) end - def test_add_as_rule + def test_add_as_rule color_scale = Axlsx::ColorScale.new do |cs| cs.colors.first.rgb = "FFDFDFDF" cs.colors.last.rgb = "FF00FF00" @@ -26,17 +25,17 @@ class TestConditionalFormatting < Test::Unit::TestCase data_bar = Axlsx::DataBar.new :color => "FFFF0000" icon_set = Axlsx::IconSet.new :iconSet => "5Rating" - cfr = Axlsx::ConditionalFormattingRule.new( { :type => :containsText, :text => "TRUE", - :dxfId => 0, :priority => 1, - :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))', - :color_scale => color_scale, - :data_bar => data_bar, - :icon_set => icon_set}) + cfr = Axlsx::ConditionalFormattingRule.new({ :type => :containsText, :text => "TRUE", + :dxfId => 0, :priority => 1, + :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))', + :color_scale => color_scale, + :data_bar => data_bar, + :icon_set => icon_set }) assert(cfr.data_bar.is_a?(Axlsx::DataBar)) assert(cfr.icon_set.is_a?(Axlsx::IconSet)) assert(cfr.color_scale.is_a?(Axlsx::ColorScale)) - cfs = @ws.add_conditional_formatting( "B2:B2", [cfr]) + 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)))'") @@ -56,12 +55,9 @@ class TestConditionalFormatting < Test::Unit::TestCase 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) - end - def test_add_as_hash - color_scale = Axlsx::ColorScale.new do |cs| cs.colors.first.rgb = "FFDFDFDF" cs.colors.last.rgb = "FF00FF00" @@ -72,12 +68,12 @@ class TestConditionalFormatting < Test::Unit::TestCase data_bar = Axlsx::DataBar.new :color => "FFFF0000" icon_set = Axlsx::IconSet.new :iconSet => "5Rating" - cfs = @ws.add_conditional_formatting( "B2:B2", [{ :type => :containsText, :text => "TRUE", - :dxfId => 0, :priority => 1, - :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))', - :color_scale => color_scale, - :data_bar => data_bar, - :icon_set => icon_set}]) + cfs = @ws.add_conditional_formatting("B2:B2", [{ :type => :containsText, :text => "TRUE", + :dxfId => 0, :priority => 1, + :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))', + :color_scale => color_scale, + :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)))'") @@ -97,7 +93,6 @@ class TestConditionalFormatting < Test::Unit::TestCase 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) - end def test_single_rule @@ -107,11 +102,11 @@ class TestConditionalFormatting < Test::Unit::TestCase end def test_many_options - cf = Axlsx::ConditionalFormatting.new( :sqref => "B3:B4" ) - cf.add_rule({:type => :cellIs, :aboveAverage => false, :bottom => false, :dxfId => 0, - :equalAverage => false, :priority => 2, :operator => :lessThan, :text => "", - :percent => false, :rank => 0, :stdDev => 1, :stopIfTrue => true, :timePeriod => :today, - :formula => "0.0"}) + cf = Axlsx::ConditionalFormatting.new(:sqref => "B3:B4") + cf.add_rule({ :type => :cellIs, :aboveAverage => false, :bottom => false, :dxfId => 0, + :equalAverage => false, :priority => 2, :operator => :lessThan, :text => "", + :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") @@ -131,7 +126,7 @@ class TestConditionalFormatting < Test::Unit::TestCase end def test_multiple_formulas - @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2","5"] } + @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'") @@ -192,7 +187,7 @@ class TestConditionalFormatting < Test::Unit::TestCase end def test_percent - assert_raise(ArgumentError) { @cfr.percent = "10%" } #WRONG! + assert_raise(ArgumentError) { @cfr.percent = "10%" } # WRONG! assert_nothing_raised { @cfr.percent = true } assert_equal(@cfr.percent, true) end @@ -220,5 +215,4 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_nothing_raised { @cfr.timePeriod = :today } assert_equal(@cfr.timePeriod, :today) end - end diff --git a/test/workbook/worksheet/tc_data_bar.rb b/test/workbook/worksheet/tc_data_bar.rb index 1c460630..aa39c48b 100644 --- a/test/workbook/worksheet/tc_data_bar.rb +++ b/test/workbook/worksheet/tc_data_bar.rb @@ -12,27 +12,26 @@ class TestDataBar < Test::Unit::TestCase end def test_override_default_cfvos - data_bar = Axlsx::DataBar.new({:color => 'FF00FF00'}, {:type => :min, :val => "20"}) + 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 - def test_minLength assert_raise(ArgumentError) { @data_bar.minLength = :invalid_type } - assert_nothing_raised { @data_bar.minLength = 0} + assert_nothing_raised { @data_bar.minLength = 0 } assert_equal(@data_bar.minLength, 0) end def test_maxLength assert_raise(ArgumentError) { @data_bar.maxLength = :invalid_type } - assert_nothing_raised { @data_bar.maxLength = 0} + assert_nothing_raised { @data_bar.maxLength = 0 } assert_equal(@data_bar.maxLength, 0) end def test_showValue assert_raise(ArgumentError) { @data_bar.showValue = :invalid_type } - assert_nothing_raised { @data_bar.showValue = false} + assert_nothing_raised { @data_bar.showValue = false } assert_equal(@data_bar.showValue, false) end @@ -42,5 +41,4 @@ class TestDataBar < Test::Unit::TestCase assert_equal(doc.xpath(".//dataBar//cfvo").size, 2) assert_equal(doc.xpath(".//dataBar//color").size, 1) end - end diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb index 12fee6ef..ff92b847 100644 --- a/test/workbook/worksheet/tc_data_validation.rb +++ b/test/workbook/worksheet/tc_data_validation.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 require 'tc_helper.rb' require 'support/capture_warnings' @@ -6,119 +5,119 @@ class TestDataValidation < Test::Unit::TestCase include CaptureWarnings def setup - #inverse defaults + # inverse defaults @boolean_options = { :allowBlank => false, :hideDropDown => true, :showErrorMessage => false, :showInputMessage => true } - @nil_options = { :formula1 => 'foo', :formula2 => 'foo', :errorTitle => 'foo', :operator => :lessThan, :prompt => 'foo', :promptTitle => 'foo', :sqref => 'foo' } + @nil_options = { :formula1 => 'foo', :formula2 => 'foo', :errorTitle => 'foo', :operator => :lessThan, :prompt => 'foo', :promptTitle => 'foo', :sqref => 'foo' } @type_option = { :type => :whole } @error_style_option = { :errorStyle => :warning } - + @string_options = { :formula1 => 'foo', :formula2 => 'foo', :error => 'foo', :errorTitle => 'foo', :prompt => 'foo', :promptTitle => 'foo', :sqref => 'foo' } - @symbol_options = { :errorStyle => :warning, :operator => :lessThan, :type => :whole} - + @symbol_options = { :errorStyle => :warning, :operator => :lessThan, :type => :whole } + @options = @boolean_options.merge(@nil_options).merge(@type_option).merge(@error_style_option) - + @dv = Axlsx::DataValidation.new(@options) end - + def test_initialize dv = Axlsx::DataValidation.new - + @boolean_options.each do |key, value| assert_equal(!value, dv.send(key.to_sym), "initialized default #{key} should be #{!value}") assert_equal(value, @dv.send(key.to_sym), "initialized options #{key} should be #{value}") end - + @nil_options.each do |key, value| assert_equal(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 - + @type_option.each do |key, value| assert_equal(:none, dv.send(key.to_sym), "initialized default #{key} should be :none") assert_equal(value, @dv.send(key.to_sym), "initialized options #{key} should be #{value}") end - + @error_style_option.each do |key, value| assert_equal(:stop, dv.send(key.to_sym), "initialized default #{key} should be :stop") assert_equal(value, @dv.send(key.to_sym), "initialized options #{key} should be #{value}") end end - + def test_boolean_attribute_validation @boolean_options.each do |key, value| assert_raise(ArgumentError, "#{key} must be boolean") { @dv.send("#{key}=".to_sym, 'A') } assert_nothing_raised { @dv.send("#{key}=".to_sym, true) } end end - + def test_string_attribute_validation @string_options.each do |key, value| assert_raise(ArgumentError, "#{key} must be string") { @dv.send("#{key}=".to_sym, :symbol) } assert_nothing_raised { @dv.send("#{key}=".to_sym, "foo") } end end - + def test_symbol_attribute_validation @symbol_options.each do |key, value| assert_raise(ArgumentError, "#{key} must be symbol") { @dv.send("#{key}=".to_sym, "foo") } assert_nothing_raised { @dv.send("#{key}=".to_sym, value) } end end - + def test_formula1 assert_raise(ArgumentError) { @dv.formula1 = 10 } assert_nothing_raised { @dv.formula1 = "=SUM(A1:A1)" } assert_equal(@dv.formula1, "=SUM(A1:A1)") 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)") end - + def test_allowBlank assert_raise(ArgumentError) { @dv.allowBlank = "foo´" } assert_nothing_raised { @dv.allowBlank = false } assert_equal(@dv.allowBlank, false) 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") end - + def test_errorStyle assert_raise(ArgumentError) { @dv.errorStyle = "foo" } assert_nothing_raised { @dv.errorStyle = :information } assert_equal(@dv.errorStyle, :information) 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") end - + def test_operator assert_raise(ArgumentError) { @dv.operator = "foo" } assert_nothing_raised { @dv.operator = :greaterThan } assert_equal(@dv.operator, :greaterThan) 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") 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") end - + def test_showDropDown warnings = capture_warnings do assert_raise(ArgumentError) { @dv.showDropDown = "foo´" } @@ -137,42 +136,42 @@ class TestDataValidation < Test::Unit::TestCase # As hideDropdown is just an alias for showDropDown, we should test the original value too assert_equal(@dv.showDropDown, false) end - + def test_showErrorMessage assert_raise(ArgumentError) { @dv.showErrorMessage = "foo´" } assert_nothing_raised { @dv.showErrorMessage = false } assert_equal(@dv.showErrorMessage, false) end - + def test_showInputMessage assert_raise(ArgumentError) { @dv.showInputMessage = "foo´" } assert_nothing_raised { @dv.showInputMessage = false } assert_equal(@dv.showInputMessage, false) end - + def test_sqref assert_raise(ArgumentError) { @dv.sqref = 10 } assert_nothing_raised { @dv.sqref = "A1:A1" } assert_equal(@dv.sqref, "A1:A1") end - + def test_type assert_raise(ArgumentError) { @dv.type = "foo" } assert_nothing_raised { @dv.type = :list } assert_equal(@dv.type, :list) end - + def test_whole_decimal_data_time_textLength_to_xml p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"data_validation" - @ws.add_data_validation("A1", { :type => :whole, :operator => :between, :formula1 => '5', :formula2 => '10', - :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values between 5 and 10', - :errorStyle => :information, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values between 5 and 10'}) - + @ws = p.workbook.add_worksheet :name => "data_validation" + @ws.add_data_validation("A1", { :type => :whole, :operator => :between, :formula1 => '5', :formula2 => '10', + :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values between 5 and 10', + :errorStyle => :information, :showInputMessage => true, :promptTitle => 'Be carful!', + :prompt => 'Only values between 5 and 10' }) + doc = Nokogiri::XML.parse(@ws.to_xml_string) - - #test attributes + + # test attributes assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1'] [@promptTitle='Be carful!'][@prompt='Only values between 5 and 10'][@operator='between'][@errorTitle='Wrong input'] [@error='Only values between 5 and 10'][@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@type='whole'] @@ -181,27 +180,27 @@ class TestDataValidation < Test::Unit::TestCase [@promptTitle='Be carful!'][@prompt='Only values between 5 and 10'][@operator='between'][@errorTitle='Wrong input'] [@error='Only values between 5 and 10'][@showErrorMessage=1][@allowBlank=1][@showInputMessage=1] [@type='whole'][@errorStyle='information']") - - #test forumula1 + + # test forumula1 assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1").size) assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1='5'") - - #test forumula2 + + # test forumula2 assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula2").size) assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula2='10'") end - + def test_list_to_xml p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"data_validation" + @ws = p.workbook.add_worksheet :name => "data_validation" @ws.add_data_validation("A1", { :type => :list, :formula1 => 'A1:A5', - :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', - :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values from list', :hideDropDown => true}) - + :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', + :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', + :prompt => 'Only values from list', :hideDropDown => true }) + doc = Nokogiri::XML.parse(@ws.to_xml_string) - - #test attributes + + # test attributes assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1'] [@promptTitle='Be carful!'][@prompt='Only values from list'][@errorTitle='Wrong input'][@error='Only values from list'] [@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@showDropDown=1][@type='list'] @@ -209,50 +208,50 @@ class TestDataValidation < Test::Unit::TestCase assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1'] [@promptTitle='Be carful!'][@prompt='Only values from list'][@errorTitle='Wrong input'][@error='Only values from list'] [@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@showDropDown=1][@type='list'][@errorStyle='stop']") - - #test forumula1 + + # test forumula1 assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1").size) assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1='A1:A5'") end - + def test_custom_to_xml p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"data_validation" + @ws = p.workbook.add_worksheet :name => "data_validation" @ws.add_data_validation("A1", { :type => :custom, :formula1 => '=5/2', - :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values corresponding formula', - :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values corresponding formula'}) - + :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values corresponding formula', + :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', + :prompt => 'Only values corresponding formula' }) + doc = Nokogiri::XML.parse(@ws.to_xml_string) - - #test attributes + + # test attributes assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1'][@promptTitle='Be carful!'] [@prompt='Only values corresponding formula'][@errorTitle='Wrong input'][@error='Only values corresponding formula'][@showErrorMessage=1] [@allowBlank=1][@showInputMessage=1][@type='custom'][@errorStyle='stop']").size) assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='1']/xmlns:dataValidation[@sqref='A1'][@promptTitle='Be carful!'] [@prompt='Only values corresponding formula'][@errorTitle='Wrong input'][@error='Only values corresponding formula'] [@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@type='custom'][@errorStyle='stop']") - - #test forumula1 + + # test forumula1 assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1").size) assert doc.xpath("//xmlns:worksheet/xmlns:dataValidations/xmlns:dataValidation/xmlns:formula1='=5/2'") end - + def test_multiple_datavalidations_to_xml p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"data_validation" - @ws.add_data_validation("A1", { :type => :whole, :operator => :between, :formula1 => '5', :formula2 => '10', - :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values between 5 and 10', - :errorStyle => :information, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values between 5 and 10'}) + @ws = p.workbook.add_worksheet :name => "data_validation" + @ws.add_data_validation("A1", { :type => :whole, :operator => :between, :formula1 => '5', :formula2 => '10', + :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values between 5 and 10', + :errorStyle => :information, :showInputMessage => true, :promptTitle => 'Be carful!', + :prompt => 'Only values between 5 and 10' }) @ws.add_data_validation("B1", { :type => :list, :formula1 => 'A1:A5', - :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', - :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', - :prompt => 'Only values from list', :hideDropDown => true}) - + :showErrorMessage => true, :errorTitle => 'Wrong input', :error => 'Only values from list', + :errorStyle => :stop, :showInputMessage => true, :promptTitle => 'Be carful!', + :prompt => 'Only values from list', :hideDropDown => true }) + doc = Nokogiri::XML.parse(@ws.to_xml_string) - - #test attributes + + # test attributes assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='2']/xmlns:dataValidation[@sqref='A1'] [@promptTitle='Be carful!'][@prompt='Only values between 5 and 10'][@operator='between'][@errorTitle='Wrong input'] [@error='Only values between 5 and 10'][@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@type='whole'] @@ -261,8 +260,8 @@ class TestDataValidation < Test::Unit::TestCase [@promptTitle='Be carful!'][@prompt='Only values between 5 and 10'][@operator='between'][@errorTitle='Wrong input'] [@error='Only values between 5 and 10'][@showErrorMessage=1][@allowBlank=1][@showInputMessage=1] [@type='whole'][@errorStyle='information']") - - #test attributes + + # test attributes assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:dataValidations[@count='2']/xmlns:dataValidation[@sqref='B1'] [@promptTitle='Be carful!'][@prompt='Only values from list'][@errorTitle='Wrong input'][@error='Only values from list'] [@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@showDropDown=1][@type='list'] @@ -271,10 +270,9 @@ class TestDataValidation < Test::Unit::TestCase [@promptTitle='Be carful!'][@prompt='Only values from list'][@errorTitle='Wrong input'][@error='Only values from list'] [@showErrorMessage=1][@allowBlank=1][@showInputMessage=1][@showDropDown=1][@type='list'][@errorStyle='stop']") end - - def test_empty_attributes - v = Axlsx::DataValidation.new - assert_equal(nil, v.send(:get_valid_attributes)) + def test_empty_attributes + v = Axlsx::DataValidation.new + assert_equal(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 1bdee04b..9c813486 100644 --- a/test/workbook/worksheet/tc_date_time_converter.rb +++ b/test/workbook/worksheet/tc_date_time_converter.rb @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- require 'tc_helper.rb' class TestDateTimeConverter < Test::Unit::TestCase @@ -28,7 +27,7 @@ class TestDateTimeConverter < Test::Unit::TestCase "1970-01-01" => 25569.0, # Unix epoch "1970-01-02" => 25570.0, "2006-02-01" => 38749.0, - "2038-01-19" => 50424.0, # max date using signed timestamp in 32bit + "2038-01-19" => 50424.0 # max date using signed timestamp in 32bit } end tests.each do |date_string, expected| @@ -52,7 +51,7 @@ class TestDateTimeConverter < Test::Unit::TestCase "1970-01-01" => 24107.0, # Unix epoch "1970-01-02" => 24108.0, "2006-02-01" => 37287.0, - "2038-01-19" => 48962.0, # max date using signed timestamp in 32bit + "2038-01-19" => 48962.0 # max date using signed timestamp in 32bit } end tests.each do |date_string, expected| @@ -64,21 +63,21 @@ class TestDateTimeConverter < Test::Unit::TestCase def test_time_to_serial_1900 Axlsx::Workbook.date1904 = false tests = if @extended_time_range - { # examples taken straight from the spec - "1893-08-05T00:00:01Z" => -2337.999989, - "1899-12-28T18:00:00Z" => -1.25, - "1910-02-03T10:05:54Z" => 3687.4207639, - "1900-01-01T12:00:00Z" => 2.5, # wrongly indicated as 1.5 in the spec! - "9999-12-31T23:59:59Z" => 2958465.9999884 - } - else - { # examples taken inside the possible values - "1970-01-01T00:00:00Z" => 25569.0, # Unix epoch - "1970-01-01T12:00:00Z" => 25569.5, - "2000-01-01T00:00:00Z" => 36526.0, - "2038-01-19T03:14:07Z" => 50424.134803, # max signed timestamp in 32bit - } - end + { # examples taken straight from the spec + "1893-08-05T00:00:01Z" => -2337.999989, + "1899-12-28T18:00:00Z" => -1.25, + "1910-02-03T10:05:54Z" => 3687.4207639, + "1900-01-01T12:00:00Z" => 2.5, # wrongly indicated as 1.5 in the spec! + "9999-12-31T23:59:59Z" => 2958465.9999884 + } + else + { # examples taken inside the possible values + "1970-01-01T00:00:00Z" => 25569.0, # Unix epoch + "1970-01-01T12:00:00Z" => 25569.5, + "2000-01-01T00:00:00Z" => 36526.0, + "2038-01-19T03:14:07Z" => 50424.134803 # max signed timestamp in 32bit + } + 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 @@ -87,23 +86,23 @@ class TestDateTimeConverter < Test::Unit::TestCase def test_time_to_serial_1904 Axlsx::Workbook.date1904 = true - # ruby 1.8.7 cannot parse dates prior to epoch. see http://ruby-doc.org/core-1.8.7/Time.html + # ruby 1.8.7 cannot parse dates prior to epoch. see http://ruby-doc.org/core-1.8.7/Time.html tests = if @extended_time_range - { # examples taken straight from the spec - "1893-08-05T00:00:01Z" => -3799.999989, - "1910-02-03T10:05:54Z" => 2225.4207639, - "1904-01-01T12:00:00Z" => 0.5000000, - "9999-12-31T23:59:59Z" => 2957003.9999884 - } - else - { # examples taken inside the possible values - "1970-01-01T00:00:00Z" => 24107.0, # Unix epoch - "1970-01-01T12:00:00Z" => 24107.5, - "2000-01-01T00:00:00Z" => 35064.0, - "2038-01-19T03:14:07Z" => 48962.134803, # max signed timestamp in 32bit - } - end + { # examples taken straight from the spec + "1893-08-05T00:00:01Z" => -3799.999989, + "1910-02-03T10:05:54Z" => 2225.4207639, + "1904-01-01T12:00:00Z" => 0.5000000, + "9999-12-31T23:59:59Z" => 2957003.9999884 + } + else + { # examples taken inside the possible values + "1970-01-01T00:00:00Z" => 24107.0, # Unix epoch + "1970-01-01T12:00:00Z" => 24107.5, + "2000-01-01T00:00:00Z" => 35064.0, + "2038-01-19T03:14:07Z" => 48962.134803 # max signed timestamp in 32bit + } + 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 @@ -111,14 +110,12 @@ class TestDateTimeConverter < Test::Unit::TestCase end def test_timezone - utc = Time.utc 2012 # January 1st, 2012 at 0:00 UTC local = Time.parse "2012-01-01 09:00:00 +0900" assert_equal local, utc - assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - local.utc_offset.to_f/86400, Axlsx::DateTimeConverter::time_to_serial(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) + 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 caf1b9df..1ecea096 100644 --- a/test/workbook/worksheet/tc_header_footer.rb +++ b/test/workbook/worksheet/tc_header_footer.rb @@ -1,7 +1,6 @@ require 'tc_helper' class TestHeaderFooter < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet :name => 'test' @@ -59,7 +58,7 @@ class TestHeaderFooter < Test::Unit::TestCase end def test_boolean_attributes - %w(different_first different_odd_even).each do |attr| + %w(different_first different_odd_even).each do |attr| assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @hf.send("#{attr}=", 'foo') } assert_nothing_raised { @hf.send("#{attr}=", 1) } end @@ -148,4 +147,3 @@ class TestHeaderFooter < Test::Unit::TestCase assert_equal(0, doc.xpath(".//headerFooter/firstFooter").size) end end - diff --git a/test/workbook/worksheet/tc_icon_set.rb b/test/workbook/worksheet/tc_icon_set.rb index 9096625a..3a4079bf 100644 --- a/test/workbook/worksheet/tc_icon_set.rb +++ b/test/workbook/worksheet/tc_icon_set.rb @@ -14,25 +14,25 @@ class TestIconSet < Test::Unit::TestCase def test_icon_set assert_raise(ArgumentError) { @icon_set.iconSet = "invalid_value" } - assert_nothing_raised { @icon_set.iconSet = "5Rating"} + assert_nothing_raised { @icon_set.iconSet = "5Rating" } assert_equal(@icon_set.iconSet, "5Rating") end def test_percent assert_raise(ArgumentError) { @icon_set.percent = :invalid_type } - assert_nothing_raised { @icon_set.percent = false} + assert_nothing_raised { @icon_set.percent = false } assert_equal(@icon_set.percent, false) end def test_showValue assert_raise(ArgumentError) { @icon_set.showValue = :invalid_type } - assert_nothing_raised { @icon_set.showValue = false} + assert_nothing_raised { @icon_set.showValue = false } assert_equal(@icon_set.showValue, false) end def test_reverse assert_raise(ArgumentError) { @icon_set.reverse = :invalid_type } - assert_nothing_raised { @icon_set.reverse = false} + assert_nothing_raised { @icon_set.reverse = false } assert_equal(@icon_set.reverse, false) end @@ -41,5 +41,4 @@ class TestIconSet < Test::Unit::TestCase assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size, 1) assert_equal(doc.xpath(".//iconSet//cfvo").size, 3) end - end diff --git a/test/workbook/worksheet/tc_outline_pr.rb b/test/workbook/worksheet/tc_outline_pr.rb index 41a2b4ca..d2906a61 100644 --- a/test/workbook/worksheet/tc_outline_pr.rb +++ b/test/workbook/worksheet/tc_outline_pr.rb @@ -1,19 +1,19 @@ require 'tc_helper.rb' class TestOutlinePr < Test::Unit::TestCase - def setup - @outline_pr = Axlsx::OutlinePr.new(:summary_below => false, :summary_right => true, :apply_styles => false) - end + def setup + @outline_pr = Axlsx::OutlinePr.new(:summary_below => false, :summary_right => true, :apply_styles => false) + end - def test_summary_below - assert_equal false, @outline_pr.summary_below - end + def test_summary_below + assert_equal false, @outline_pr.summary_below + end - def test_summary_right - assert_equal true, @outline_pr.summary_right - end - - def test_apply_styles - assert_equal false, @outline_pr.apply_styles - end + def test_summary_right + assert_equal true, @outline_pr.summary_right + end + + def test_apply_styles + assert_equal false, @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 386f47da..ba532e7f 100644 --- a/test/workbook/worksheet/tc_page_margins.rb +++ b/test/workbook/worksheet/tc_page_margins.rb @@ -1,10 +1,9 @@ require 'tc_helper.rb' class TestPageMargins < Test::Unit::TestCase - def setup p = Axlsx::Package.new - ws = p.workbook.add_worksheet :name=>"hmmm" + ws = p.workbook.add_worksheet :name => "hmmm" @pm = ws.page_margins end @@ -27,7 +26,6 @@ class TestPageMargins < Test::Unit::TestCase assert_equal(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) diff --git a/test/workbook/worksheet/tc_page_set_up_pr.rb b/test/workbook/worksheet/tc_page_set_up_pr.rb index d04097d0..8ca4f825 100644 --- a/test/workbook/worksheet/tc_page_set_up_pr.rb +++ b/test/workbook/worksheet/tc_page_set_up_pr.rb @@ -1,15 +1,15 @@ require 'tc_helper.rb' class TestPageSetUpPr < Test::Unit::TestCase - def setup - @page_setup_pr = Axlsx::PageSetUpPr.new(:fit_to_page => true, :auto_page_breaks => true) - end + def setup + @page_setup_pr = Axlsx::PageSetUpPr.new(:fit_to_page => true, :auto_page_breaks => true) + end - def test_fit_to_page - assert_equal true, @page_setup_pr.fit_to_page - end + def test_fit_to_page + assert_equal true, @page_setup_pr.fit_to_page + end - def test_auto_page_breaks - assert_equal true, @page_setup_pr.auto_page_breaks - end + def test_auto_page_breaks + assert_equal true, @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 097eb563..b7a36600 100644 --- a/test/workbook/worksheet/tc_page_setup.rb +++ b/test/workbook/worksheet/tc_page_setup.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestPageSetup < Test::Unit::TestCase - def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet :name => "hmmm" @@ -133,11 +132,9 @@ class TestPageSetup < Test::Unit::TestCase fits = @ps.fit_to(:width => 1) assert_equal([1, 999], fits) fits = @ps.fit_to :height => 1 - assert_equal(fits, [999 ,1]) + assert_equal(fits, [999, 1]) fits = @ps.fit_to :height => 7, :width => 2 assert_equal(fits, [2, 7]) - assert_raise(ArgumentError) { puts @ps.fit_to(:width => true)} - - + 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 fff0bf7a..9a16866b 100644 --- a/test/workbook/worksheet/tc_pane.rb +++ b/test/workbook/worksheet/tc_pane.rb @@ -1,51 +1,50 @@ -# encoding: UTF-8 $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../" require 'tc_helper.rb' class TestPane < Test::Unit::TestCase def setup - #inverse defaults for booleans + # inverse defaults for booleans @nil_options = { :active_pane => :bottom_left, :state => :frozen, :top_left_cell => 'A2' } @int_0_options = { :x_split => 2, :y_split => 2 } - @options = @nil_options.merge(@int_0_options) + @options = @nil_options.merge(@int_0_options) @pane = Axlsx::Pane.new(@options) end - 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") end - + def test_state assert_raise(ArgumentError) { @pane.state = "foo" } assert_nothing_raised { @pane.state = :frozen_split } assert_equal(@pane.state, "frozenSplit") 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) 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) 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") 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) diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb index f676a72d..a5bb8906 100644 --- a/test/workbook/worksheet/tc_pivot_table.rb +++ b/test/workbook/worksheet/tc_pivot_table.rb @@ -1,6 +1,5 @@ require 'tc_helper.rb' - def shared_test_pivot_table_xml_validity(pivot_table) schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(pivot_table.to_xml_string) @@ -17,8 +16,8 @@ class TestPivotTable < Test::Unit::TestCase p = Axlsx::Package.new @ws = p.workbook.add_worksheet - @ws << ["Year","Month","Region", "Type", "Sales"] - @ws << [2012, "Nov", "East", "Soda", "12345"] + @ws << ["Year", "Month", "Region", "Type", "Sales"] + @ws << [2012, "Nov", "East", "Soda", "12345"] end def test_initialization @@ -55,21 +54,21 @@ class TestPivotTable < Test::Unit::TestCase end assert_equal(['Year', 'Month'], pivot_table.rows) assert_equal(['Type'], pivot_table.columns) - assert_equal([{:ref=>"Sales"}], pivot_table.data) + assert_equal([{ :ref => "Sales" }], pivot_table.data) assert_equal(['Region'], pivot_table.pages) shared_test_pivot_table_xml_validity(pivot_table) end def test_add_pivot_table_with_options_on_data_field pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt| - pt.data = [{:ref=>"Sales", :subtotal => 'average'}] + pt.data = [{ :ref => "Sales", :subtotal => 'average' }] end - assert_equal([{:ref=>"Sales", :subtotal => 'average'}], pivot_table.data) + assert_equal([{ :ref => "Sales", :subtotal => 'average' }], pivot_table.data) end def test_add_pivot_table_with_style_info - style_info_data = { :name=>"PivotStyleMedium9", :showRowHeaders=>"1", :showLastColumn=>"0"} - pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:style_info=>style_info_data}) do |pt| + style_info_data = { :name => "PivotStyleMedium9", :showRowHeaders => "1", :showLastColumn => "0" } + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', { :style_info => style_info_data }) do |pt| pt.rows = ['Year', 'Month'] pt.columns = ['Type'] pt.data = ['Sales'] @@ -80,33 +79,33 @@ class TestPivotTable < Test::Unit::TestCase end def test_add_pivot_table_with_row_without_subtotals - pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5', {:no_subtotals_on_headers=>['Year']}) do |pt| + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5', { :no_subtotals_on_headers => ['Year'] }) do |pt| pt.data = ['Sales'] - pt.rows = ['Year','Month'] + pt.rows = ['Year', 'Month'] end assert_equal(['Year'], pivot_table.no_subtotals_on_headers) end def test_add_pivot_table_with_months_sorted - pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:sort_on_headers=>['Month']}) do |pt| + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', { :sort_on_headers => ['Month'] }) do |pt| pt.data = ['Sales'] - pt.rows = ['Year','Month'] + pt.rows = ['Year', 'Month'] end - assert_equal({'Month' => :ascending}, pivot_table.sort_on_headers) + 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) + pivot_table.sort_on_headers = { 'Month' => :descending } + assert_equal({ 'Month' => :descending }, pivot_table.sort_on_headers) shared_test_pivot_table_xml_validity(pivot_table) end 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(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_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs) end @@ -130,7 +129,7 @@ class TestPivotTable < Test::Unit::TestCase end def test_to_xml_string - pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:no_subtotals_on_headers=>['Year']}) do |pt| + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', { :no_subtotals_on_headers => ['Year'] }) do |pt| pt.rows = ['Year', 'Month'] pt.columns = ['Type'] pt.data = ['Sales'] @@ -141,14 +140,14 @@ class TestPivotTable < Test::Unit::TestCase def test_to_xml_string_with_options_on_data_field pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt| - pt.data = [{:ref=>"Sales", :subtotal => 'average'}] + pt.data = [{ :ref => "Sales", :subtotal => 'average' }] end shared_test_pivot_table_xml_validity(pivot_table) end def test_add_pivot_table_with_format_options_on_data_field pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt| - pt.data = [{:ref=>"Sales", :subtotal => 'sum', num_fmt: 4}] + 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') @@ -156,13 +155,13 @@ class TestPivotTable < Test::Unit::TestCase def test_pivot_table_with_more_than_one_data_row ### https://github.com/caxlsx/caxlsx/issues/110 - + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt| pt.rows = ["Date", "Name"] pt.data = [ - {ref: "Gross amount", num_fmt: 2}, - {ref: "Net amount", num_fmt: 2}, - {ref: "Margin", num_fmt: 2}, + { ref: "Gross amount", num_fmt: 2 }, + { ref: "Net amount", num_fmt: 2 }, + { ref: "Margin", num_fmt: 2 } ] end @@ -178,20 +177,19 @@ class TestPivotTable < Test::Unit::TestCase assert_equal('-2', doc.at_css('colFields field')['x']) assert_equal('3', doc.at_css('colItems')['count']) - assert_equal( 3, doc.at_css('colItems').children.size) - assert_nil( doc.at_css('colItems i')['x']) + assert_equal(3, doc.at_css('colItems').children.size) + assert_nil(doc.at_css('colItems i')['x']) assert_equal('1', doc.at_css('colItems i[i=1] x')['v']) assert_equal('2', doc.at_css('colItems i[i=2] x')['v']) - end def test_pivot_table_with_only_one_data_row ### https://github.com/caxlsx/caxlsx/issues/110 - + pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt| pt.rows = ["Date", "Name"] pt.data = [ - {ref: "Gross amount", num_fmt: 2}, + { ref: "Gross amount", num_fmt: 2 } ] end diff --git a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb index 37d7e485..2127c4b3 100644 --- a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +++ b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb @@ -5,7 +5,7 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase p = Axlsx::Package.new @ws = p.workbook.add_worksheet 5.times do - @ws << ["aa","aa","aa","aa"] + @ws << ["aa", "aa", "aa", "aa"] end @pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') @cache_definition = @pivot_table.cache_definition diff --git a/test/workbook/worksheet/tc_print_options.rb b/test/workbook/worksheet/tc_print_options.rb index 32af9cd0..8dc2b804 100644 --- a/test/workbook/worksheet/tc_print_options.rb +++ b/test/workbook/worksheet/tc_print_options.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestPrintOptions < Test::Unit::TestCase - def setup p = Axlsx::Package.new ws = p.workbook.add_worksheet :name => "hmmm" @@ -68,5 +67,4 @@ class TestPrintOptions < Test::Unit::TestCase assert_nothing_raised { @po.vertical_centered = true } assert_equal(@po.vertical_centered, true) end - end diff --git a/test/workbook/worksheet/tc_protected_range.rb b/test/workbook/worksheet/tc_protected_range.rb index 4ae942b3..906c6014 100644 --- a/test/workbook/worksheet/tc_protected_range.rb +++ b/test/workbook/worksheet/tc_protected_range.rb @@ -1,17 +1,16 @@ -# encoding: UTF-8 require 'tc_helper.rb' class TestProtectedRange < Test::Unit::TestCase -def setup - @p = Axlsx::Package.new - @ws = @p.workbook.add_worksheet { |sheet| sheet.add_row [1,2,3,4,5,6,7,8,9] } -end + def setup + @p = Axlsx::Package.new + @ws = @p.workbook.add_worksheet { |sheet| sheet.add_row [1, 2, 3, 4, 5, 6, 7, 8, 9] } + end -def test_initialize_options - assert_nothing_raised {Axlsx::ProtectedRange.new(:sqref => 'A1:B1', :name => "only bob")} -end + def test_initialize_options + assert_nothing_raised { Axlsx::ProtectedRange.new(:sqref => 'A1:B1', :name => "only bob") } + end -def test_range - r = @ws.protect_range('A1:B1') - assert_equal('A1:B1', r.sqref) -end + 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 d79d3021..34117b1b 100644 --- a/test/workbook/worksheet/tc_rich_text.rb +++ b/test/workbook/worksheet/tc_rich_text.rb @@ -8,7 +8,7 @@ class RichText < Test::Unit::TestCase @rt = Axlsx::RichText.new b = true (0..26).each do |r| - @rt.add_run "run #{r}, ", :b => (b=!b), :i => !b + @rt.add_run "run #{r}, ", :b => (b = !b), :i => !b end @row = @ws.add_row [@rt] @c = @row.first @@ -22,9 +22,9 @@ class RichText < Test::Unit::TestCase assert_equal(rt_direct.runs.length, 1) assert_equal(rt_indirect.runs.length, 1) row = @ws.add_row [rt_direct, rt_indirect] - assert_equal(row[0].to_xml_string(0,0), row[1].to_xml_string(0,0)) + 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) @@ -33,12 +33,12 @@ class RichText < Test::Unit::TestCase assert_equal(runs[1].b, true) assert_equal(runs[1].i, false) end - + def test_implicit_richtext rt = Axlsx::RichText.new('a', :b => true) 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)) + 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 39919a31..d21329a9 100644 --- a/test/workbook/worksheet/tc_rich_text_run.rb +++ b/test/workbook/worksheet/tc_rich_text_run.rb @@ -106,7 +106,7 @@ class RichTextRun < Test::Unit::TestCase assert_raise(ArgumentError) { @c.u = -1.1 } assert_nothing_raised { @c.u = :single } assert_equal(@c.u, :single) - doc = Nokogiri::XML(@c.to_xml_string(1,1)) + doc = Nokogiri::XML(@c.to_xml_string(1, 1)) assert(doc.xpath('//u[@val="single"]')) end @@ -141,7 +141,7 @@ class RichTextRun < Test::Unit::TestCase end def test_multiline_autowidth - wrap = @p.workbook.styles.add_style({:alignment => {:wrap_text => true}}) + wrap = @p.workbook.styles.add_style({ :alignment => { :wrap_text => true } }) awtr = Axlsx::RichTextRun.new('I\'m bold' + "\n", :b => true) rt = Axlsx::RichText.new rt.runs << awtr diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index 38b13806..29c4415b 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -1,10 +1,9 @@ require 'tc_helper.rb' class TestRow < Test::Unit::TestCase - def setup p = Axlsx::Package.new - @ws = p.workbook.add_worksheet :name=>"hmmm" + @ws = p.workbook.add_worksheet :name => "hmmm" @row = @ws.add_row end @@ -16,19 +15,19 @@ class TestRow < Test::Unit::TestCase end def test_initialize_with_fixed_height - row = @ws.add_row([1,2,3,4,5], :height=>40) + row = @ws.add_row([1, 2, 3, 4, 5], :height => 40) assert_equal(40, row.height) assert(row.custom_height) end 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 = @ws.add_row([1, 2, 3, 4, 5]) + r.style = 1 + r.cells.each { |c| assert_equal(c.style, 1) } end def test_color - r = @ws.add_row([1,2,3,4,5]) + r = @ws.add_row([1, 2, 3, 4, 5]) r.color = "FF00FF00" r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") } end @@ -49,15 +48,14 @@ class TestRow < Test::Unit::TestCase end def test_array_to_cells - r = @ws.add_row [1,2,3], :style=>1, :types=>[:integer, :string, :float] + r = @ws.add_row [1, 2, 3], :style => 1, :types => [:integer, :string, :float] assert_equal(r.cells.size, 3) r.cells.each do |c| assert_equal(c.style, 1) end - r = @ws.add_row [1,2,3], :style=>[1] + 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") - end def test_array_to_cells_with_escape_formulas @@ -88,7 +86,6 @@ class TestRow < Test::Unit::TestCase assert_equal(15, @row.height) end - def test_ph assert_raise(ArgumentError) { @row.ph = -3 } assert_nothing_raised { @row.ph = true } @@ -138,9 +135,9 @@ class TestRow < Test::Unit::TestCase def test_offsets offset = 3 - values = [1,2,3,4,5] + values = [1, 2, 3, 4, 5] r = @ws.add_row(values, offset: offset, style: 1) - r.cells.each_with_index do |c, index| + r.cells.each_with_index do |c, index| assert_equal(c.style, index < offset ? 0 : 1) assert_equal(c.value, index < offset ? nil : values[index - offset]) end @@ -148,13 +145,12 @@ class TestRow < Test::Unit::TestCase def test_offsets_with_styles offset = 3 - values = [1,2,3,4,5] - styles = (1..5).map{ @ws.workbook.styles.add_style } + values = [1, 2, 3, 4, 5] + styles = (1..5).map { @ws.workbook.styles.add_style } r = @ws.add_row(values, offset: offset, style: styles) - r.cells.each_with_index do |c, index| - assert_equal(c.style, index < offset ? 0 : styles[index-offset]) + r.cells.each_with_index do |c, index| + assert_equal(c.style, index < offset ? 0 : styles[index - offset]) assert_equal(c.value, index < offset ? nil : values[index - offset]) end end - end diff --git a/test/workbook/worksheet/tc_selection.rb b/test/workbook/worksheet/tc_selection.rb index 696b67eb..d600aa67 100644 --- a/test/workbook/worksheet/tc_selection.rb +++ b/test/workbook/worksheet/tc_selection.rb @@ -1,9 +1,8 @@ -# encoding: UTF-8 require 'tc_helper.rb' class TestSelection < Test::Unit::TestCase def setup - @options = { :active_cell => 'A2', :active_cell_id => 1, :pane => :top_left, :sqref => 'A2' } + @options = { :active_cell => 'A2', :active_cell_id => 1, :pane => :top_left, :sqref => 'A2' } @selection = Axlsx::Selection.new(@options) end diff --git a/test/workbook/worksheet/tc_sheet_calc_pr.rb b/test/workbook/worksheet/tc_sheet_calc_pr.rb index 05b837cf..9473c94b 100644 --- a/test/workbook/worksheet/tc_sheet_calc_pr.rb +++ b/test/workbook/worksheet/tc_sheet_calc_pr.rb @@ -1,7 +1,6 @@ require 'tc_helper' class TestSheetCalcPr < Test::Unit::TestCase - def setup @sheet_calc_pr = Axlsx::SheetCalcPr.new(:full_calc_on_load => false) end diff --git a/test/workbook/worksheet/tc_sheet_format_pr.rb b/test/workbook/worksheet/tc_sheet_format_pr.rb index b7d7b929..1240da26 100644 --- a/test/workbook/worksheet/tc_sheet_format_pr.rb +++ b/test/workbook/worksheet/tc_sheet_format_pr.rb @@ -1,7 +1,6 @@ require 'tc_helper.rb' class TestSheetFormatPr < Test::Unit::TestCase - def setup @options = { :base_col_width => 5, @@ -45,31 +44,33 @@ class TestSheetFormatPr < Test::Unit::TestCase end def test_default_row_height - assert_raise(ArgumentError) { @sheet_format_pr.default_row_height = :foo } - assert_nothing_raised { @sheet_format_pr.default_row_height= 1.0 } + assert_raise(ArgumentError) { @sheet_format_pr.default_row_height = :foo } + assert_nothing_raised { @sheet_format_pr.default_row_height = 1.0 } end def test_default_col_width - assert_raise(ArgumentError) { @sheet_format_pr.default_col_width= :foo } - assert_nothing_raised { @sheet_format_pr.default_col_width = 1.0 } + assert_raise(ArgumentError) { @sheet_format_pr.default_col_width = :foo } + assert_nothing_raised { @sheet_format_pr.default_col_width = 1.0 } end def test_custom_height - assert_raise(ArgumentError) { @sheet_format_pr.custom_height= :foo } - assert_nothing_raised { @sheet_format_pr.custom_height = true } + assert_raise(ArgumentError) { @sheet_format_pr.custom_height = :foo } + assert_nothing_raised { @sheet_format_pr.custom_height = true } end def test_zero_height - assert_raise(ArgumentError) { @sheet_format_pr.zero_height= :foo } - assert_nothing_raised { @sheet_format_pr.zero_height = true } + assert_raise(ArgumentError) { @sheet_format_pr.zero_height = :foo } + assert_nothing_raised { @sheet_format_pr.zero_height = true } end + def test_thick_top - assert_raise(ArgumentError) { @sheet_format_pr.thick_top= :foo } - assert_nothing_raised { @sheet_format_pr.thick_top = true } + assert_raise(ArgumentError) { @sheet_format_pr.thick_top = :foo } + assert_nothing_raised { @sheet_format_pr.thick_top = true } end + def test_thick_bottom - assert_raise(ArgumentError) { @sheet_format_pr.thick_bottom= :foo } - assert_nothing_raised { @sheet_format_pr.thick_bottom = true } + assert_raise(ArgumentError) { @sheet_format_pr.thick_bottom = :foo } + assert_nothing_raised { @sheet_format_pr.thick_bottom = true } end def test_to_xml_string @@ -84,5 +85,4 @@ class TestSheetFormatPr < Test::Unit::TestCase assert doc.xpath("sheetFormatPr[@outline_level_row=0]") assert doc.xpath("sheetFormatPr[@outline_level_col=0]") end - end diff --git a/test/workbook/worksheet/tc_sheet_pr.rb b/test/workbook/worksheet/tc_sheet_pr.rb index be45438b..70ce0428 100644 --- a/test/workbook/worksheet/tc_sheet_pr.rb +++ b/test/workbook/worksheet/tc_sheet_pr.rb @@ -1,8 +1,6 @@ require 'tc_helper.rb' - class TestSheetPr < Test::Unit::TestCase - def setup worksheet = Axlsx::Package.new.workbook.add_worksheet @options = { @@ -22,7 +20,7 @@ class TestSheetPr < Test::Unit::TestCase def test_initialization @options.each do |key, value| - if key==:tab_color + if key == :tab_color stored_value = @sheet_pr.send(key) assert_equal Axlsx::Color, stored_value.class assert_equal value, stored_value.rgb diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb index 0595d2ec..b14f3e03 100644 --- a/test/workbook/worksheet/tc_sheet_protection.rb +++ b/test/workbook/worksheet/tc_sheet_protection.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 require 'tc_helper.rb' # <xsd:complexType name="CT_SheetProtection"> @@ -20,19 +19,19 @@ require 'tc_helper.rb' # <xsd:attribute name="selectUnlockedCells" type="xsd:boolean" use="optional" default=0/> # <xsd:attribute name="password" type="xsd:string" use="optional" default="nil"/> # </xsd:complexType> - + class TestSheetProtection < Test::Unit::TestCase def setup - #inverse defaults + # inverse defaults @boolean_options = { :sheet => false, :objects => true, :scenarios => true, :format_cells => false, :format_columns => false, :format_rows => false, :insert_columns => false, :insert_rows => false, :insert_hyperlinks => false, :delete_columns => false, :delete_rows => false, :select_locked_cells => true, :sort => false, :auto_filter => false, :pivot_tables => false, :select_unlocked_cells => true } @string_options = { :password => nil } - + @options = @boolean_options.merge(@string_options) - + @sp = Axlsx::SheetProtection.new(@options) end @@ -56,62 +55,7 @@ class TestSheetProtection < Test::Unit::TestCase @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}']")) + assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { $1.upcase }}='#{value}']")) end end - end - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/workbook/worksheet/tc_sheet_view.rb b/test/workbook/worksheet/tc_sheet_view.rb index 3a8e0a06..0f0986cf 100644 --- a/test/workbook/worksheet/tc_sheet_view.rb +++ b/test/workbook/worksheet/tc_sheet_view.rb @@ -1,13 +1,12 @@ -# encoding: UTF-8 $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../" require 'tc_helper.rb' class TestSheetView < Test::Unit::TestCase def setup - #inverse defaults for booleans + # inverse defaults for booleans @boolean_options = { :right_to_left => true, :show_formulas => true, :show_outline_symbols => true, - :show_white_space => true, :tab_selected => true, :default_grid_color => false, :show_grid_lines => false, - :show_row_col_headers => false, :show_ruler => false, :show_zeros => false, :window_protection => true } + :show_white_space => true, :tab_selected => true, :default_grid_color => false, :show_grid_lines => false, + :show_row_col_headers => false, :show_ruler => false, :show_zeros => false, :window_protection => true } @symbol_options = { :view => :page_break_preview } @nil_options = { :color_id => 2, :top_left_cell => 'A2' } @int_0 = { :zoom_scale_normal => 100, :zoom_scale_page_layout_view => 100, :zoom_scale_sheet_layout_view => 100, :workbook_view_id => 2 } @@ -16,7 +15,6 @@ class TestSheetView < Test::Unit::TestCase @integer_options = { :color_id => 2, :workbook_view_id => 2 }.merge(@int_0).merge(@int_100) @string_options = { :top_left_cell => 'A2' } - @options = @boolean_options.merge(@boolean_options).merge(@symbol_options).merge(@nil_options).merge(@int_0).merge(@int_100) @sv = Axlsx::SheetView.new(@options) @@ -207,8 +205,7 @@ class TestSheetView < Test::Unit::TestCase end def test_add_selection - @sv.add_selection(:top_left, :active_cell => "A1") - assert_equal('A1', @sv.selections[:top_left].active_cell) + @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 fd6c1923..7a2e5987 100644 --- a/test/workbook/worksheet/tc_table.rb +++ b/test/workbook/worksheet/tc_table.rb @@ -5,14 +5,13 @@ class TestTable < Test::Unit::TestCase p = Axlsx::Package.new @ws = p.workbook.add_worksheet 40.times do - @ws << ["aa","aa","aa","aa","aa","aa"] + @ws << ["aa", "aa", "aa", "aa", "aa", "aa"] end end def test_initialization assert(@ws.workbook.tables.empty?) assert(@ws.tables.empty?) - end def test_table_style_info diff --git a/test/workbook/worksheet/tc_table_style_info.rb b/test/workbook/worksheet/tc_table_style_info.rb index c0c452c9..3d71dc9b 100644 --- a/test/workbook/worksheet/tc_table_style_info.rb +++ b/test/workbook/worksheet/tc_table_style_info.rb @@ -4,17 +4,15 @@ class TestTableStyleInfo < Test::Unit::TestCase def setup p = Axlsx::Package.new @ws = p.workbook.add_worksheet - 40.times do + 40.times do @ws.add_row %w(aa bb cc dd ee ff gg hh ii jj kk) end - @table = @ws.add_table(Axlsx::cell_range([@ws.rows.first.cells.first,@ws.rows.last.cells.last], false), :name => 'foo') + @table = @ws.add_table(Axlsx::cell_range([@ws.rows.first.cells.first, @ws.rows.last.cells.last], false), :name => 'foo') @options = { :show_first_column => 1, - :show_last_column => 1, - :show_row_stripes => 1, - :show_column_stripes => 1, - :name => "TableStyleDark4" } - - + :show_last_column => 1, + :show_row_stripes => 1, + :show_column_stripes => 1, + :name => "TableStyleDark4" } end def test_initialize @@ -27,10 +25,11 @@ class TestTableStyleInfo < Test::Unit::TestCase def test_boolean_properties table_style = Axlsx::TableStyleInfo.new @options.keys.each do |key| - assert_nothing_raised { table_style.send("#{key.to_sym}=", true) } - assert_raises(ArgumentError) { table_style.send(key.to_sym, 'foo') } + assert_nothing_raised { table_style.send("#{key.to_sym}=", true) } + assert_raises(ArgumentError) { table_style.send(key.to_sym, 'foo') } end end + def doc @doc ||= Nokogiri::XML(Axlsx::TableStyleInfo.new(@options).to_xml_string) end diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 8e0c5696..f6c65fe4 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -7,7 +7,6 @@ class TestWorksheet < Test::Unit::TestCase @ws = @wb.add_worksheet end - def test_pn assert_equal(@ws.pn, "worksheets/sheet1.xml") ws = @ws.workbook.add_worksheet @@ -30,7 +29,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_name_unique - assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) } + assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name => n) } end def test_name_unique_only_checks_other_worksheet_names @@ -108,15 +107,15 @@ class TestWorksheet < Test::Unit::TestCase def test_no_autowidth @ws.workbook.use_autowidth = false - @ws.add_row [1,2,3,4] + @ws.add_row [1, 2, 3, 4] assert_equal(@ws.column_info[0].width, nil) end def test_initialization_options - page_margins = {:left => 2, :right => 2, :bottom => 2, :top => 2, :header => 2, :footer => 2} - page_setup = {:fit_to_height => 1, :fit_to_width => 1, :orientation => :landscape, :paper_width => "210mm", :paper_height => "297mm", :scale => 80} - 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'} + page_margins = { :left => 2, :right => 2, :bottom => 2, :top => 2, :header => 2, :footer => 2 } + page_setup = { :fit_to_height => 1, :fit_to_width => 1, :orientation => :landscape, :paper_width => "210mm", :paper_height => "297mm", :scale => 80 } + 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.keys.each do |key| assert_equal(page_margins[key], optioned.page_margins.send(key)) @@ -131,10 +130,8 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(header_footer[key], optioned.header_footer.send(key)) end assert_equal(optioned.name, 'bob') - end - # def test_use_gridlines # assert_raise(ArgumentError) { @ws.show_gridlines = -1.1 } # assert_nothing_raised { @ws.show_gridlines = false } @@ -178,8 +175,8 @@ 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(@ws.rows[0], first_row) + assert_equal(@ws.rows[1], last_row) assert_equal(range.size, 6) assert_equal(range.first, @ws.rows.first.cells.first) assert_equal(range.last, @ws.rows.last.cells.last) @@ -187,7 +184,7 @@ class TestWorksheet < Test::Unit::TestCase def test_add_row assert(@ws.rows.empty?, "sheet has no rows by default") - r = @ws.add_row([1,2,3]) + r = @ws.add_row([1, 2, 3]) assert_equal(@ws.rows.size, 1, "add_row adds a row") assert_equal(@ws.rows.first, r, "the row returned is the row added") end @@ -210,7 +207,6 @@ 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?) @ws.add_page_break(@ws.rows.last.cells[1]) @@ -218,7 +214,6 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(1, @ws.col_breaks.size) end - def test_drawing assert @ws.drawing == nil @ws.add_chart(Axlsx::Pie3DChart) @@ -232,12 +227,12 @@ class TestWorksheet < Test::Unit::TestCase end def test_col_style - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3,4] - @ws.col_style( (1..2), 1, :row_offset=>1) - @ws.rows[(1..-1)].each do | r | + @ws.add_row [1, 2, 3, 4] + @ws.add_row [1, 2, 3, 4] + @ws.add_row [1, 2, 3, 4] + @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) end @@ -246,41 +241,41 @@ class TestWorksheet < Test::Unit::TestCase end def test_col_style_with_empty_column - @ws.add_row [1,2,3,4] + @ws.add_row [1, 2, 3, 4] @ws.add_row [1] - @ws.add_row [1,2,3,4] - assert_nothing_raised {@ws.col_style(1, 1)} + @ws.add_row [1, 2, 3, 4] + assert_nothing_raised { @ws.col_style(1, 1) } end def test_cols - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3] - @ws.add_row [1,2,3,4] + @ws.add_row [1, 2, 3, 4] + @ws.add_row [1, 2, 3, 4] + @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) end def test_cols_with_block - @ws.add_row [1,2,3] + @ws.add_row [1, 2, 3] @ws.add_row [1] - cols = @ws.cols {|row, column| :foo } + cols = @ws.cols { |row, column| :foo } assert_equal(:foo, cols[1][1]) end def test_row_style - @ws.add_row [1,2,3,4] - @ws.add_row [1,2,3,4] - @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 | + @ws.add_row [1, 2, 3, 4] + @ws.add_row [1, 2, 3, 4] + @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) end assert_equal(@ws.rows[1].cells[0].style, 0) assert_equal(@ws.rows[2].cells[1].style, 0) - @ws.row_style( 1..2, 1, :col_offset => 2) + @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) @@ -295,7 +290,7 @@ class TestWorksheet < Test::Unit::TestCase # end def test_to_xml_string_dimensions - @ws.add_row [1,2,3] + @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) end @@ -353,7 +348,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_to_xml_string_row_breaks - @ws.add_page_break("A1") + @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) end @@ -419,7 +414,7 @@ class TestWorksheet < Test::Unit::TestCase 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(schema.validate(doc).map { |e| puts e.message; e }.empty?, "error free validation") end def test_styles @@ -429,7 +424,7 @@ class TestWorksheet < Test::Unit::TestCase def test_to_xml_string_with_illegal_chars old = Axlsx::trust_input Axlsx::trust_input = false - nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f" + 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")) @@ -442,6 +437,7 @@ class TestWorksheet < Test::Unit::TestCase 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 + # Make sure the XML for all optional elements (like pageMargins, autoFilter, ...) # is generated in correct order. def test_valid_with_optional_elements @@ -452,14 +448,14 @@ class TestWorksheet < Test::Unit::TestCase @ws.merge_cells "A4:A5" @ws.add_chart Axlsx::Pie3DChart @ws.add_table "E1:F3" - @ws.add_pivot_table 'G5:G6', 'A1:D10' + @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 { |e| e.message }.join('\n')) end def test_relationships - @ws.add_row [1,2,3] + @ws.add_row [1, 2, 3] assert(@ws.relationships.empty?, "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") @@ -533,14 +529,14 @@ class TestWorksheet < Test::Unit::TestCase def test_protect_range_with_cells @ws.add_row [1, 2, 3] - assert_nothing_raised {@ws.protect_range(@ws.rows.first.cells) } + assert_nothing_raised { @ws.protect_range(@ws.rows.first.cells) } assert_equal('A1:C1', @ws.send(:protected_ranges).last.sqref) end def test_merge_cells - @ws.add_row [1,2,3] - @ws.add_row [4,5,6] - @ws.add_row [7,8,9] + @ws.add_row [1, 2, 3] + @ws.add_row [4, 5, 6] + @ws.add_row [7, 8, 9] @ws.merge_cells "A1:A2" @ws.merge_cells "B2:C3" @ws.merge_cells @ws.rows.last.cells[(0..1)] @@ -558,12 +554,12 @@ class TestWorksheet < Test::Unit::TestCase def test_auto_filter assert(@ws.auto_filter.range.nil?) - assert(@wb.defined_names.none?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) + 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") @ws.to_xml_string - assert(@wb.defined_names.any?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) + assert(@wb.defined_names.any? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }) end def test_auto_filter_assign @@ -571,7 +567,7 @@ class TestWorksheet < Test::Unit::TestCase assert(@ws.auto_filter.range.nil?) assert(other_ws.auto_filter.range.nil?) - assert(@wb.defined_names.none?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) + assert(@wb.defined_names.none? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }) assert_raise(ArgumentError) { @ws.auto_filter = 123 } @ws.auto_filter = "A1:D9" @@ -583,13 +579,12 @@ class TestWorksheet < Test::Unit::TestCase @ws.to_xml_string other_ws.to_xml_string - filter_database = @wb.defined_names.select{|defined_name| defined_name.name=='_xlnm._FilterDatabase'} + 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) end - def test_sheet_pr_for_auto_filter @ws.auto_filter.range = 'A1:D9' @ws.auto_filter.add_column 0, :filters, :filter_items => [1] @@ -598,7 +593,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_outline_level_rows - 3.times { @ws.add_row [1,2,3] } + 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) @@ -606,7 +601,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_outline_level_columns - 3.times { @ws.add_row [1,2,3] } + 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) @@ -695,7 +690,7 @@ class TestWorksheet < Test::Unit::TestCase sheet.add_row ['', 'Butter', 'Dairy', 4.99] sheet.add_row ['', 'Bread', 'Baked Goods', 3.45] sheet.add_row ['', 'Broccoli', 'Produce', 2.99] - sheet.add_row ['', 'Pizza', 'Frozen Foods', 4.99] + sheet.add_row ['', 'Pizza', 'Frozen Foods', 4.99] sheet.column_widths 5, 20, 20, 20 sheet.add_style 'B2:D2', b: true @@ -722,16 +717,16 @@ class TestWorksheet < Test::Unit::TestCase wb.add_worksheet do |sheet| 20.times.each do - sheet.add_row [1,2,3,4,5] + sheet.add_row [1, 2, 3, 4, 5] end sheet.add_border "B2:D5" - sheet.add_border ["C3:C4", "D3:D4", "A2"], {color: "FF00000"} + sheet.add_border ["C3:C4", "D3:D4", "A2"], { color: "FF00000" } sheet.add_border "B10:E10", [:top, :bottom, :left, :right] sheet.add_border "B12:E12", :all sheet.add_border "B14:E14", Axlsx::Border::EDGES - sheet.add_border "B16:E16", {edges: :all, style: :thick} - sheet.add_border "B18:E18", {edges: [:top], style: :thick, color: "FFFFF00"} + sheet.add_border "B16:E16", { edges: :all, style: :thick } + sheet.add_border "B18:E18", { edges: [:top], style: :thick, color: "FFFFF00" } end wb.apply_styles @@ -791,7 +786,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} + assert_equal b2_cell_style, wb.styles.style_index.values.find { |x| x == b2_cell_style } d3_cell_style = { border: { @@ -804,7 +799,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} + assert_equal d3_cell_style, wb.styles.style_index.values.find { |x| x == d3_cell_style } end def test_mixed_borders_1 @@ -838,7 +833,7 @@ class TestWorksheet < Test::Unit::TestCase sheet.add_border 'B2:D4', style: :medium sheet.add_style 'D2:D4', border: { style: :thin, color: '000000' } end - + wb.apply_styles assert_equal 8, wb.styled_cells.count @@ -877,24 +872,23 @@ class TestWorksheet < Test::Unit::TestCase wb.styles.fonts[0].sz = 12 wb.add_worksheet do |sheet| - sheet.add_row [1,2,3] + sheet.add_row [1, 2, 3] sheet.add_style "A1:C1", { color: "FFFFFF" } end wb.apply_styles assert_equal 1, wb.styles.style_index.size - + assert_equal( { - type: :xf, - name: "Times New Roman", - sz: 12, - family: 1, - color: "FFFFFF", - }, + type: :xf, + name: "Times New Roman", + sz: 12, + family: 1, + color: "FFFFFF" + }, wb.styles.style_index.values.first ) end - end diff --git a/test/workbook/worksheet/tc_worksheet_hyperlink.rb b/test/workbook/worksheet/tc_worksheet_hyperlink.rb index 88a40bc6..98b6937b 100644 --- a/test/workbook/worksheet/tc_worksheet_hyperlink.rb +++ b/test/workbook/worksheet/tc_worksheet_hyperlink.rb @@ -22,13 +22,13 @@ class TestWorksheetHyperlink < Test::Unit::TestCase end def test_target - assert_equal(@options[:target], Axlsx.instance_values_for(@a)['target']) end def test_display assert_equal(@options[:display], @a.display) end + def test_ref assert_equal(@options[:ref], @a.ref) end @@ -52,5 +52,3 @@ class TestWorksheetHyperlink < Test::Unit::TestCase assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size, 1) end end - - |
