summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_bar_3D_chart.rb
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2021-07-25 01:37:29 +0200
committerGitHub <[email protected]>2021-07-25 01:37:29 +0200
commitc4d7279de2bd20bc98c15ea64e9074ded19124ca (patch)
tree05653d98a5aead376ab378dc9fbc1274f56c9b75 /test/drawing/tc_bar_3D_chart.rb
parent158942c16b249a269e77633dd261b87787d191af (diff)
downloadcaxlsx-c4d7279de2bd20bc98c15ea64e9074ded19124ca.tar.gz
caxlsx-c4d7279de2bd20bc98c15ea64e9074ded19124ca.zip
Fix gap width validator for bar charts (#108)
`gap_width` and `gap_depth` now allow only integers in the range of 0–500. The previous behaviour (requiring a percentage value) was according to the current version of the OOXML spec, but Excel seems to rely on an older version, where the gap amount was required to be a simple integer. Also, `gapDepth` is only allowed in 3D bar charts, so it is now no longer available for 2D bar charts.
Diffstat (limited to 'test/drawing/tc_bar_3D_chart.rb')
-rw-r--r--test/drawing/tc_bar_3D_chart.rb37
1 files changed, 26 insertions, 11 deletions
diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb
index 0cae7af6..b7a1eca4 100644
--- a/test/drawing/tc_bar_3D_chart.rb
+++ b/test/drawing/tc_bar_3D_chart.rb
@@ -32,18 +32,19 @@ class TestBar3DChart < Test::Unit::TestCase
assert(@chart.grouping == :standard)
end
+ def test_gap_width
+ assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = -1 }
+ assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 501 }
+ assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = 200 }
+ assert_equal(@chart.gap_width, 200, 'gap width is incorrect')
+ end
- def test_gapWidth
- assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 200 }
- assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = "200%" }
- assert(@chart.gap_width == "200%")
- end
-
- def test_gapDepth
- assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 200 }
- assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = "200%" }
- assert(@chart.gap_depth == "200%")
- end
+ def test_gap_depth
+ assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = -1 }
+ assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 501 }
+ assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = 200 }
+ assert_equal(@chart.gap_depth, 200, 'gap depth is incorrect')
+ end
def test_shape
assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
@@ -68,4 +69,18 @@ class TestBar3DChart < Test::Unit::TestCase
val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
end
+
+ def test_to_xml_string_has_gap_depth
+ gap_depth_value = rand(0..500)
+ @chart.gap_depth = gap_depth_value
+ doc = Nokogiri::XML(@chart.to_xml_string)
+ assert_equal(doc.xpath("//c:bar3DChart/c:gapDepth").first.attribute('val').value, gap_depth_value.to_s)
+ end
+
+ def test_to_xml_string_has_gap_width
+ gap_width_value = rand(0..500)
+ @chart.gap_width = gap_width_value
+ doc = Nokogiri::XML(@chart.to_xml_string)
+ assert_equal(doc.xpath("//c:bar3DChart/c:gapWidth").first.attribute('val').value, gap_width_value.to_s)
+ end
end