summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-08-02 22:38:48 +0900
committerRandy Morgan <[email protected]>2012-08-02 22:38:48 +0900
commit93ba4b05c2e44724cfdf4c8a1352b098ea9c1482 (patch)
tree5423ea5da40205bcbd8ce78c3912cad6f199232d /test
parent1431d1bd0851ed29e188ad17c6a9b93c316fe983 (diff)
downloadcaxlsx-93ba4b05c2e44724cfdf4c8a1352b098ea9c1482.tar.gz
caxlsx-93ba4b05c2e44724cfdf4c8a1352b098ea9c1482.zip
bring coverage up to 100% for d_lbls and defined names
release prep!
Diffstat (limited to 'test')
-rw-r--r--test/tc_package.rb17
-rw-r--r--test/workbook/tc_defined_name.rb41
-rw-r--r--test/workbook/tc_workbook.rb6
3 files changed, 61 insertions, 3 deletions
diff --git a/test/tc_package.rb b/test/tc_package.rb
index 3b5db288..df56b044 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -7,6 +7,7 @@ class TestPackage < Test::Unit::TestCase
ws = @package.workbook.add_worksheet
ws.add_row ['Can', 'we', 'build it?']
ws.add_row ['Yes!', 'We', 'can!']
+ ws.workbook.add_defined_name("#{ws.name}!A1:C2", :name => '_xlnm.Print_Titles', :hidden => true)
ws.protect_range('A1:C1')
ws.protect_range(ws.rows.last.cells)
ws.add_comment :author => 'alice', :text => 'Hi Bob', :ref => 'A12'
@@ -28,11 +29,25 @@ class TestPackage < Test::Unit::TestCase
ws.add_chart(Axlsx::Pie3DChart, :title => "これは?", :start_at => [0,3]) do |chart|
chart.add_series :data=>[1,2,3], :labels=>["a", "b", "c"]
+ chart.d_lbls.show_val = true
+ chart.d_lbls.d_lbl_pos = :outEnd
+ chart.d_lbls.show_percent = true
end
ws.add_chart(Axlsx::Line3DChart, :title => "axis labels") do |chart|
chart.valAxis.title = 'bob'
+ chart.d_lbls.show_val = true
end
+
+ ws.add_chart(Axlsx::Bar3DChart, :title => 'bar chart') do |chart|
+ chart.add_series :data => [1,4,5], :labels => %w(A B C)
+ chart.d_lbls.show_percent = true
+ end
+
+ ws.add_chart(Axlsx::ScatterChart, :title => 'scat man') do |chart|
+ chart.add_series :xData => [1,2,3,4], :yData => [4,3,2,1]
+ chart.d_lbls.show_val = true
+ end
@fname = 'axlsx_test_serialization.xlsx'
img = File.expand_path('../../examples/image1.jpeg', __FILE__)
@@ -122,7 +137,7 @@ class TestPackage < Test::Unit::TestCase
#no mystery parts
- assert_equal(p.size, 19)
+ assert_equal(p.size, 21)
end
diff --git a/test/workbook/tc_defined_name.rb b/test/workbook/tc_defined_name.rb
new file mode 100644
index 00000000..51f5a484
--- /dev/null
+++ b/test/workbook/tc_defined_name.rb
@@ -0,0 +1,41 @@
+require 'tc_helper'
+
+class TestDefinedNames < Test::Unit::TestCase
+ def setup
+ @dn = Axlsx::DefinedName.new('Sheet1!A1:A1')
+ end
+
+ def test_initialize
+ assert_equal('Sheet1!A1:A1', @dn.formula)
+ end
+
+ def test_string_attributes
+ Axlsx::DefinedName::STRING_ATTRIBUTES.each do |attr|
+ assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
+ assert_nothing_raised { @dn.send("#{attr}=", '_xlnm.Sheet_Title') }
+ end
+ end
+
+ def test_boolean_attributes
+ Axlsx::DefinedName::BOOLEAN_ATTRIBUTES.each do |attr|
+ assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @dn.send("#{attr}=", 'foo') }
+ assert_nothing_raised { @dn.send("#{attr}=", 1) }
+ end
+
+ end
+
+ def test_local_sheet_id
+ assert_raise(ArgumentError, 'local_sheet_id must be an unsigned int') { @dn.local_sheet_id = -1 }
+ assert_nothing_raised { @dn.local_sheet_id = 1 }
+ end
+
+ def test_to_xml_string
+ assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string }
+ @dn.name = '_xlnm.Print_Titles'
+ @dn.hidden = true
+ doc = Nokogiri::XML(@dn.to_xml_string)
+ assert(doc.xpath("//definedName[@name='_xlnm.Print_Titles']"))
+ assert(doc.xpath("//definedName[@hidden='true']"))
+ assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
+ end
+end
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index f6f38778..537f9074 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -24,7 +24,10 @@ class TestWorkbook < Test::Unit::TestCase
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
end
-
+ def test_add_defined_name
+ @wb.add_defined_name 'Sheet1!1:1', :name => '_xlnm.Print_Titles', :hidden => true
+ assert_equal(1, @wb.defined_names.size)
+ end
def test_shared_strings
assert_equal(@wb.use_shared_strings, nil)
@@ -72,7 +75,6 @@ class TestWorkbook < Test::Unit::TestCase
assert(@wb.worksheets.size == 1)
end
-
def test_to_xml_string_defined_names
@wb.add_worksheet do |sheet|
sheet.add_row [1, "two"]