test/test_roo.rb in roo-0.3.0 vs test/test_roo.rb in roo-0.4.0

- old
+ new

@@ -188,10 +188,11 @@ assert_equal "thisisc8", oo.cell(8,'c') assert_equal "thisisc8", oo.cell('c',8) assert_equal "thisisd9", oo.cell('d',9) assert_equal "thisisa11", oo.cell('a',11) + #assert_equal "lulua", oo.cell('b',10) end if GOOGLE @goo.default_sheet = 1 # @goo.sheets.first assert_equal "tata", @goo.cell(6,1) @@ -428,23 +429,19 @@ assert_equal 2, oo.first_column assert_equal 'B', oo.first_column_as_letter assert_equal 5, oo.first_row assert_equal 'E', oo.last_column_as_letter assert_equal 14, oo.last_row - assert_equal 'E', oo.first_row_as_letter - assert_equal 'N', oo.last_row_as_letter if EXCEL #-- Excel oo = Excel.new(File.join("test","numbers1.xls")) oo.default_sheet = 2 # "Name of Sheet 2" assert_equal 2, oo.first_column assert_equal 'B', oo.first_column_as_letter assert_equal 5, oo.first_row assert_equal 'E', oo.last_column_as_letter assert_equal 14, oo.last_row - assert_equal 'E', oo.first_row_as_letter - assert_equal 'N', oo.last_row_as_letter end end def test_multiple_letters #-- OpenOffice @@ -535,18 +532,26 @@ File.join("test","numbers2.ods")) end end def test_reload - oo = Openoffice.new(File.join("test","numbers1.ods")) - oo.default_sheet = oo.sheets.first - assert_equal 1, oo.cell(1,1) + if OPENOFFICE + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = oo.sheets.first + assert_equal 1, oo.cell(1,1) -if DateTime.now < Date.new(2007, 6, 15) - oo.reload - assert_equal 2, oo.cell(1,1) -end + oo.reload + assert_equal 1, oo.cell(1,1) + end + if EXCEL + oo = Excel.new(File.join("test","numbers1.xls")) + oo.default_sheet = 1 # oo.sheets.first + assert_equal 1, oo.cell(1,1) + + oo.reload + assert_equal 1, oo.cell(1,1) + end end def test_bug_contiguous_cells if OPENOFFICE oo = Openoffice.new(File.join("test","numbers1.ods")) @@ -685,61 +690,169 @@ assert_equal(41.31205555, oo.cell('AA',5)) assert_equal(2218.3344, oo.cell('AB',5)) end end + def myfunc(n) + puts "#{n} Euro" + end def test_formula + if OPENOFFICE + oo = Openoffice.new(File.join("test","formula.ods")) + oo.default_sheet = oo.sheets.first + assert_equal 1, oo.cell('A',1) + assert_equal 2, oo.cell('A',2) + assert_equal 3, oo.cell('A',3) + assert_equal 4, oo.cell('A',4) + assert_equal 5, oo.cell('A',5) + assert_equal 6, oo.cell('A',6) + assert_equal 21, oo.cell('A',7) + assert_equal :formula, oo.celltype('A',7) + assert_equal "=[Sheet2.A1]", oo.formula('C',7) + assert_nil oo.formula('A',6) + assert_equal [[7, 1, "=SUM([.A1:.A6])"], + [7, 2, "=SUM([.$A$1:.B6])"], + [7, 3, "=[Sheet2.A1]"], + [8, 2, "=SUM([.$A$1:.B7])"], + ], oo.formulas - oo = Openoffice.new(File.join("test","formula.ods")) - oo.default_sheet = oo.sheets.first - assert_equal 1, oo.cell('A',1) - assert_equal 2, oo.cell('A',2) - assert_equal 3, oo.cell('A',3) - assert_equal 4, oo.cell('A',4) - assert_equal 5, oo.cell('A',5) - assert_equal 6, oo.cell('A',6) - assert_equal 21, oo.cell('A',7) - assert_equal :formula, oo.celltype('A',7) - #assert_equal "=SUM(A1:A6)", oo.formula('A',7) - #assert_equal "=SUM(A1:A6)", oo.formula('B',7) - #assert_equal "=SUM(A1:A6)", oo.formula('B',7) - assert_equal "=[Sheet2.A1]", oo.formula('C',7) - assert_nil oo.formula('A',6) + if DateTime.now > Date.new(2007,6,25) + # setting a cell + oo.set('A',15, 41) + assert_equal 41, oo.cell('A',15) + oo.set('A',16, "41") + assert_equal "41", oo.cell('A',16) + oo.set('A',17, 42.5) + assert_equal 42.5, oo.cell('A',17) + end + if DateTime.now > Date.new(2007,6,30) + assert_equal 21, oo.solve('a',7) + end - oo = Openoffice.new(File.join("test","external1.ods")) - # each spreadsheet, each row, each column - oo.sheets.each {|sheet| - oo.default_sheet = sheet - oo.first_row.upto(oo.last_row) do |row| - oo.first_column.upto(oo.last_column) do |col| - value = oo.cell(row,col) - # is it a formula? - if oo.formula?(row,col) - # formula - puts oo.formula(row,col) - # value - puts value if value - else - puts value if value + oo = Openoffice.new(File.join("test","external1.ods")) + # each spreadsheet, each row, each column + oo.sheets.each {|sheet| + oo.default_sheet = sheet + if oo.first_row + oo.first_row.upto(oo.last_row) do |row| + oo.first_column.upto(oo.last_column) do |col| + value = oo.cell(row,col) + # is it a formula? + if oo.formula?(row,col) + # formula + puts oo.formula(row,col) + # value + puts value if value + else + puts value if value + end + end end end - end - } - if false - oo = Excel.new(File.join("test","formula.xls")) - oo.default_sheet = 1 # oo.sheets.first - assert_equal 1, oo.cell('A',1) - assert_equal 2, oo.cell('A',2) - assert_equal 3, oo.cell('A',3) - assert_equal 4, oo.cell('A',4) - assert_equal 5, oo.cell('A',5) - assert_equal 6, oo.cell('A',6) - assert_equal 21, oo.cell('A',7), oo.cell('A',7).to_yaml - assert_equal :formula, oo.celltype('A',7) - assert_equal "=SUM(A1:A6)", oo.formula('A',7) - assert_equal "=SUM(A1:A6)", oo.formula('B',7) - assert_nil oo.formula('A',6) + } end + end + + def test_borders_sheets + if OPENOFFICE + oo = Openoffice.new(File.join("test","borders.ods")) + oo.default_sheet = oo.sheets[1] + assert_equal 6, oo.first_row + assert_equal 11, oo.last_row + assert_equal 4, oo.first_column + assert_equal 8, oo.last_column + + oo.default_sheet = oo.sheets.first + #assert_nil oo.first_row + assert_equal 5, oo.first_row + #assert_nil oo.last_row + assert_equal 10, oo.last_row + assert_equal 3, oo.first_column + #assert_nil oo.first_column + assert_equal 7, oo.last_column + #assert_nil oo.last_column + + oo.default_sheet = oo.sheets[2] + assert_equal 7, oo.first_row + assert_equal 12, oo.last_row + assert_equal 5, oo.first_column + assert_equal 9, oo.last_column + end + if EXCEL + oo = Excel.new(File.join("test","borders.xls")) + oo.default_sheet = 2 # oo.sheets[1] + assert_equal 6, oo.first_row + assert_equal 11, oo.last_row + assert_equal 4, oo.first_column + assert_equal 8, oo.last_column + + oo.default_sheet = 1 # oo.sheets.first + #assert_nil oo.first_row + assert_equal 5, oo.first_row + #assert_nil oo.last_row + assert_equal 10, oo.last_row + assert_equal 3, oo.first_column + #assert_nil oo.first_column + assert_equal 7, oo.last_column + #assert_nil oo.last_column + + oo.default_sheet = 3 # oo.sheets[2] + assert_equal 7, oo.first_row + assert_equal 12, oo.last_row + assert_equal 5, oo.first_column + assert_equal 9, oo.last_column + end + end + + def yaml_entry(row,col,type,value) + "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n" + end + + def test_to_yaml + if OPENOFFICE + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = oo.sheets.first + assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1) + assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3) + assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3) + assert_equal \ + "--- \n"+yaml_entry(12,3,"float",43.0) + + yaml_entry(12,4,"float",44.0) + + yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12) + assert_equal \ + "--- \n"+yaml_entry(12,3,"float",43.0)+ + yaml_entry(12,4,"float",44.0)+ + yaml_entry(12,5,"float",45.0)+ + yaml_entry(15,3,"float",43.0)+ + yaml_entry(15,4,"float",44.0)+ + yaml_entry(15,5,"float",45.0)+ + yaml_entry(16,3,"string","dreiundvierzig")+ + yaml_entry(16,4,"string","vierundvierzig")+ + yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3) + end + if EXCEL + oo = Excel.new(File.join("test","numbers1.xls")) + oo.default_sheet = 1 + assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1) + assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3) + assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3) + assert_equal \ + "--- \n"+yaml_entry(12,3,"float",43.0) + + yaml_entry(12,4,"float",44.0) + + yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12) + assert_equal \ + "--- \n"+yaml_entry(12,3,"float",43.0)+ + yaml_entry(12,4,"float",44.0)+ + yaml_entry(12,5,"float",45.0)+ + yaml_entry(15,3,"float",43.0)+ + yaml_entry(15,4,"float",44.0)+ + yaml_entry(15,5,"float",45.0)+ + yaml_entry(16,3,"string","dreiundvierzig")+ + yaml_entry(16,4,"string","vierundvierzig")+ + yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3) + end + end + end # class