summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_bar_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_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_chart.rb')
-rw-r--r--test/drawing/tc_bar_chart.rb25
1 files changed, 13 insertions, 12 deletions
diff --git a/test/drawing/tc_bar_chart.rb b/test/drawing/tc_bar_chart.rb
index d064e5be..c8bdc8d0 100644
--- a/test/drawing/tc_bar_chart.rb
+++ b/test/drawing/tc_bar_chart.rb
@@ -32,18 +32,12 @@ class TestBarChart < Test::Unit::TestCase
assert(@chart.grouping == :standard)
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_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 gap width") { @chart.gap_width = 200 }
+ assert_equal(@chart.gap_width, 200, 'gap width is incorrect')
+ end
def test_overlap
assert_raise(ArgumentError, "require valid overlap") { @chart.overlap = -101 }
@@ -76,6 +70,13 @@ class TestBarChart < Test::Unit::TestCase
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_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:barChart/c:gapWidth").first.attribute('val').value, gap_width_value.to_s)
+ end
+
def test_to_xml_string_has_overlap
overlap_value = rand(-100..100)
@chart.overlap = overlap_value