diff options
| author | Geremia Taglialatela <[email protected]> | 2023-04-13 13:13:34 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-03 16:05:17 +0200 |
| commit | 350f7ae9a04f3d39c099cc54f7c04bf31f385d96 (patch) | |
| tree | e84af2a70d3b18a0b94c784338faf48215c9c8a8 /test/stylesheet | |
| parent | e81036b76e734ab03fac31faafb9732f6b3b2928 (diff) | |
| download | caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.tar.gz caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.zip | |
Add RuboCop Minitest
Diffstat (limited to 'test/stylesheet')
| -rw-r--r-- | test/stylesheet/tc_border.rb | 12 | ||||
| -rw-r--r-- | test/stylesheet/tc_border_pr.rb | 10 | ||||
| -rw-r--r-- | test/stylesheet/tc_cell_alignment.rb | 37 | ||||
| -rw-r--r-- | test/stylesheet/tc_cell_protection.rb | 8 | ||||
| -rw-r--r-- | test/stylesheet/tc_cell_style.rb | 24 | ||||
| -rw-r--r-- | test/stylesheet/tc_color.rb | 13 | ||||
| -rw-r--r-- | test/stylesheet/tc_dxf.rb | 14 | ||||
| -rw-r--r-- | test/stylesheet/tc_font.rb | 55 | ||||
| -rw-r--r-- | test/stylesheet/tc_gradient_fill.rb | 28 | ||||
| -rw-r--r-- | test/stylesheet/tc_gradient_stop.rb | 9 | ||||
| -rw-r--r-- | test/stylesheet/tc_num_fmt.rb | 8 | ||||
| -rw-r--r-- | test/stylesheet/tc_pattern_fill.rb | 13 | ||||
| -rw-r--r-- | test/stylesheet/tc_styles.rb | 108 | ||||
| -rw-r--r-- | test/stylesheet/tc_table_style.rb | 20 | ||||
| -rw-r--r-- | test/stylesheet/tc_table_style_element.rb | 14 | ||||
| -rw-r--r-- | test/stylesheet/tc_table_styles.rb | 8 | ||||
| -rw-r--r-- | test/stylesheet/tc_xf.rb | 56 |
17 files changed, 237 insertions, 200 deletions
diff --git a/test/stylesheet/tc_border.rb b/test/stylesheet/tc_border.rb index f7791d94..4060dbf5 100644 --- a/test/stylesheet/tc_border.rb +++ b/test/stylesheet/tc_border.rb @@ -8,28 +8,28 @@ class TestBorder < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@b.diagonalUp, nil) - assert_equal(@b.diagonalDown, nil) - assert_equal(@b.outline, nil) + assert_nil(@b.diagonalUp) + assert_nil(@b.diagonalDown) + assert_nil(@b.outline) assert(@b.prs.is_a?(Axlsx::SimpleTypedList)) end def test_diagonalUp assert_raise(ArgumentError) { @b.diagonalUp = :red } assert_nothing_raised { @b.diagonalUp = true } - assert_equal(@b.diagonalUp, true) + assert(@b.diagonalUp) end def test_diagonalDown assert_raise(ArgumentError) { @b.diagonalDown = :red } assert_nothing_raised { @b.diagonalDown = true } - assert_equal(@b.diagonalDown, true) + assert(@b.diagonalDown) end def test_outline assert_raise(ArgumentError) { @b.outline = :red } assert_nothing_raised { @b.outline = true } - assert_equal(@b.outline, true) + assert(@b.outline) end def test_prs diff --git a/test/stylesheet/tc_border_pr.rb b/test/stylesheet/tc_border_pr.rb index 652f4f6d..90f18586 100644 --- a/test/stylesheet/tc_border_pr.rb +++ b/test/stylesheet/tc_border_pr.rb @@ -8,9 +8,9 @@ class TestBorderPr < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@bpr.color, nil) - assert_equal(@bpr.style, nil) - assert_equal(@bpr.name, nil) + assert_nil(@bpr.color) + assert_nil(@bpr.style) + assert_nil(@bpr.name) end def test_color @@ -22,12 +22,12 @@ class TestBorderPr < Test::Unit::TestCase def test_style assert_raise(ArgumentError) { @bpr.style = :red } assert_nothing_raised { @bpr.style = :thin } - assert_equal(@bpr.style, :thin) + assert_equal(:thin, @bpr.style) end def test_name assert_raise(ArgumentError) { @bpr.name = :red } assert_nothing_raised { @bpr.name = :top } - assert_equal(@bpr.name, :top) + assert_equal(:top, @bpr.name) end end diff --git a/test/stylesheet/tc_cell_alignment.rb b/test/stylesheet/tc_cell_alignment.rb index 0b514bf4..28e0d272 100644 --- a/test/stylesheet/tc_cell_alignment.rb +++ b/test/stylesheet/tc_cell_alignment.rb @@ -6,19 +6,20 @@ class TestCellAlignment < Test::Unit::TestCase end def test_initialiation - assert_equal(@item.horizontal, nil) - assert_equal(@item.vertical, nil) - assert_equal(@item.textRotation, nil) - assert_equal(@item.wrapText, nil) - assert_equal(@item.indent, nil) - assert_equal(@item.relativeIndent, nil) - assert_equal(@item.justifyLastLine, nil) - assert_equal(@item.shrinkToFit, nil) - assert_equal(@item.readingOrder, nil) + assert_nil(@item.horizontal) + assert_nil(@item.vertical) + assert_nil(@item.textRotation) + assert_nil(@item.wrapText) + assert_nil(@item.indent) + assert_nil(@item.relativeIndent) + assert_nil(@item.justifyLastLine) + assert_nil(@item.shrinkToFit) + assert_nil(@item.readingOrder) 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) end @@ -27,54 +28,54 @@ class TestCellAlignment < Test::Unit::TestCase def test_horizontal assert_raise(ArgumentError) { @item.horizontal = :red } assert_nothing_raised { @item.horizontal = :left } - assert_equal(@item.horizontal, :left) + assert_equal(:left, @item.horizontal) end def test_vertical assert_raise(ArgumentError) { @item.vertical = :red } assert_nothing_raised { @item.vertical = :top } - assert_equal(@item.vertical, :top) + assert_equal(:top, @item.vertical) end def test_textRotation assert_raise(ArgumentError) { @item.textRotation = -1 } assert_nothing_raised { @item.textRotation = 5 } - assert_equal(@item.textRotation, 5) + assert_equal(5, @item.textRotation) end def test_wrapText assert_raise(ArgumentError) { @item.wrapText = -1 } assert_nothing_raised { @item.wrapText = false } - assert_equal(@item.wrapText, false) + refute(@item.wrapText) end def test_indent assert_raise(ArgumentError) { @item.indent = -1 } assert_nothing_raised { @item.indent = 5 } - assert_equal(@item.indent, 5) + assert_equal(5, @item.indent) end def test_relativeIndent assert_raise(ArgumentError) { @item.relativeIndent = :symbol } assert_nothing_raised { @item.relativeIndent = 5 } - assert_equal(@item.relativeIndent, 5) + assert_equal(5, @item.relativeIndent) end def test_justifyLastLine assert_raise(ArgumentError) { @item.justifyLastLine = -1 } assert_nothing_raised { @item.justifyLastLine = true } - assert_equal(@item.justifyLastLine, true) + assert(@item.justifyLastLine) end def test_shrinkToFit assert_raise(ArgumentError) { @item.shrinkToFit = -1 } assert_nothing_raised { @item.shrinkToFit = true } - assert_equal(@item.shrinkToFit, true) + assert(@item.shrinkToFit) end def test_readingOrder assert_raise(ArgumentError) { @item.readingOrder = -1 } assert_nothing_raised { @item.readingOrder = 2 } - assert_equal(@item.readingOrder, 2) + assert_equal(2, @item.readingOrder) end end diff --git a/test/stylesheet/tc_cell_protection.rb b/test/stylesheet/tc_cell_protection.rb index 253b6c82..631192de 100644 --- a/test/stylesheet/tc_cell_protection.rb +++ b/test/stylesheet/tc_cell_protection.rb @@ -8,19 +8,19 @@ class TestCellProtection < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.hidden, nil) - assert_equal(@item.locked, nil) + assert_nil(@item.hidden) + assert_nil(@item.locked) end def test_hidden assert_raise(ArgumentError) { @item.hidden = -1 } assert_nothing_raised { @item.hidden = false } - assert_equal(@item.hidden, false) + refute(@item.hidden) end def test_locked assert_raise(ArgumentError) { @item.locked = -1 } assert_nothing_raised { @item.locked = false } - assert_equal(@item.locked, false) + refute(@item.locked) end end diff --git a/test/stylesheet/tc_cell_style.rb b/test/stylesheet/tc_cell_style.rb index 06f20af3..d62e68ed 100644 --- a/test/stylesheet/tc_cell_style.rb +++ b/test/stylesheet/tc_cell_style.rb @@ -8,47 +8,47 @@ class TestCellStyle < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.name, nil) - assert_equal(@item.xfId, nil) - assert_equal(@item.builtinId, nil) - assert_equal(@item.iLevel, nil) - assert_equal(@item.hidden, nil) - assert_equal(@item.customBuiltin, nil) + assert_nil(@item.name) + assert_nil(@item.xfId) + assert_nil(@item.builtinId) + assert_nil(@item.iLevel) + assert_nil(@item.hidden) + assert_nil(@item.customBuiltin) end def test_name assert_raise(ArgumentError) { @item.name = -1 } assert_nothing_raised { @item.name = "stylin" } - assert_equal(@item.name, "stylin") + assert_equal("stylin", @item.name) end def test_xfId assert_raise(ArgumentError) { @item.xfId = -1 } assert_nothing_raised { @item.xfId = 5 } - assert_equal(@item.xfId, 5) + assert_equal(5, @item.xfId) end def test_builtinId assert_raise(ArgumentError) { @item.builtinId = -1 } assert_nothing_raised { @item.builtinId = 5 } - assert_equal(@item.builtinId, 5) + assert_equal(5, @item.builtinId) end def test_iLevel assert_raise(ArgumentError) { @item.iLevel = -1 } assert_nothing_raised { @item.iLevel = 5 } - assert_equal(@item.iLevel, 5) + assert_equal(5, @item.iLevel) end def test_hidden assert_raise(ArgumentError) { @item.hidden = -1 } assert_nothing_raised { @item.hidden = true } - assert_equal(@item.hidden, true) + assert(@item.hidden) end def test_customBuiltin assert_raise(ArgumentError) { @item.customBuiltin = -1 } assert_nothing_raised { @item.customBuiltin = true } - assert_equal(@item.customBuiltin, true) + assert(@item.customBuiltin) end end diff --git a/test/stylesheet/tc_color.rb b/test/stylesheet/tc_color.rb index 46e94f88..336c093f 100644 --- a/test/stylesheet/tc_color.rb +++ b/test/stylesheet/tc_color.rb @@ -8,32 +8,33 @@ class TestColor < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.auto, nil) - assert_equal(@item.rgb, "FF000000") - assert_equal(@item.tint, nil) + assert_nil(@item.auto) + assert_equal("FF000000", @item.rgb) + assert_nil(@item.tint) end def test_auto assert_raise(ArgumentError) { @item.auto = -1 } assert_nothing_raised { @item.auto = true } - assert_equal(@item.auto, true) + assert(@item.auto) end def test_rgb assert_raise(ArgumentError) { @item.rgb = -1 } assert_nothing_raised { @item.rgb = "FF00FF00" } - assert_equal(@item.rgb, "FF00FF00") + assert_equal("FF00FF00", @item.rgb) end def test_rgb_writer_doesnt_mutate_its_argument my_rgb = 'ff00ff00' @item.rgb = my_rgb + assert_equal 'ff00ff00', my_rgb end def test_tint assert_raise(ArgumentError) { @item.tint = -1 } assert_nothing_raised { @item.tint = -1.0 } - assert_equal(@item.tint, -1.0) + assert_in_delta(@item.tint, -1.0) end end diff --git a/test/stylesheet/tc_dxf.rb b/test/stylesheet/tc_dxf.rb index ecbd7112..bac649dd 100644 --- a/test/stylesheet/tc_dxf.rb +++ b/test/stylesheet/tc_dxf.rb @@ -9,12 +9,12 @@ class TestDxf < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.alignment, nil) - assert_equal(@item.protection, nil) - assert_equal(@item.numFmt, nil) - assert_equal(@item.font, nil) - assert_equal(@item.fill, nil) - assert_equal(@item.border, nil) + assert_nil(@item.alignment) + assert_nil(@item.protection) + assert_nil(@item.numFmt) + assert_nil(@item.font) + assert_nil(@item.fill) + assert_nil(@item.border) end def test_alignment @@ -56,6 +56,7 @@ class TestDxf < Test::Unit::TestCase def test_to_xml @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) end @@ -69,6 +70,7 @@ class TestDxf < Test::Unit::TestCase @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) diff --git a/test/stylesheet/tc_font.rb b/test/stylesheet/tc_font.rb index 601e7a65..3eaec01a 100644 --- a/test/stylesheet/tc_font.rb +++ b/test/stylesheet/tc_font.rb @@ -8,108 +8,109 @@ class TestFont < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.name, nil) - assert_equal(@item.charset, nil) - assert_equal(@item.family, nil) - assert_equal(@item.b, nil) - assert_equal(@item.i, nil) - assert_equal(@item.u, nil) - assert_equal(@item.strike, nil) - assert_equal(@item.outline, nil) - assert_equal(@item.shadow, nil) - assert_equal(@item.condense, nil) - assert_equal(@item.extend, nil) - assert_equal(@item.color, nil) - assert_equal(@item.sz, nil) + assert_nil(@item.name) + assert_nil(@item.charset) + assert_nil(@item.family) + assert_nil(@item.b) + assert_nil(@item.i) + assert_nil(@item.u) + assert_nil(@item.strike) + assert_nil(@item.outline) + assert_nil(@item.shadow) + assert_nil(@item.condense) + assert_nil(@item.extend) + assert_nil(@item.color) + assert_nil(@item.sz) 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") + assert_equal("bob", @item.name) 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) + assert_equal(5, @item.charset) 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) + assert_equal(5, @item.family) 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) + assert(@item.b) 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) + assert(@item.i) 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 } - assert_equal(@item.u, :single) + assert_equal(:single, @item.u) doc = Nokogiri::XML(@item.to_xml_string) + assert(doc.xpath('//u[@val="single"]')) end def test_u_backward_compatibility # backward compatibility for true assert_nothing_raised { @item.u = true } - assert_equal(@item.u, :single) + assert_equal(:single, @item.u) # backward compatibility for false assert_nothing_raised { @item.u = false } - assert_equal(@item.u, :none) + assert_equal(:none, @item.u) 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) + assert(@item.strike) 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) + assert(@item.outline) 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) + assert(@item.shadow) 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) + assert(@item.condense) 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) + assert(@item.extend) end # def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end @@ -123,6 +124,6 @@ class TestFont < Test::Unit::TestCase def test_sz assert_raise(ArgumentError) { @item.sz = -7 } assert_nothing_raised { @item.sz = 5 } - assert_equal(@item.sz, 5) + assert_equal(5, @item.sz) end end diff --git a/test/stylesheet/tc_gradient_fill.rb b/test/stylesheet/tc_gradient_fill.rb index 3707cdad..7f0a4013 100644 --- a/test/stylesheet/tc_gradient_fill.rb +++ b/test/stylesheet/tc_gradient_fill.rb @@ -8,54 +8,55 @@ class TestGradientFill < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.type, :linear) - assert_equal(@item.degree, nil) - assert_equal(@item.left, nil) - assert_equal(@item.right, nil) - assert_equal(@item.top, nil) - assert_equal(@item.bottom, nil) + assert_equal(:linear, @item.type) + assert_nil(@item.degree) + assert_nil(@item.left) + assert_nil(@item.right) + assert_nil(@item.top) + assert_nil(@item.bottom) assert(@item.stop.is_a?(Axlsx::SimpleTypedList)) end def test_type assert_raise(ArgumentError) { @item.type = 7 } assert_nothing_raised { @item.type = :path } - assert_equal(@item.type, :path) + assert_equal(:path, @item.type) end def test_degree assert_raise(ArgumentError) { @item.degree = -7 } assert_nothing_raised { @item.degree = 5.0 } - assert_equal(@item.degree, 5.0) + assert_in_delta(@item.degree, 5.0) end def test_left assert_raise(ArgumentError) { @item.left = -1.1 } assert_nothing_raised { @item.left = 1.0 } - assert_equal(@item.left, 1.0) + assert_in_delta(@item.left, 1.0) end def test_right assert_raise(ArgumentError) { @item.right = -1.1 } assert_nothing_raised { @item.right = 0.5 } - assert_equal(@item.right, 0.5) + assert_in_delta(@item.right, 0.5) end def test_top assert_raise(ArgumentError) { @item.top = -1.1 } assert_nothing_raised { @item.top = 1.0 } - assert_equal(@item.top, 1.0) + assert_in_delta(@item.top, 1.0) end def test_bottom assert_raise(ArgumentError) { @item.bottom = -1.1 } assert_nothing_raised { @item.bottom = 0.0 } - assert_equal(@item.bottom, 0.0) + assert_in_delta(@item.bottom, 0.0) end def test_stop @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "00000000"), 0.5) - assert(@item.stop.size == 1) + + assert_equal(1, @item.stop.size) assert(@item.stop.last.is_a?(Axlsx::GradientStop)) end @@ -64,6 +65,7 @@ class TestGradientFill < Test::Unit::TestCase @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "FFFFFF"), 0.5) @item.type = :path doc = Nokogiri::XML(@item.to_xml_string) + assert(doc.xpath("//color[@rgb='FF000000']")) end end diff --git a/test/stylesheet/tc_gradient_stop.rb b/test/stylesheet/tc_gradient_stop.rb index a4cd4ef8..48b0d69d 100644 --- a/test/stylesheet/tc_gradient_stop.rb +++ b/test/stylesheet/tc_gradient_stop.rb @@ -8,20 +8,21 @@ class TestGradientStop < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.color.rgb, "FFFF0000") - assert_equal(@item.position, 1.0) + assert_equal("FFFF0000", @item.color.rgb) + assert_in_delta(@item.position, 1.0) end def test_position assert_raise(ArgumentError) { @item.position = -1.1 } assert_nothing_raised { @item.position = 0.0 } - assert_equal(@item.position, 0.0) + assert_in_delta(@item.position, 0.0) end def test_color assert_raise(ArgumentError) { @item.color = nil } color = Axlsx::Color.new(:rgb => "FF0000FF") @item.color = color - assert_equal(@item.color.rgb, "FF0000FF") + + assert_equal("FF0000FF", @item.color.rgb) end end diff --git a/test/stylesheet/tc_num_fmt.rb b/test/stylesheet/tc_num_fmt.rb index 63c818b0..f75db1d1 100644 --- a/test/stylesheet/tc_num_fmt.rb +++ b/test/stylesheet/tc_num_fmt.rb @@ -8,19 +8,19 @@ class TestNumFmt < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.numFmtId, 0) - assert_equal(@item.formatCode, "") + assert_equal(0, @item.numFmtId) + assert_equal("", @item.formatCode) end def test_numFmtId assert_raise(ArgumentError) { @item.numFmtId = -1.1 } assert_nothing_raised { @item.numFmtId = 2 } - assert_equal(@item.numFmtId, 2) + assert_equal(2, @item.numFmtId) end def test_fomatCode assert_raise(ArgumentError) { @item.formatCode = -1.1 } assert_nothing_raised { @item.formatCode = "0" } - assert_equal(@item.formatCode, "0") + assert_equal("0", @item.formatCode) end end diff --git a/test/stylesheet/tc_pattern_fill.rb b/test/stylesheet/tc_pattern_fill.rb index 228d7ca2..9e122d19 100644 --- a/test/stylesheet/tc_pattern_fill.rb +++ b/test/stylesheet/tc_pattern_fill.rb @@ -8,32 +8,33 @@ class TestPatternFill < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.patternType, :none) - assert_equal(@item.bgColor, nil) - assert_equal(@item.fgColor, nil) + assert_equal(:none, @item.patternType) + assert_nil(@item.bgColor) + assert_nil(@item.fgColor) end def test_bgColor assert_raise(ArgumentError) { @item.bgColor = -1.1 } assert_nothing_raised { @item.bgColor = Axlsx::Color.new } - assert_equal(@item.bgColor.rgb, "FF000000") + assert_equal("FF000000", @item.bgColor.rgb) end def test_fgColor assert_raise(ArgumentError) { @item.fgColor = -1.1 } assert_nothing_raised { @item.fgColor = Axlsx::Color.new } - assert_equal(@item.fgColor.rgb, "FF000000") + assert_equal("FF000000", @item.fgColor.rgb) end def test_pattern_type assert_raise(ArgumentError) { @item.patternType = -1.1 } assert_nothing_raised { @item.patternType = :lightUp } - assert_equal(@item.patternType, :lightUp) + assert_equal(:lightUp, @item.patternType) end def test_to_xml_string @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"]')) end diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index d6e9115a..415bf968 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -15,16 +15,18 @@ class TestStyles < Test::Unit::TestCase errors.push error puts error.message end - assert(errors.empty?) + + assert_empty(errors) end def test_add_style_border_hash border_count = @styles.borders.size @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_equal("FFFF0000", @styles.borders.last.prs.last.color.rgb) assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" } } - assert_equal @styles.borders.last.prs.size, 4 + assert_equal(4, @styles.borders.last.prs.size) end def test_add_style_border_array @@ -46,34 +48,39 @@ class TestStyles < Test::Unit::TestCase 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 } - assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}") - end + next unless b_opts[:edges] + + 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 def test_add_style_border_edges @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") + + parts.each { |pr| assert_equal("0000FFFF", pr.color.rgb, "Style is applied to #{pr.name} properly") } + assert_equal(2, (parts.map { |pr| pr.name.to_s }.sort && ['bottom', 'top']).size, "specify two edges, and you get two border prs") 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" } } @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' + + assert_equal(:thin, options[:border][:style], 'thin style is stil in option') + assert_equal("FF000000", options[:border][:color], 'color is stil in option') end def test_parse_num_fmt 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') + + assert_nil(@styles.parse_num_fmt_options, 'noop if neither :format_code or :num_fmt exist') max = @styles.numFmts.map(&: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") @@ -88,9 +95,10 @@ class TestStyles < Test::Unit::TestCase def test_parse_border_basic_options 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(@styles.borders.last.diagonalUp == 1, "border options are passed in to the initializer") + assert_equal(1, @styles.borders.last.diagonalUp, "border options are passed in to the initializer") end def test_parse_border_options_edges @@ -101,22 +109,23 @@ class TestStyles < Test::Unit::TestCase right = b.prs.select { |bpr| bpr.name == :right }[0] top = b.prs.select { |bpr| bpr.name == :top }[0] bottom = b.prs.select { |bpr| bpr.name == :bottom }[0] - assert_equal(top, nil, "unspecified top edge should not be created") - assert_equal(bottom, nil, "unspecified bottom edge should not be created") + + assert_nil(top, "unspecified top edge should not be created") + assert_nil(bottom, "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, :thick, "the style is THICK") + assert_equal(:thick, left.style, "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("FFDADADA", right.color.rgb, "edge color rgb is correct") end def test_parse_border_options_noop - assert_equal(@styles.parse_border_options({}), nil, "noop if the border key is not in options") + assert_nil(@styles.parse_border_options({}), "noop if the border key is not in options") end def test_parse_border_options_integer_xf - assert_equal(@styles.parse_border_options(:border => 1), 1) + assert_equal(1, @styles.parse_border_options(:border => 1)) assert_raise(ArgumentError, "unknown border index") { @styles.parse_border_options(:border => 100) } end @@ -124,11 +133,12 @@ class TestStyles < Test::Unit::TestCase 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") end def test_parse_alignment_options - assert_equal(@styles.parse_alignment_options, nil, "noop if :alignment is not set") + assert_nil(@styles.parse_alignment_options, "noop if :alignment is not set") assert(@styles.parse_alignment_options(:alignment => {}).is_a?(Axlsx::CellAlignment)) end @@ -137,10 +147,12 @@ class TestStyles < Test::Unit::TestCase @styles.add_style :b => 1, :sz => 99 created = @styles.fonts.last 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 } instance_vals = Axlsx.instance_values_for(created) + copied.each do |key, value| assert_equal(instance_vals[key], value) end @@ -160,13 +172,15 @@ class TestStyles < Test::Unit::TestCase :family => 1, :font_name => "woot font" } - assert_equal(@styles.parse_font_options, nil, "noop if no font keys are set") + + assert_nil(@styles.parse_font_options, "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") f = @styles.parse_font_options(options.merge(:type => :dxf)) color = options.delete(:fg_color) options[:name] = options.delete(:font_name) + options.each do |key, value| assert_equal(f.send(key), value, "assert that #{key} was parsed") end @@ -174,15 +188,16 @@ class TestStyles < Test::Unit::TestCase end def test_parse_fill_options - assert_equal(@styles.parse_fill_options, nil, "noop if no fill keys are set") + assert_nil(@styles.parse_fill_options, "noop if no fill keys are set") assert(@styles.parse_fill_options(:bg_color => "DE").is_a?(Integer), "return index of fill if not :dxf type") assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type") f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf) - assert(f.fill_type.bgColor.rgb == "FFDEDEDE") + + assert_equal("FFDEDEDE", f.fill_type.bgColor.rgb) end def test_parse_protection_options - assert_equal(@styles.parse_protection_options, nil, "noop if no protection keys are set") + assert_nil(@styles.parse_protection_options, "noop if no protection keys are set") assert_equal(@styles.parse_protection_options(:hidden => 1).class, Axlsx::CellProtection, "creates a new cell protection object") end @@ -192,39 +207,42 @@ class TestStyles < Test::Unit::TestCase 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) xf = @styles.cellXfs.last + 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("FF000000", @styles.fills.last.fill_type.fgColor.rgb, "fill created with color") 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") + assert_equal(13, @styles.fonts.last.sz, "font sz applied") + assert_equal("FFFFFFFF", @styles.fonts.last.color.rgb, "font color applied") assert_equal(xf.borderId, Axlsx::STYLE_THIN_BORDER, "border id is set") assert_equal(xf.numFmtId, Axlsx::NUM_FMT_PERCENT, "number format id is set") assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created") - assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied") - assert_equal(xf.protection.hidden, true, "hidden protection set") - assert_equal(xf.protection.locked, true, "cell locking set") + assert_equal(:left, xf.alignment.horizontal, "horizontal alignment applied") + assert(xf.protection.hidden, "hidden protection set") + assert(xf.protection.locked, "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.applyAlignment, true, "alignment applied") + assert(xf.applyProtection, "protection applied") + assert(xf.applyBorder, "border applied") + assert(xf.applyNumberFormat, "number format applied") + assert(xf.applyAlignment, "alignment applied") end def test_basic_add_style_dxf border_count = @styles.borders.size @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_equal("FFFF0000", @styles.dxfs.last.border.prs.last.color.rgb) assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" }, :type => :dxf } - assert_equal @styles.borders.last.prs.size, 4 + assert_equal(4, @styles.borders.last.prs.size) end def test_add_style_dxf @@ -233,30 +251,34 @@ class TestStyles < Test::Unit::TestCase 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) assert_equal(0, style, "returns the zero-based dxfId") dxf = @styles.dxfs.last - assert_equal(@styles.dxfs.last.fill.fill_type.bgColor.rgb, "FF000000", "fill created with color") + + assert_equal("FF000000", @styles.dxfs.last.fill.fill_type.bgColor.rgb, "fill created with color") assert_equal(font_count, @styles.fonts.size, "font not created under styles") assert_equal(fill_count, @styles.fills.size, "fill not created under styles") assert(dxf.border.is_a?(Axlsx::Border), "border is set") - assert_equal(nil, dxf.numFmt, "number format is not set") + assert_nil(dxf.numFmt, "number format is not set") assert(dxf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created") - assert_equal(dxf.alignment.horizontal, :left, "horizontal alignment applied") - assert_equal(dxf.protection.hidden, true, "hidden protection set") - assert_equal(dxf.protection.locked, true, "cell locking set") + assert_equal(:left, dxf.alignment.horizontal, "horizontal alignment applied") + assert(dxf.protection.hidden, "hidden protection set") + assert(dxf.protection.locked, "cell locking set") assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 3 } end 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 + 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 + assert_equal(1, style, "returns the second dxfId") end @@ -283,7 +305,8 @@ class TestStyles < Test::Unit::TestCase errors.push error puts error.message end - assert(errors.empty?) + + assert_empty(errors) end def test_border_top_without_border_regression @@ -302,6 +325,7 @@ class TestStyles < Test::Unit::TestCase current_border = @styles.borders.last border_pr = current_border.prs.detect { |x| x.name == edge } + assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}") end end diff --git a/test/stylesheet/tc_table_style.rb b/test/stylesheet/tc_table_style.rb index a003c37a..6c15ebae 100644 --- a/test/stylesheet/tc_table_style.rb +++ b/test/stylesheet/tc_table_style.rb @@ -8,35 +8,37 @@ class TestTableStyle < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.name, "fisher") - assert_equal(@item.pivot, nil) - assert_equal(@item.table, nil) + assert_equal("fisher", @item.name) + assert_nil(@item.pivot) + assert_nil(@item.table) ts = Axlsx::TableStyle.new 'price', :pivot => true, :table => true - assert_equal(ts.name, 'price') - assert_equal(ts.pivot, true) - assert_equal(ts.table, true) + + assert_equal('price', ts.name) + assert(ts.pivot) + assert(ts.table) end def test_name assert_raise(ArgumentError) { @item.name = -1.1 } assert_nothing_raised { @item.name = "lovely table style" } - assert_equal(@item.name, "lovely table style") + assert_equal("lovely table style", @item.name) end def test_pivot assert_raise(ArgumentError) { @item.pivot = -1.1 } assert_nothing_raised { @item.pivot = true } - assert_equal(@item.pivot, true) + assert(@item.pivot) end def test_table assert_raise(ArgumentError) { @item.table = -1.1 } assert_nothing_raised { @item.table = true } - assert_equal(@item.table, true) + assert(@item.table) end def test_to_xml_string doc = Nokogiri::XML(@item.to_xml_string) + assert(doc.xpath("//tableStyle[@name='#{@item.name}']")) end end diff --git a/test/stylesheet/tc_table_style_element.rb b/test/stylesheet/tc_table_style_element.rb index 2b52a23d..6dcbedd9 100644 --- a/test/stylesheet/tc_table_style_element.rb +++ b/test/stylesheet/tc_table_style_element.rb @@ -8,36 +8,38 @@ class TestTableStyleElement < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.type, nil) - assert_equal(@item.size, nil) - assert_equal(@item.dxfId, nil) + assert_nil(@item.type) + assert_nil(@item.size) + assert_nil(@item.dxfId) options = { :type => :headerRow, :size => 10, :dxfId => 1 } tse = Axlsx::TableStyleElement.new options + options.each { |key, value| assert_equal(tse.send(key.to_sym), value) } end def test_type assert_raise(ArgumentError) { @item.type = -1.1 } assert_nothing_raised { @item.type = :blankRow } - assert_equal(@item.type, :blankRow) + assert_equal(:blankRow, @item.type) end def test_size assert_raise(ArgumentError) { @item.size = -1.1 } assert_nothing_raised { @item.size = 2 } - assert_equal(@item.size, 2) + assert_equal(2, @item.size) end def test_dxfId assert_raise(ArgumentError) { @item.dxfId = -1.1 } assert_nothing_raised { @item.dxfId = 7 } - assert_equal(@item.dxfId, 7) + assert_equal(7, @item.dxfId) end def test_to_xml_string doc = Nokogiri::XML(@item.to_xml_string) @item.type = :headerRow + assert(doc.xpath("//tableStyleElement[@type='#{@item.type}']")) end end diff --git a/test/stylesheet/tc_table_styles.rb b/test/stylesheet/tc_table_styles.rb index 5ce315d5..4fdee796 100644 --- a/test/stylesheet/tc_table_styles.rb +++ b/test/stylesheet/tc_table_styles.rb @@ -8,19 +8,19 @@ class TestTableStyles < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.defaultTableStyle, "TableStyleMedium9") - assert_equal(@item.defaultPivotStyle, "PivotStyleLight16") + assert_equal("TableStyleMedium9", @item.defaultTableStyle) + assert_equal("PivotStyleLight16", @item.defaultPivotStyle) end def test_defaultTableStyle assert_raise(ArgumentError) { @item.defaultTableStyle = -1.1 } assert_nothing_raised { @item.defaultTableStyle = "anyones guess" } - assert_equal(@item.defaultTableStyle, "anyones guess") + assert_equal("anyones guess", @item.defaultTableStyle) end def test_defaultPivotStyle assert_raise(ArgumentError) { @item.defaultPivotStyle = -1.1 } assert_nothing_raised { @item.defaultPivotStyle = "anyones guess" } - assert_equal(@item.defaultPivotStyle, "anyones guess") + assert_equal("anyones guess", @item.defaultPivotStyle) end end diff --git a/test/stylesheet/tc_xf.rb b/test/stylesheet/tc_xf.rb index 9a972aaf..71ce71a4 100644 --- a/test/stylesheet/tc_xf.rb +++ b/test/stylesheet/tc_xf.rb @@ -8,21 +8,21 @@ class TestXf < Test::Unit::TestCase def teardown; end def test_initialiation - assert_equal(@item.alignment, nil) - assert_equal(@item.protection, nil) - assert_equal(@item.numFmtId, nil) - assert_equal(@item.fontId, nil) - assert_equal(@item.fillId, nil) - assert_equal(@item.borderId, nil) - assert_equal(@item.xfId, nil) - assert_equal(@item.quotePrefix, nil) - assert_equal(@item.pivotButton, nil) - assert_equal(@item.applyNumberFormat, nil) - assert_equal(@item.applyFont, nil) - assert_equal(@item.applyFill, nil) - assert_equal(@item.applyBorder, nil) - assert_equal(@item.applyAlignment, nil) - assert_equal(@item.applyProtection, nil) + assert_nil(@item.alignment) + assert_nil(@item.protection) + assert_nil(@item.numFmtId) + assert_nil(@item.fontId) + assert_nil(@item.fillId) + assert_nil(@item.borderId) + assert_nil(@item.xfId) + assert_nil(@item.quotePrefix) + assert_nil(@item.pivotButton) + assert_nil(@item.applyNumberFormat) + assert_nil(@item.applyFont) + assert_nil(@item.applyFill) + assert_nil(@item.applyBorder) + assert_nil(@item.applyAlignment) + assert_nil(@item.applyProtection) end def test_alignment @@ -40,78 +40,78 @@ class TestXf < Test::Unit::TestCase def test_numFmtId assert_raise(ArgumentError) { @item.numFmtId = -1.1 } assert_nothing_raised { @item.numFmtId = 0 } - assert_equal(@item.numFmtId, 0) + assert_equal(0, @item.numFmtId) end def test_fillId assert_raise(ArgumentError) { @item.fillId = -1.1 } assert_nothing_raised { @item.fillId = 0 } - assert_equal(@item.fillId, 0) + assert_equal(0, @item.fillId) end def test_fontId assert_raise(ArgumentError) { @item.fontId = -1.1 } assert_nothing_raised { @item.fontId = 0 } - assert_equal(@item.fontId, 0) + assert_equal(0, @item.fontId) end def test_borderId assert_raise(ArgumentError) { @item.borderId = -1.1 } assert_nothing_raised { @item.borderId = 0 } - assert_equal(@item.borderId, 0) + assert_equal(0, @item.borderId) end def test_xfId assert_raise(ArgumentError) { @item.xfId = -1.1 } assert_nothing_raised { @item.xfId = 0 } - assert_equal(@item.xfId, 0) + assert_equal(0, @item.xfId) end def test_quotePrefix assert_raise(ArgumentError) { @item.quotePrefix = -1.1 } assert_nothing_raised { @item.quotePrefix = false } - assert_equal(@item.quotePrefix, false) + refute(@item.quotePrefix) end def test_pivotButton assert_raise(ArgumentError) { @item.pivotButton = -1.1 } assert_nothing_raised { @item.pivotButton = false } - assert_equal(@item.pivotButton, false) + refute(@item.pivotButton) end def test_applyNumberFormat assert_raise(ArgumentError) { @item.applyNumberFormat = -1.1 } assert_nothing_raised { @item.applyNumberFormat = false } - assert_equal(@item.applyNumberFormat, false) + refute(@item.applyNumberFormat) end def test_applyFont assert_raise(ArgumentError) { @item.applyFont = -1.1 } assert_nothing_raised { @item.applyFont = false } - assert_equal(@item.applyFont, false) + refute(@item.applyFont) end def test_applyFill assert_raise(ArgumentError) { @item.applyFill = -1.1 } assert_nothing_raised { @item.applyFill = false } - assert_equal(@item.applyFill, false) + refute(@item.applyFill) end def test_applyBorder assert_raise(ArgumentError) { @item.applyBorder = -1.1 } assert_nothing_raised { @item.applyBorder = false } - assert_equal(@item.applyBorder, false) + refute(@item.applyBorder) end def test_applyAlignment assert_raise(ArgumentError) { @item.applyAlignment = -1.1 } assert_nothing_raised { @item.applyAlignment = false } - assert_equal(@item.applyAlignment, false) + refute(@item.applyAlignment) end def test_applyProtection assert_raise(ArgumentError) { @item.applyProtection = -1.1 } assert_nothing_raised { @item.applyProtection = false } - assert_equal(@item.applyProtection, false) + refute(@item.applyProtection) end end |
