test/test_roo.rb in roo-1.9.1 vs test/test_roo.rb in roo-1.9.2
- old
+ new
@@ -136,14 +136,14 @@
class TestRoo < Test::Unit::TestCase
OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
EXCEL = true # do Excel Tests?
- GOOGLE = true # do Google-Spreadsheet Tests?
+ GOOGLE = false # do Google-Spreadsheet Tests?
EXCELX = true # do Excel-X Tests? (.xlsx-files)
- ONLINE = true
+ ONLINE = false
LONG_RUN = true
GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
def setup
#if DISPLAY_LOG
@@ -156,10 +156,22 @@
end
# call a block of code for each spreadsheet type
# and yield a reference to the roo object
def with_each_spreadsheet(options)
+ # test if the spreadsheet type is valid :nodoc
+ if options[:format]
+ if options[:format].is_a? Symbol
+ options[:format] = [options[:format]]
+ end
+ options[:format].each do |formatname|
+ unless [:openoffice,:excel,:excelx,:google].include?(formatname)
+ raise "invalid spreadsheet type #{formatname}"
+ end
+ end
+ end
+ # end test spreadsheet type :nodoc
options[:format] ||= [:excel, :excelx, :openoffice, :google]
options[:format] = [options[:format]] if options[:format].class == Symbol
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
@@ -779,11 +791,12 @@
def test_huge_document_to_csv
after Date.new(2009,10,1) do
if LONG_RUN
with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
:excel,
- :excelx]) do |oo|
+ :excelx
+ ]) do |oo|
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
File.delete_if_exist("/tmp/Bibelbund.csv")
assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
@@ -796,10 +809,24 @@
end
end
end
end
+ def test_bug_quotes_excelx
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
+ :excel,
+ :excelx]) do |oo|
+ oo.default_sheet = oo.sheets.first
+ assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
+ oo.cell('a',76)
+ dummy = oo.to_csv("csv#{$$}")
+ assert_equal 'Einflüsse der neuen Theologie in "de gereformeerde Kerken van Nederland"',
+ oo.cell('a',78)
+ File.delete_if_exist("csv#{$$}")
+ end
+ end
+
def test_to_csv
with_each_spreadsheet(:name=>'numbers1') do |oo|
master = "#{TESTDIR}/numbers1.csv"
File.delete_if_exist("/tmp/numbers1.csv")
assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
@@ -1418,13 +1445,13 @@
def test_to_xml
after Date.new(2009,10,1) do
with_each_spreadsheet(:name=>'numbers1', :encoding => 'utf8') do |oo|
assert_nothing_raised {oo.to_xml}
sheetname = oo.sheets.first
-# doc = XML::Parser.string(oo.to_xml).parse
-doc = Nokogiri::XML(oo.to_xml)
-# doc.root.each_element {|xml_sheet|
+ # doc = XML::Parser.string(oo.to_xml).parse
+ doc = Nokogiri::XML(oo.to_xml)
+ # doc.root.each_element {|xml_sheet|
doc.root.each {|xml_sheet|
all_cells = init_all_cells(oo, sheetname)
x = 0
assert_equal sheetname, xml_sheet.attributes['name']
xml_sheet.each_element {|cell|
@@ -1844,24 +1871,25 @@
}
end # each
end
def test_cell_methods
- with_each_spreadsheet(:name=>'numbers1') do |oo|
- assert_equal 10, oo.a4 # cell(4,'A')
- assert_equal 11, oo.b4 # cell(4,'B')
- assert_equal 12, oo.c4 # cell(4,'C')
- assert_equal 13, oo.d4 # cell(4,'D')
- assert_equal 14, oo.e4 # cell(4,'E')
- assert_equal 'ABC', oo.c6('Sheet5')
+ after Date.new(2010,1,30) do
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
+ assert_equal 10, oo.a4 # cell(4,'A')
+ assert_equal 11, oo.b4 # cell(4,'B')
+ assert_equal 12, oo.c4 # cell(4,'C')
+ assert_equal 13, oo.d4 # cell(4,'D')
+ assert_equal 14, oo.e4 # cell(4,'E')
+ assert_equal 'ABC', oo.c6('Sheet5')
- assert_raises(ArgumentError) {
- # a42a is not a valid cell name, should raise ArgumentError
- assert_equal 9999, oo.a42a
- }
+ assert_raises(ArgumentError) {
+ # a42a is not a valid cell name, should raise ArgumentError
+ assert_equal 9999, oo.a42a
+ }
+ end
end
-
end
# compare large spreadsheets
def test_compare_large_spreadsheets
@@ -1888,44 +1916,71 @@
end # LONG_RUN
end
end
def test_labeled_cells
- # TODO: more spreadsheet types
- with_each_spreadsheet(:name=>'named_cells', :format=>:openoffice) do |oo|
- oo.default_sheet = oo.sheets.first
- begin
+ after Date.new(2010,1,25) do
+ # TODO: more spreadsheet types
+ with_each_spreadsheet(:name=>'named_cells', :format=>:openoffice) do |oo|
+ oo.default_sheet = oo.sheets.first
+ begin
+ row,col = oo.label('anton')
+ rescue ArgumentError
+ puts "labels error at #{oo.class}"
+ raise
+ end
+ assert_equal 5, row
+ assert_equal 3, col
+
row,col = oo.label('anton')
- rescue ArgumentError
- puts "labels error at #{oo.class}"
- raise
- end
- assert_equal 5, row
- assert_equal 3, col
+ assert_equal 'Anton', oo.cell(row,col)
- row,col = oo.label('anton')
- assert_equal 'Anton', oo.cell(row,col)
+ row,col = oo.label('berta')
+ assert_equal 'Bertha', oo.cell(row,col)
- row,col = oo.label('berta')
- assert_equal 'Bertha', oo.cell(row,col)
+ row,col = oo.label('caesar')
+ assert_equal 'Cäsar', oo.cell(row,col)
- row,col = oo.label('caesar')
- assert_equal 'Cäsar', oo.cell(row,col)
+ # a not defined label:
+ row,col = oo.label('never')
+ assert_nil row
+ assert_nil col
- # a not defined label:
- row,col = oo.label('never')
- assert_nil row
- assert_nil col
-
- row,col,sheet = oo.label('anton')
- assert_equal 5, row
- assert_equal 3, col
- assert_equal "Sheet1", sheet
- #
- # assert_equal "Anton", oo.label('anton')
- after Date.new(2009,12,12) do
- assert_equal "Anton", oo.anton
+ row,col,sheet = oo.label('anton')
+ assert_equal 5, row
+ assert_equal 3, col
+ assert_equal "Sheet1", sheet
+ #
+ # assert_equal "Anton", oo.label('anton')
+ after Date.new(2009,12,12) do
+ assert_equal "Anton", oo.anton
+ end
end
end
end
-
+
+
+ def test_bug_excel_last_row_255
+ after Date.new(2010,2,20) do
+ oo = Excel.new(File.join('test','ScienceStaff.xls'))
+ oo.default_sheet = oo.sheets.first
+ assert_equal "COMSCI", oo.cell(255,1)
+ assert_equal "lala", oo.cell(256,1)
+ assert_equal 1537, oo.last_row
+ end
+ end
+
+ def test_bug_excel_last_row_255_modified
+ oo = Excel.new(File.join('test','ScienceStaff_modified.xls'))
+ oo.default_sheet = oo.sheets.first
+ assert_equal 1537, oo.last_row
+ end
+require 'matrix'
+ def test_matrix
+ with_each_spreadsheet(:name => 'matrix', :format => [:openoffice, :excel, :google]) do |oo|
+ oo.default_sheet = oo.sheets.first
+ assert_equal Matrix[ [1.0, 2.0, 3.0],
+ [4.0, 5.0, 6.0],
+ [7.0, 8.0, 9.0] ], oo.to_matrix
+ end
+ end
end # class