test/workbook/worksheet/tc_worksheet.rb in axlsx-2.0.1 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-2.1.0.pre

- old
+ new

@@ -71,10 +71,19 @@ assert(hf.is_a? Axlsx::HeaderFooter) assert(@ws.header_footer == hf) end end + def test_state + assert_equal(:visible, @ws.state) + end + + def test_state_validation + assert_raise(ArgumentError) { @ws.state = :dead } + assert_nothing_raised { @ws.state = :very_hidden } + end + def test_no_autowidth @ws.workbook.use_autowidth = false @ws.add_row [1,2,3,4] assert_equal(@ws.column_info[0].width, nil) end @@ -258,11 +267,11 @@ end def test_to_xml_string_fit_to_page @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) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:pageSetUpPr[@fitToPage=1]').size, 1) end def test_to_xml_string_dimensions @ws.add_row [1,2,3] doc = Nokogiri::XML(@ws.to_xml_string) @@ -275,17 +284,17 @@ 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) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@tabSelected=1]').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) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetViews/xmlns:sheetView[@showGridLines=0]').size, 1) end def test_to_xml_string_auto_fit_data @ws.add_row [1, "two"] doc = Nokogiri::XML(@ws.to_xml_string) @@ -348,21 +357,21 @@ @ws.print_options do |po| po.grid_lines = true po.horizontal_centered = true end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines="true"][@horizontalCentered="true"]').size, 1) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines=1][@horizontalCentered=1]').size, 1) end def test_to_xml_string_header_footer @ws.header_footer do |hf| hf.different_first = false hf.different_odd_even = false hf.odd_header = 'Test Header' end doc = Nokogiri::XML(@ws.to_xml_string) - assert_equal(doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst="false"][@differentOddEven="false"]').size, 1) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst=0][@differentOddEven=0]').size, 1) end def test_to_xml_string_drawing @ws.add_chart Axlsx::Pie3DChart doc = Nokogiri::XML(@ws.to_xml_string) @@ -387,14 +396,17 @@ def test_styles assert(@ws.styles.is_a?(Axlsx::Styles), 'worksheet provides access to styles') end def test_to_xml_string_with_illegal_chars + old = Axlsx::trust_input + Axlsx::trust_input = false nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f" @ws.add_row [nasties] assert_equal(0, @ws.rows.last.cells.last.value.index("\v")) - assert_equal(nil,@ws.to_xml_string.index("\v")) + assert_equal(nil, @ws.to_xml_string.index("\v")) + Axlsx::trust_input = old end def test_to_xml_string_with_newlines cell_with_newline = "foo\n\r\nbar" @ws.add_row [cell_with_newline] @@ -423,15 +435,15 @@ c = @ws.add_chart Axlsx::Pie3DChart assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship") c = @ws.add_chart Axlsx::Pie3DChart assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship") c = @ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last - assert_equal(@ws.relationships.size, 4, "adding a comment adds 3 relationships") + assert_equal(@ws.relationships.size, 3, "adding a comment adds 2 relationships") c = @ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1" - assert_equal(@ws.relationships.size, 4, "adding multiple comments in the same worksheet should not add any additional comment relationships") + assert_equal(@ws.relationships.size, 3, "adding multiple comments in the same worksheet should not add any additional comment relationships") c = @ws.add_pivot_table 'G5:G6', 'A1:D10' - assert_equal(@ws.relationships.size, 5, "adding a pivot table adds 1 relationship") + assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship") end def test_name_unique assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) } @@ -499,19 +511,46 @@ assert_equal "A9:A10", @ws.send(:merged_cells).first end def test_auto_filter assert(@ws.auto_filter.range.nil?) + assert(@wb.defined_names.none?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) assert_raise(ArgumentError) { @ws.auto_filter = 123 } @ws.auto_filter.range = "A1:D9" assert_equal(@ws.auto_filter.range, "A1:D9") + @ws.to_xml_string + assert(@wb.defined_names.any?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) end + def test_auto_filter_assign + other_ws = @wb.add_worksheet + + assert(@ws.auto_filter.range.nil?) + assert(other_ws.auto_filter.range.nil?) + assert(@wb.defined_names.none?{|defined_name| defined_name.name=='_xlnm._FilterDatabase'}) + assert_raise(ArgumentError) { @ws.auto_filter = 123 } + + @ws.auto_filter = "A1:D9" + assert_equal(@ws.auto_filter.range, "A1:D9") + + other_ws.auto_filter = "A1:D2" + assert_equal(other_ws.auto_filter.range, "A1:D2") + + @ws.to_xml_string + other_ws.to_xml_string + + filter_database = @wb.defined_names.select{|defined_name| defined_name.name=='_xlnm._FilterDatabase'} + assert_equal(2, filter_database.size) + assert_equal(@ws.index, filter_database[0].local_sheet_id) + assert_equal(other_ws.index, filter_database[1].local_sheet_id) + end + + def test_sheet_pr_for_auto_filter @ws.auto_filter.range = 'A1:D9' @ws.auto_filter.add_column 0, :filters, :filter_items => [1] doc = Nokogiri::XML(@ws.to_xml_string) - assert(doc.xpath('//sheetPr[@filterMode="true"]')) + assert(doc.xpath('//sheetPr[@filterMode=1]')) end def test_outline_level_rows 3.times { @ws.add_row [1,2,3] } @ws.outline_level_rows 0, 2