diff options
| -rw-r--r-- | Rakefile | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 12 | ||||
| -rw-r--r-- | test/drawing/tc_axis.rb | 8 | ||||
| -rw-r--r-- | test/drawing/tc_hyperlink.rb | 5 | ||||
| -rw-r--r-- | test/drawing/tc_scatter_chart.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_two_cell_anchor.rb | 3 | ||||
| -rw-r--r-- | test/stylesheet/tc_styles.rb | 7 | ||||
| -rw-r--r-- | test/tc_package.rb | 17 | ||||
| -rw-r--r-- | test/util/tc_validators.rb | 14 | ||||
| -rw-r--r-- | test/workbook/worksheet/table/tc_table.rb | 6 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 11 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_comments.rb | 9 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_data_bar.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_row.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 4 |
16 files changed, 55 insertions, 54 deletions
@@ -18,7 +18,8 @@ task :test do Rake::TestTask.new do |t| t.libs << 'test' t.test_files = FileList['test/**/tc_*.rb'] - t.verbose = true + t.verbose = false + t.warning = true end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 2684af75..745809f9 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -195,7 +195,7 @@ module Axlsx # @option options [Symbol] scheme must be one of :none, major, :minor def initialize(row, value="", options={}) self.row=row - @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil + @value = @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil @styles = row.worksheet.workbook.styles @row.cells << self diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 854e629c..b104b054 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -488,12 +488,12 @@ module Axlsx str.concat "<drawing r:id='rId1'></drawing>" if @drawing str << '<legacyDrawing r:id="rId1"/>' if @comments.size > 0 unless @tables.empty? - str.concat "<tableParts count='%s'>%s</tableParts>" % [@tables.size, @tables.reduce('') { |memo, obj| memo += "<tablePart r:id='%s'/>" % obj.rId }] - end - @conditional_formattings.each do |cf| - str.concat cf.to_xml_string - end - str + '</worksheet>' + str.concat "<tableParts count='%s'>%s</tableParts>" % [@tables.size, @tables.reduce('') { |memo, obj| memo += "<tablePart r:id='%s'/>" % obj.rId }] + end + @conditional_formattings.each do |cf| + str.concat cf.to_xml_string + end + str + '</worksheet>' end # The worksheet relationships. This is managed automatically by the worksheet diff --git a/test/drawing/tc_axis.rb b/test/drawing/tc_axis.rb index c86d3c50..77eb61a1 100644 --- a/test/drawing/tc_axis.rb +++ b/test/drawing/tc_axis.rb @@ -13,7 +13,7 @@ class TestAxis < Test::Unit::TestCase assert_equal(@axis.tickLblPos, :nextTo, "tick label position default incorrect") assert_equal(@axis.crosses, :autoZero, "tick label position default incorrect") assert(@axis.scaling.is_a?(Axlsx::Scaling) && @axis.scaling.orientation == :minMax, "scaling default incorrect") - assert_raise(ArgumentError) { Axlsx::Axis.new -1234, 'abcd' } + assert_raise(ArgumentError) { Axlsx::Axis.new( -1234, 'abcd') } end def test_axis_position @@ -54,9 +54,9 @@ class TestAxis < Test::Unit::TestCase str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">' doc = Nokogiri::XML(@axis.to_xml_string(str)) assert(doc.xpath('//a:noFill')) - assert(doc.xpath("//c:crosses[@val='#{@crosses.to_s}']")) - assert(doc.xpath("//c:crossAx[@val='#{@crossAx.to_s}']")) - assert(doc.xpath("//a:bodyPr[@rot='#{@label_rotation.to_s}']")) + assert(doc.xpath("//c:crosses[@val='#{@axis.crosses.to_s}']")) + assert(doc.xpath("//c:crossAx[@val='#{@axis.crossAx.to_s}']")) + assert(doc.xpath("//a:bodyPr[@rot='#{@axis.label_rotation.to_s}']")) end end diff --git a/test/drawing/tc_hyperlink.rb b/test/drawing/tc_hyperlink.rb index 4d95e67a..292f1f96 100644 --- a/test/drawing/tc_hyperlink.rb +++ b/test/drawing/tc_hyperlink.rb @@ -19,11 +19,6 @@ class TestHyperlink < Test::Unit::TestCase assert_equal(@hyperlink.href, "http://axlsx.blogspot.com") end - def test_invalidUrl - assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" } - assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com") - end - def test_tgtFrame assert_nothing_raised { @hyperlink.tgtFrame = "http://axlsx.blogspot.com" } assert_equal(@hyperlink.tgtFrame, "http://axlsx.blogspot.com") diff --git a/test/drawing/tc_scatter_chart.rb b/test/drawing/tc_scatter_chart.rb index a60bba76..15b1f0a0 100644 --- a/test/drawing/tc_scatter_chart.rb +++ b/test/drawing/tc_scatter_chart.rb @@ -4,7 +4,7 @@ class TestScatterChart < Test::Unit::TestCase def setup @p = Axlsx::Package.new @chart = nil - ws = @p.workbook.add_worksheet do |sheet| + @p.workbook.add_worksheet do |sheet| sheet.add_row ["First", 1, 5, 7, 9] sheet.add_row ["", 1, 25, 49, 81] sheet.add_row ["Second", 5, 2, 14, 9] diff --git a/test/drawing/tc_two_cell_anchor.rb b/test/drawing/tc_two_cell_anchor.rb index c3e58d94..66f8bd58 100644 --- a/test/drawing/tc_two_cell_anchor.rb +++ b/test/drawing/tc_two_cell_anchor.rb @@ -5,8 +5,7 @@ class TestTwoCellAnchor < Test::Unit::TestCase def setup p = Axlsx::Package.new @ws = p.workbook.add_worksheet - row = @ws.add_row ["one", 1, Time.now] - title = Axlsx::Title.new + @ws.add_row ["one", 1, Time.now] chart = @ws.add_chart Axlsx::Bar3DChart @anchor = chart.graphic_frame.anchor end diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index 719a066b..e43d9b55 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -19,7 +19,7 @@ class TestStyles < Test::Unit::TestCase end def test_add_style_border_hash border_count = @styles.borders.size - s = @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"} } @@ -27,7 +27,7 @@ class TestStyles < Test::Unit::TestCase end def test_add_style_border_edges - s = @styles.add_style :border => { :style => :thin, :color => "0000FFFF", :edges => [:top, :bottom] } + @styles.add_style :border => { :style => :thin, :color => "0000FFFF", :edges => [:top, :bottom] } parts = @styles.borders.last.prs parts.each { |pr| assert_equal(pr.color.rgb, "0000FFFF", "Style is applied to #{pr.name} properly") } assert((parts.map { |pr| pr.name.to_s }.sort && ['bottom', 'top']).size == 2, "specify two edges, and you get two border prs") @@ -44,7 +44,6 @@ class TestStyles < Test::Unit::TestCase def test_parse_num_fmt f_code = {:format_code => "YYYY/MM"} num_fmt = {:num_fmt => 5} - both = { :format_code => "#000", :num_fmt => 0 } 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 @styles.parse_num_fmt_options(f_code) @@ -181,7 +180,7 @@ class TestStyles < Test::Unit::TestCase def test_basic_add_style_dxf border_count = @styles.borders.size - s = @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 } diff --git a/test/tc_package.rb b/test/tc_package.rb index 60f5f0a7..d51f0f5f 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -51,18 +51,17 @@ class TestPackage < Test::Unit::TestCase end def test_serialization - fname = 'axlsx_test_serialization.xlsx' assert_nothing_raised do begin - z= @package.serialize(@fname) - zf = Zip::ZipFile.open(@fname) - @package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } - File.delete(@fname) + @package.serialize(@fname) + zf = Zip::ZipFile.open(@fname) + @package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } + File.delete(@fname) rescue Errno::EACCES - puts "WARNING:: test_serialization requires write access." + puts "WARNING:: test_serialization requires write access." end - end - end + end + end def test_validation assert_equal(@package.validate.size, 0, @package.validate) @@ -120,7 +119,7 @@ class TestPackage < Test::Unit::TestCase def test_content_type_added_with_shared_strings @package.use_shared_strings = true ct = @package.send(:content_types) - assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1) + assert(ct.select { |type| type.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1) end def test_name_to_indices diff --git a/test/util/tc_validators.rb b/test/util/tc_validators.rb index 2a0a0229..bcb2eadf 100644 --- a/test/util/tc_validators.rb +++ b/test/util/tc_validators.rb @@ -8,15 +8,15 @@ class TestValidators < Test::Unit::TestCase def test_validators #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_nothing_raised { Axlsx.validate_unsigned_int(+1) } + assert_raise(ArgumentError) { Axlsx.validate_unsigned_int(-1)} + assert_raise(ArgumentError) { Axlsx.validate_unsigned_int('1') } #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 Array } + 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(Array) } #boolean (as 0 or 1, :true, :false, true, false, or "true," "false") [0,1,:true, :false, true, false, "true", "false"].each do |v| diff --git a/test/workbook/worksheet/table/tc_table.rb b/test/workbook/worksheet/table/tc_table.rb index d4acf39a..c8e56fc3 100644 --- a/test/workbook/worksheet/table/tc_table.rb +++ b/test/workbook/worksheet/table/tc_table.rb @@ -34,17 +34,17 @@ class TestTable < Test::Unit::TestCase end def test_pn - table = @ws.add_table("A1:D5") + @ws.add_table("A1:D5") assert_equal(@ws.tables.first.pn, "tables/table1.xml") end def test_rId - table = @ws.add_table("A1:D5") + @ws.add_table("A1:D5") assert_equal(@ws.tables.first.rId, "rId1") end def test_index - table = @ws.add_table("A1:D5") + @ws.add_table("A1:D5") assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first)) end diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index c486a770..fccffc64 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -33,7 +33,7 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.index, @row.cells.index(@c)) end - def test_index + def test_pos assert_equal(@c.pos, [@c.index, @c.row.index]) end @@ -250,6 +250,7 @@ class TestCell < Test::Unit::TestCase 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_with_run @c.b = true @c.type = :string @@ -261,17 +262,17 @@ class TestCell < Test::Unit::TestCase end def test_to_xml_string_formula p = Axlsx::Package.new - ws = p.workbook.add_worksheet do |ws| - ws.add_row ["=IF(2+2=4,4,5)"] + ws = p.workbook.add_worksheet do |sheet| + sheet.add_row ["=IF(2+2=4,4,5)"] end doc = Nokogiri::XML(ws.to_xml_string) - assert("//f[text()=['IF(2+2=4,4,5)']") + assert(doc.xpath("//f[@text()='IF(2+2=4,4,5)']")) end def test_to_xml # TODO This could use some much more stringent testing related to the xml content generated! - row = @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"] + @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"] schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) errors = [] diff --git a/test/workbook/worksheet/tc_comments.rb b/test/workbook/worksheet/tc_comments.rb index cbc267ad..665f3598 100644 --- a/test/workbook/worksheet/tc_comments.rb +++ b/test/workbook/worksheet/tc_comments.rb @@ -37,9 +37,16 @@ class TestComments < Test::Unit::TestCase def test_index assert_equal(@ws.index, @ws.comments.index) end + def test_to_xml_string doc = Nokogiri::XML(@ws.comments.to_xml_string) - # puts doc.xpath("comments").to_xml + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) + errors = [] + schema.validate(doc).each do |error| + errors << error + end + assert_equal(0, errors.length) + # TODO figure out why these xpath expressions dont work! # assert(doc.xpath("//comments")) # assert_equal(doc.xpath("//xmlns:author").size, @ws.comments.authors.size) diff --git a/test/workbook/worksheet/tc_data_bar.rb b/test/workbook/worksheet/tc_data_bar.rb index 644ce6bd..af803f23 100644 --- a/test/workbook/worksheet/tc_data_bar.rb +++ b/test/workbook/worksheet/tc_data_bar.rb @@ -23,7 +23,7 @@ class TestDataBar < Test::Unit::TestCase assert_equal(@data_bar.maxLength, 0) end - def test_maxLength + def test_showValue assert_raise(ArgumentError) { @data_bar.showValue = :invalid_type } assert_nothing_raised { @data_bar.showValue = false} assert_equal(@data_bar.showValue, false) diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index a5bacdbf..bfd5ae9f 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -39,7 +39,7 @@ class TestRow < Test::Unit::TestCase def test_add_cell_autowidth_info width = @ws.send :calculate_width, 'this is the cell of cells', @ws.workbook.styles.fonts.first.sz - c = @row.add_cell("this is the cell of cells") + @row.add_cell("this is the cell of cells") assert_equal(@ws.column_info.last.width, width) end @@ -91,7 +91,7 @@ class TestRow < Test::Unit::TestCase assert_equal(2, @row.outlineLevel) end - def test_to_xml_without_custom_height + def test_to_xml_without_custom_height doc = Nokogiri::XML.parse(@row.to_xml_string(0)) assert_equal(0, doc.xpath(".//row[@ht]").size) assert_equal(0, doc.xpath(".//row[@customHeight]").size) diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 0155a959..857437d8 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -280,7 +280,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_to_xml_string_drawing - c = @ws.add_chart Axlsx::Pie3DChart + @ws.add_chart Axlsx::Pie3DChart doc = Nokogiri::XML(@ws.to_xml_string) assert_equal(doc.xpath('//xmlns:worksheet/xmlns:drawing[@r:id="rId1"]').size, 1) end @@ -347,7 +347,7 @@ class TestWorksheet < Test::Unit::TestCase def test_name_unique - assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) } + assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) } end def test_name_size |
