summaryrefslogtreecommitdiffhomepage
path: root/test/workbook
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-03-26 18:29:35 +0900
committerRandy Morgan <[email protected]>2012-03-26 18:29:35 +0900
commit42f45f4138a1f71b19411fd8600f2a2bce67a46b (patch)
treebcef93a7c400d806f1f8aa7a4ebc08d359540d67 /test/workbook
parentd7ccb09a0aaac4564fe01a56305e68d41ee37f57 (diff)
downloadcaxlsx-42f45f4138a1f71b19411fd8600f2a2bce67a46b.tar.gz
caxlsx-42f45f4138a1f71b19411fd8600f2a2bce67a46b.zip
Quick and Dirty run on trying interpolated strings instead of nokogiri for sheet generation.
Diffstat (limited to 'test/workbook')
-rw-r--r--test/workbook/worksheet/tc_cell.rb7
-rw-r--r--test/workbook/worksheet/tc_row.rb12
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb81
3 files changed, 100 insertions, 0 deletions
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 7a33e9b9..fb3814ae 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -222,6 +222,13 @@ class TestCell < Test::Unit::TestCase
assert_equal(@c.ssti, 1)
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))
+ assert_equal(@c.to_xml_string, c_xml.xpath("/c").to_xml(:save_with => 0))
+ 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)"]
diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb
index cabdcde7..b77715c5 100644
--- a/test/workbook/worksheet/tc_row.rb
+++ b/test/workbook/worksheet/tc_row.rb
@@ -60,6 +60,18 @@ class TestRow < Test::Unit::TestCase
assert_equal(0, doc.xpath(".//row[@customHeight]").size)
end
+ def test_to_xml_string
+ r_s_xml = Nokogiri::XML(@row.to_xml_string)
+ assert_equal(r_s_xml.xpath(".//row[@r=1]").size, 1)
+ end
+
+ def test_to_xml_string_with_custom_height
+ @row.add_cell 1
+ @row.height = 20
+ r_s_xml = Nokogiri::XML(@row.to_xml_string)
+ 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
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 6e1991e6..9f8a06e1 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -153,6 +153,87 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(@ws.rows[2].cells[1].style, 0)
end
+ def test_to_xml_string_fit_to_page
+ @ws.fit_to_page = true
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:pageSetUpPr[@fitToPage="true"]').size, 1)
+ end
+
+ def test_to_xml_string_dimensions
+ @ws.add_row [1,2,3]
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size, 1)
+ end
+
+ def test_to_xml_string_selected
+ @ws.selected = true
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@tabSelected="true"]').size, 1)
+ end
+
+ def test_to_xml_string_show_gridlines
+ @ws.show_gridlines = false
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines="false"]').size, 1)
+ end
+
+
+ def test_to_xml_string_show_selection
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@activeCell="A1"]').size, 1)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView/xmlns:selection[@sqref="A1"]').size, 1)
+ end
+
+ def test_to_xml_string_auto_fit_data
+ @ws.add_row [1, "two"]
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size, 2)
+ end
+
+ def test_to_xml_string_sheet_data
+ @ws.add_row [1, "two"]
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size, 1)
+ end
+
+ def test_to_xml_string_auto_filter
+ @ws.add_row [1, "two"]
+ @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)
+ end
+
+ def test_to_xml_string_merge_cells
+ @ws.add_row [1, "two"]
+ @ws.merge_cells "A1:D1"
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1)
+ end
+
+ def test_to_xml_string_page_margins
+ @ws.page_margins do |pm|
+ pm.left = 9
+ pm.right = 7
+ end
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size, 1)
+ end
+
+ def test_to_xml_string_drawing
+ c = @ws.add_chart Axlsx::Pie3DChart
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:drawing[@r:id="rId1"]').size, 1)
+ end
+
+ def test_to_xml_string_tables
+ @ws.add_row ["one", "two"]
+ @ws.add_row [1, 2]
+ @ws.add_table "A1:B2"
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size, 1)
+ assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart[@r:id="rId1"]').size, 1)
+ end
+
def test_to_xml
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml)