test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.5 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.6
- old
+ new
@@ -178,24 +178,35 @@
@ws.rows[1].cells[(1..-1)].each do | c |
assert_equal(c.style, 1)
end
assert_equal(@ws.rows[1].cells[0].style, 0)
assert_equal(@ws.rows[2].cells[1].style, 0)
+ @ws.row_style( 1..2, 1, :col_offset => 2)
+ @ws.rows[(1..2)].each do |r|
+ r.cells[(2..-1)].each do |c|
+ assert_equal(c.style, 1)
+ end
+ end
end
def test_to_xml_string_fit_to_page
- @ws.fit_to_page = true
+ @ws.page_setup.fit_to_width = 1
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_fit_to_page_assignation_does_nothing
+ @ws.fit_to_page = false
+ assert_equal(@ws.fit_to_page, false)
+ 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
@@ -239,10 +250,16 @@
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1)
end
+ def test_to_xml_string_sheet_protection
+ @ws.sheet_protection.password = 'fish'
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert(doc.xpath('//sheetProtection'))
+ end
+
def test_to_xml_string_page_margins
@ws.page_margins do |pm|
pm.left = 9
pm.right = 7
end
@@ -267,11 +284,11 @@
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines="true"][@horizontalCentered="true"]').size, 1)
end
def test_to_xml_string_drawing
- c = @ws.add_chart Axlsx::Pie3DChart
+ @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
@@ -334,11 +351,11 @@
assert_equal(@ws.relationships.size, 4, "adding multiple comments in the same worksheet should not add any additional comment relationships")
end
def test_name_unique
- assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> @ws) }
+ assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) }
end
def test_name_size
assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join('') }
assert_nothing_raised { @ws.name = Array.new(31, "A").join('') }
@@ -374,10 +391,18 @@
@ws.merge_cells "B2:C3"
@ws.merge_cells @ws.rows.last.cells[(0..1)]
assert_equal(@ws.merged_cells.size, 3)
assert_equal(@ws.merged_cells.last, "A3:B3")
end
-
+
+ def test_merge_cells_sorts_correctly_by_row_when_given_array
+ 10.times do |i|
+ @ws.add_row [i]
+ end
+ @ws.merge_cells [@ws.rows[8].cells.first, @ws.rows[9].cells.first]
+ assert_equal "A9:A10", @ws.merged_cells.first
+ end
+
def test_auto_filter
assert(@ws.auto_filter.nil?)
assert_raise(ArgumentError) { @ws.auto_filter = 123 }
@ws.auto_filter = "A1:D9"
assert_equal(@ws.auto_filter, "A1:D9")