summaryrefslogtreecommitdiffhomepage
path: root/test/workbook
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
committerRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
commit22a341841f191a5aa00e87b1f166b4f25cc67f0a (patch)
tree505f46708d5cac7d33d0dd6679c125e2eb819075 /test/workbook
parentbb2117ba17297e02a0fc6d5ad5a22462e72a9a79 (diff)
downloadcaxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.tar.gz
caxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.zip
part way through changing all serialization to use string concatenation prior to dropping Nokogiri dep in production.
Diffstat (limited to 'test/workbook')
-rw-r--r--test/workbook/tc_workbook.rb14
-rw-r--r--test/workbook/worksheet/table/tc_table.rb4
-rw-r--r--test/workbook/worksheet/tc_cell.rb7
-rw-r--r--test/workbook/worksheet/tc_page_margins.rb4
-rw-r--r--test/workbook/worksheet/tc_row.rb12
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb49
6 files changed, 22 insertions, 68 deletions
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index af2a7889..e6bb48a0 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -50,7 +50,7 @@ class TestWorkbook < Test::Unit::TestCase
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@wb.to_xml)
+ doc = Nokogiri::XML(@wb.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
@@ -68,9 +68,19 @@ class TestWorkbook < Test::Unit::TestCase
def test_to_xml_adds_worksheet_when_worksheets_is_empty
assert(@wb.worksheets.empty?)
- @wb.to_xml
+ @wb.to_xml_string
assert(@wb.worksheets.size == 1)
end
+ def test_to_xml_string_defined_names
+ @wb.add_worksheet do |sheet|
+ sheet.add_row [1, "two"]
+ sheet.auto_filter = "A1:B1"
+ end
+ doc = Nokogiri::XML(@wb.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].abs_auto_filter)
+ end
+
+
end
diff --git a/test/workbook/worksheet/table/tc_table.rb b/test/workbook/worksheet/table/tc_table.rb
index fc29bf66..d4acf39a 100644
--- a/test/workbook/worksheet/table/tc_table.rb
+++ b/test/workbook/worksheet/table/tc_table.rb
@@ -56,10 +56,10 @@ class TestTable < Test::Unit::TestCase
assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
end
- def test_to_xml
+ def test_to_xml_string
table = @ws.add_table("A1:D5")
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(table.to_xml)
+ doc = Nokogiri::XML(table.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 499f9209..4db0c7be 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -225,17 +225,14 @@ class TestCell < Test::Unit::TestCase
end
def test_to_xml_string
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
- @c.to_xml(xml)
- end
- c_xml = Nokogiri::XML(builder.to_xml(:save_with => 0))
+ c_xml = Nokogiri::XML(@c.to_xml_string(1,1))
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
end
def test_to_xml
# TODO This could use some much more stringent testing related to the xml content generated!
row = @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"]
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@ws.to_xml)
+ doc = Nokogiri::XML(@ws.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
diff --git a/test/workbook/worksheet/tc_page_margins.rb b/test/workbook/worksheet/tc_page_margins.rb
index 4c5e43fa..386f47da 100644
--- a/test/workbook/worksheet/tc_page_margins.rb
+++ b/test/workbook/worksheet/tc_page_margins.rb
@@ -55,9 +55,7 @@ class TestPageMargins < Test::Unit::TestCase
@pm.bottom = 1.4
@pm.header = 0.8
@pm.footer = 0.9
- xml = Nokogiri::XML::Builder.new
- @pm.to_xml(xml)
- doc = Nokogiri::XML.parse(xml.to_xml)
+ doc = Nokogiri::XML.parse(@pm.to_xml_string)
assert_equal(1, doc.xpath(".//pageMargins[@left=1.1][@right=1.2][@top=1.3][@bottom=1.4][@header=0.8][@footer=0.9]").size)
end
diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb
index 47b0f054..d1507aa1 100644
--- a/test/workbook/worksheet/tc_row.rb
+++ b/test/workbook/worksheet/tc_row.rb
@@ -53,9 +53,7 @@ class TestRow < Test::Unit::TestCase
end
def test_to_xml_without_custom_height
- xml = Nokogiri::XML::Builder.new
- @row.to_xml(xml)
- doc = Nokogiri::XML.parse(xml.to_xml)
+ doc = Nokogiri::XML.parse(@row.to_xml_string(0))
assert_equal(0, doc.xpath(".//row[@ht]").size)
assert_equal(0, doc.xpath(".//row[@customHeight]").size)
end
@@ -72,12 +70,4 @@ class TestRow < Test::Unit::TestCase
assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size, 1)
end
- def test_to_xml_with_custom_height
- @row.height = 20
- xml = Nokogiri::XML::Builder.new
- @row.to_xml(xml)
- doc = Nokogiri::XML.parse(xml.to_xml)
- assert_equal(1, doc.xpath(".//row[@ht=20][@customHeight=1]").size)
- end
-
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 3a3232fe..499df864 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -202,8 +202,6 @@ class TestWorksheet < Test::Unit::TestCase
@ws.auto_filter = "A1:B1"
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size, 1)
- doc2 = Nokogiri::XML(@wb.to_xml)
- assert_equal(doc2.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @ws.abs_auto_filter)
end
def test_to_xml_string_merge_cells
@@ -240,13 +238,12 @@ class TestWorksheet < Test::Unit::TestCase
def test_abs_auto_filter
@ws.add_row [1, "two", 3]
@ws.auto_filter = "A1:C1"
- doc = Nokogiri::XML(@wb.to_xml)
- assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, "'Sheet1'!$A$1:$C$1")
+ assert_equal(@ws.abs_auto_filter, "'Sheet1'!$A$1:$C$1")
end
- def test_to_xml
+ def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@ws.to_xml)
+ doc = Nokogiri::XML(@ws.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
@@ -258,7 +255,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_valid_with_page_margins
@ws.page_margins.set :left => 9
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
- doc = Nokogiri::XML(@ws.to_xml)
+ doc = Nokogiri::XML(@ws.to_xml_string)
errors = []
schema.validate(doc).each do |error|
errors.push error
@@ -286,20 +283,6 @@ class TestWorksheet < Test::Unit::TestCase
assert_nothing_raised { @ws.name = Array.new(31, "A").join('') }
end
- def test_update_auto_with_data
- # small = @ws.workbook.styles.add_style(:sz=>2)
- # big = @ws.workbook.styles.add_style(:sz=>10)
-
- # @ws.add_row ["chasing windmills", "penut"], :style=>small
- # assert(@ws.auto_fit_data.size == 2, "a data item for each column")
-
- # assert_equal(@ws.auto_fit_data[0], {:sz => 2, :longest => "chasing windmills", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
-
-
- # @ws.add_row ["mule"], :style=>big
- # assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column")
- end
-
def test_set_fixed_width_column
@ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil]
assert(@ws.column_info.size == 3, "a data item for each column")
@@ -307,35 +290,11 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(@ws.column_info[1].width, nil, ":ignore does not set any data")
end
- def test_fixed_widths_with_merged_cells
- # @ws.add_row ["hey, I'm like really long and stuff so I think you will merge me."]
- # @ws.merge_cells "A1:C1"
- # @ws.add_row ["but Im Short!"], :widths=> [14.8]
- # assert_equal(@ws.send(:auto_width, @ws.auto_fit_data[0]), 14.8)
- end
-
- def test_fixed_width_to_auto
- # @ws.add_row ["hey, I'm like really long and stuff so I think you will merge me."]
- # @ws.merge_cells "A1:C1"
- # @ws.add_row ["but Im Short!"], :widths=> [14.8]
- # assert_equal(@ws.send(:auto_width, @ws.auto_fit_data[0]), 14.8)
- # @ws.add_row ["no, I like auto!"], :widths=>[:auto]
- # assert_equal(@ws.auto_fit_data[0][:fixed], nil)
- end
-
- def test_auto_width
- # assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size")
-
- # assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fish"}) < @ws.send(:auto_width, {:sz=>12, :longest=>"fish"}), "larger fonts produce longer with with same string")
- # assert_equal(@ws.send(:auto_width, {:sz=>11, :longest => "This is a really long string", :fixed=>0.2}), 0.2, "fixed rules!")
- end
-
def test_fixed_height
@ws.add_row [1, 2, 3], :height => 40
assert_equal(40, @ws.rows[-1].height)
end
-
def test_set_column_width
@ws.add_row ["chasing windmills", "penut"]
@ws.column_widths nil, 0.5