summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-02-12 12:55:25 +0900
committerRandy Morgan <[email protected]>2012-02-12 12:55:25 +0900
commit376988c854889d7b9708601bce11575a11491bee (patch)
tree963e196ae76022e84dbbe1a2cf293c840182be08 /test
parent6272d7bc63ee05b6793d034461af3ee811ffe72a (diff)
downloadcaxlsx-376988c854889d7b9708601bce11575a11491bee.tar.gz
caxlsx-376988c854889d7b9708601bce11575a11491bee.zip
Adding in support for optionally using the shared strings table. This will allow us to inter-op properly with Numbers
Diffstat (limited to 'test')
-rw-r--r--test/content_type/tc_content_type.rb2
-rw-r--r--test/content_type/tc_default.rb2
-rw-r--r--test/content_type/tc_override.rb1
-rw-r--r--test/tc_package.rb31
-rw-r--r--test/workbook/tc_shared_strings_table.rb39
-rw-r--r--test/workbook/tc_workbook.rb8
-rw-r--r--test/workbook/worksheet/tc_cell.rb13
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb8
8 files changed, 103 insertions, 1 deletions
diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb
index 62ea05e8..9fcbcd70 100644
--- a/test/content_type/tc_content_type.rb
+++ b/test/content_type/tc_content_type.rb
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
require 'test/unit'
require 'axlsx.rb'
diff --git a/test/content_type/tc_default.rb b/test/content_type/tc_default.rb
index ce024de8..90c0934e 100644
--- a/test/content_type/tc_default.rb
+++ b/test/content_type/tc_default.rb
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
require 'test/unit'
require 'axlsx.rb'
diff --git a/test/content_type/tc_override.rb b/test/content_type/tc_override.rb
index 3f478a3f..911ec649 100644
--- a/test/content_type/tc_override.rb
+++ b/test/content_type/tc_override.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require 'test/unit'
require 'axlsx.rb'
diff --git a/test/tc_package.rb b/test/tc_package.rb
index e831f52a..90c3cb84 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -21,6 +21,13 @@ class TestPackage < Test::Unit::TestCase
assert_raise(NoMethodError) {@package.app = nil }
end
+ def test_use_shared_strings
+ assert_equal(@package.use_shared_strings, nil)
+ assert_raise(ArgumentError) {@package.use_shared_strings 9}
+ assert_nothing_raised {@package.use_shared_strings = true}
+ assert_equal(@package.use_shared_strings, @package.workbook.use_shared_strings)
+ end
+
def test_default_objects_are_created
assert(@package.instance_values["app"].is_a?(Axlsx::App), 'App object not created')
assert(@package.instance_values["core"].is_a?(Axlsx::Core), 'Core object not created')
@@ -69,10 +76,34 @@ class TestPackage < Test::Unit::TestCase
#no mystery parts
assert_equal(p.size, 12)
+
+ end
+ def test_shared_strings_requires_part
+ @package.use_shared_strings = true
+ p = @package.send(:parts)
+ assert_equal(p.select{ |part| part[:entry] =~/xl\/sharedStrings.xml/}.size, 1, "shared strings table missing")
end
def test_workbook_is_a_workbook
assert @package.workbook.is_a? Axlsx::Workbook
end
+
+ def test_base_content_types
+ ct = @package.send(:base_content_types)
+ assert(ct.select { |ct| ct.ContentType == Axlsx::RELS_CT }.size == 1, "rels content type missing")
+ assert(ct.select { |ct| ct.ContentType == Axlsx::XML_CT }.size == 1, "xml content type missing")
+ assert(ct.select { |ct| ct.ContentType == Axlsx::APP_CT }.size == 1, "app content type missing")
+ assert(ct.select { |ct| ct.ContentType == Axlsx::CORE_CT }.size == 1, "core content type missing")
+ assert(ct.select { |ct| ct.ContentType == Axlsx::STYLES_CT }.size == 1, "styles content type missing")
+ assert(ct.select { |ct| ct.ContentType == Axlsx::WORKBOOK_CT }.size == 1, "workbook content type missing")
+ assert(ct.size == 6)
+ end
+
+ def test_content_type_added_with_shared_strings
+ @package.use_shared_strings = true
+ ct = @package.send(:content_types)
+ assert(ct.select { |ct| ct.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1)
+ end
+
end
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
new file mode 100644
index 00000000..b0e9de05
--- /dev/null
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -0,0 +1,39 @@
+require 'test/unit'
+require 'axlsx.rb'
+
+class TestSharedStringsTable < Test::Unit::TestCase
+
+ def setup
+ @p = Axlsx::Package.new :use_shared_strings=>true
+ ws = @p.workbook.add_worksheet
+ ws.add_row ['a', 1, 'b']
+ ws.add_row ['b', 1, 'c']
+ ws.add_row ['c', 1, 'd']
+ end
+
+ def test_workbook_has_shared_strings
+ assert(@p.workbook.shared_strings.is_a?(Axlsx::SharedStringsTable), "shared string table was not created")
+ end
+
+ def test_count
+ sst = @p.workbook.shared_strings
+ assert_equal(sst.count, 6)
+ end
+
+ def test_unique_count
+ sst = @p.workbook.shared_strings
+ assert_equal(sst.unique_count, 4)
+ end
+
+ def test_valid_document
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
+ doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml)
+ errors = []
+ schema.validate(doc).each do |error|
+ puts error.message
+ errors << error
+ end
+ assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s)
+ end
+
+end
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index 7f5139cb..e068a6d0 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -18,6 +18,12 @@ class TestWorkbook < Test::Unit::TestCase
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
end
+ def test_shared_strings
+ assert_equal(@wb.use_shared_strings, nil)
+ assert_raise(ArgumentError) {@wb.use_shared_strings = 'bpb'}
+ assert_nothing_raised {@wb.use_shared_strings = :true}
+ end
+
def test_add_worksheet
assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
ws = @wb.add_worksheet(:name=>"bob")
@@ -30,6 +36,8 @@ class TestWorkbook < Test::Unit::TestCase
assert(@wb.relationships.size == 1)
@wb.add_worksheet
assert(@wb.relationships.size == 2)
+ @wb.use_shared_strings = true
+ assert(@wb.relationships.size == 3)
end
def test_to_xml
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 2859ffec..ed781e0f 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -18,6 +18,7 @@ class TestCell < Test::Unit::TestCase
assert_equal(@c.value, 1.0, "type option is applied and value is casted")
end
+
def test_style_date_data
c = Axlsx::Cell.new(@c.row, Time.now)
assert_equal(Axlsx::STYLE_DATE, c.style)
@@ -191,4 +192,16 @@ class TestCell < Test::Unit::TestCase
assert_equal(@c.row.worksheet.merged_cells.last, "A1:C1")
end
+ def test_equality
+ c2 = @row.add_cell 1, :type=>:float, :style=>1
+ assert(c2.shareable(@c))
+ c3 = @row.add_cell 2, :type=>:float, :style=>1
+ c4 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
+ assert_equal(c4.shareable(c2) ,false)
+ c5 = @row.add_cell 1, :type=>:float, :style=>1, :color => "#FFFFFFFF"
+ assert(c5.shareable(c4))
+
+ end
+
+
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 24e26155..b7f93d97 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -28,7 +28,13 @@ class TestWorksheet < Test::Unit::TestCase
def test_index
assert_equal(@ws.index, @ws.workbook.worksheets.index(@ws))
end
-
+
+ def test_dimension
+ @ws.add_row [1, 2, 3]
+ @ws.add_row [4, 5, 6]
+ assert_equal @ws.dimension, "A1:C2"
+ end
+
def test_referencing
@ws.add_row [1, 2, 3]
@ws.add_row [4, 5, 6]