Permalink
Browse files

fix ALL the warnings!

  • Loading branch information...
1 parent 0297bd5 commit c8b40481b1ab947fbb783657e19749b59b716cfe @randym committed May 17, 2012
View
@@ -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
@@ -195,7 +195,7 @@ def scheme=(v)
# @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
@@ -488,12 +488,12 @@ def to_xml_string
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
@@ -13,7 +13,7 @@ def test_initialization
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 @@ def test_to_xml_string
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
@@ -19,11 +19,6 @@ def test_href
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")
@@ -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]
@@ -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
@@ -19,15 +19,15 @@ def test_valid_document
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"} }
assert_equal @styles.borders.last.prs.size, 4
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 @@ def test_do_not_alter_options_in_add_style
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 @@ def test_add_style
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 }
View
@@ -51,18 +51,17 @@ def test_default_objects_are_created
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 @@ def test_base_content_types
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
@@ -8,15 +8,15 @@ def teardown
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|
@@ -34,17 +34,17 @@ def test_charts
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
@@ -33,7 +33,7 @@ def test_index
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 @@ def test_to_xml_string_nil
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 @@ def test_to_xml_string_with_run
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 = []
@@ -37,9 +37,16 @@ def test_pn
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)
@@ -23,7 +23,7 @@ def test_maxLength
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)
@@ -39,7 +39,7 @@ def test_add_cell
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 @@ def test_outlineLevel
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)
@@ -280,7 +280,7 @@ def test_to_xml_string_print_options
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 @@ def test_relationships
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

0 comments on commit c8b4048

Please sign in to comment.