test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.7 vs test/workbook/worksheet/tc_worksheet.rb in axlsx-1.1.8
- old
+ new
@@ -12,10 +12,18 @@
assert_equal(@ws.pn, "worksheets/sheet1.xml")
ws = @ws.workbook.add_worksheet
assert_equal(ws.pn, "worksheets/sheet2.xml")
end
+ def test_name_is_html_encoded
+ @ws.name = '<foo> & <bar>'
+ assert_equal(@ws.name, '<foo> & <bar>')
+ end
+
+ def test_name_exception_on_colon
+ assert_raises(ArgumentError) { @ws.name = 'foo:bar' }
+ end
def test_page_margins
assert(@ws.page_margins.is_a? Axlsx::PageMargins)
end
def test_page_margins_yeild
@@ -106,10 +114,15 @@
@ws.add_row [1, 2, 3]
@ws.add_row [4, 5, 6]
assert_equal @ws.dimension, "A1:C2"
end
+ def test_dimension_with_empty_row
+ @ws.add_row
+ assert_equal "A1:AA200", @ws.dimension
+ end
+
def test_referencing
@ws.add_row [1, 2, 3]
@ws.add_row [4, 5, 6]
range = @ws["A1:C2"]
first_row = @ws[0]
@@ -199,12 +212,12 @@
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)
+ @ws.fit_to_page = true
+ assert_equal(@ws.fit_to_page?, false)
end
def test_to_xml_string_selected
@ws.selected = true
doc = Nokogiri::XML(@ws.to_xml_string)
@@ -246,11 +259,11 @@
end
def test_to_xml_string_sheet_protection
@ws.sheet_protection.password = 'fish'
doc = Nokogiri::XML(@ws.to_xml_string)
- assert(doc.xpath('//sheetProtection'))
+ assert(doc.xpath('//xmlns:sheetProtection'))
end
def test_to_xml_string_page_margins
@ws.page_margins do |pm|
pm.left = 9
@@ -300,18 +313,19 @@
end
def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
- errors = []
- schema.validate(doc).each do |error|
- errors.push error
- puts error.message
- end
- assert(errors.empty?, "error free validation")
+ assert(schema.validate(doc).map{ |e| puts e.message; e }.empty?, "error free validation")
end
+ def test_to_xml_string_with_illegal_chars
+ 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"))
+ end
# Make sure the XML for all optional elements (like pageMargins, autoFilter, ...)
# is generated in correct order.
def test_valid_with_optional_elements
@ws.page_margins.set :left => 9
@ws.page_setup.set :fit_to_width => 1
@@ -320,17 +334,11 @@
@ws.merge_cells "A4:A5"
@ws.add_chart Axlsx::Pie3DChart
@ws.add_table "E1:F3"
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
- errors = []
- schema.validate(doc).each do |error|
- errors.push error
- puts error.message
- end
- assert(errors.empty?, "error free validation")
-
+ assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, schema.validate(doc).map { |e| e.message }.join('\n'))
end
def test_relationships
@ws.add_row [1,2,3]
assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
@@ -348,12 +356,12 @@
def test_name_unique
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('') }
+ assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join() }
+ assert_nothing_raised { @ws.name = Array.new(31, "A").join() }
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")
@@ -372,9 +380,22 @@
assert_equal(@ws.column_info[1].width, 0.5, 'eat my width')
assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 }
assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" }
end
+ def test_protect_range
+ assert(@ws.protected_ranges.is_a?(Axlsx::SimpleTypedList))
+ assert_equal(0, @ws.protected_ranges.size)
+ @ws.protect_range('A1:A3')
+ assert_equal('A1:A3', @ws.protected_ranges.last.sqref)
+ end
+
+ def test_protect_range_with_cells
+ @ws.add_row [1, 2, 3]
+ assert_nothing_raised {@ws.protect_range(@ws.rows.first.cells) }
+ assert_equal('A1:C1', @ws.protected_ranges.last.sqref)
+
+ end
def test_merge_cells
assert(@ws.merged_cells.is_a?(Array))
assert_equal(@ws.merged_cells.size, 0)
@ws.add_row [1,2,3]
@ws.add_row [4,5,6]