summaryrefslogtreecommitdiffhomepage
path: root/test/workbook
diff options
context:
space:
mode:
Diffstat (limited to 'test/workbook')
-rw-r--r--test/workbook/tc_defined_name.rb41
-rw-r--r--test/workbook/tc_workbook.rb6
2 files changed, 45 insertions, 2 deletions
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"]