roo 1.10.1 → 1.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +38 -0
  4. data/History.txt +4 -4
  5. data/License.txt +20 -0
  6. data/Manifest.txt +68 -0
  7. data/README.markdown +109 -0
  8. data/Rakefile +5 -4
  9. data/bin/roo +0 -0
  10. data/examples/roo_soap_client.rb +53 -0
  11. data/examples/roo_soap_server.rb +29 -0
  12. data/examples/write_me.rb +33 -0
  13. data/lib/roo.rb +20 -61
  14. data/lib/roo/csv.rb +13 -11
  15. data/lib/roo/excel.rb +108 -219
  16. data/lib/roo/excel2003xml.rb +312 -0
  17. data/lib/roo/excelx.rb +205 -341
  18. data/lib/roo/generic_spreadsheet.rb +371 -268
  19. data/lib/roo/google.rb +64 -54
  20. data/lib/roo/openoffice.rb +101 -156
  21. data/lib/roo/roo_rails_helper.rb +5 -5
  22. data/lib/roo/worksheet.rb +18 -0
  23. data/roo.gemspec +43 -0
  24. data/scripts/txt2html +67 -0
  25. data/test/all_ss.rb +8 -10
  26. data/test/{1900_base.xls → files/1900_base.xls} +0 -0
  27. data/test/{1904_base.xls → files/1904_base.xls} +0 -0
  28. data/test/{Bibelbund.csv → files/Bibelbund.csv} +0 -0
  29. data/test/{Bibelbund.ods → files/Bibelbund.ods} +0 -0
  30. data/test/{Bibelbund.xls → files/Bibelbund.xls} +0 -0
  31. data/test/{Bibelbund.xlsx → files/Bibelbund.xlsx} +0 -0
  32. data/test/files/Bibelbund.xml +62518 -0
  33. data/test/{Bibelbund1.ods → files/Bibelbund1.ods} +0 -0
  34. data/test/{Pfand_from_windows_phone.xlsx → files/Pfand_from_windows_phone.xlsx} +0 -0
  35. data/test/files/bad_excel_date.xls +0 -0
  36. data/test/{bbu.ods → files/bbu.ods} +0 -0
  37. data/test/{bbu.xls → files/bbu.xls} +0 -0
  38. data/test/{bbu.xlsx → files/bbu.xlsx} +0 -0
  39. data/test/files/bbu.xml +152 -0
  40. data/test/{bode-v1.ods.zip → files/bode-v1.ods.zip} +0 -0
  41. data/test/{bode-v1.xls.zip → files/bode-v1.xls.zip} +0 -0
  42. data/test/{boolean.ods → files/boolean.ods} +0 -0
  43. data/test/{boolean.xls → files/boolean.xls} +0 -0
  44. data/test/{boolean.xlsx → files/boolean.xlsx} +0 -0
  45. data/test/files/boolean.xml +112 -0
  46. data/test/{borders.ods → files/borders.ods} +0 -0
  47. data/test/{borders.xls → files/borders.xls} +0 -0
  48. data/test/{borders.xlsx → files/borders.xlsx} +0 -0
  49. data/test/files/borders.xml +144 -0
  50. data/test/{bug-row-column-fixnum-float.xls → files/bug-row-column-fixnum-float.xls} +0 -0
  51. data/test/files/bug-row-column-fixnum-float.xml +127 -0
  52. data/test/{comments.ods → files/comments.ods} +0 -0
  53. data/test/{comments.xls → files/comments.xls} +0 -0
  54. data/test/{comments.xlsx → files/comments.xlsx} +0 -0
  55. data/test/{csvtypes.csv → files/csvtypes.csv} +0 -0
  56. data/test/{datetime.ods → files/datetime.ods} +0 -0
  57. data/test/{datetime.xls → files/datetime.xls} +0 -0
  58. data/test/{datetime.xlsx → files/datetime.xlsx} +0 -0
  59. data/test/files/datetime.xml +142 -0
  60. data/test/{datetime_floatconv.xls → files/datetime_floatconv.xls} +0 -0
  61. data/test/files/datetime_floatconv.xml +148 -0
  62. data/test/{dreimalvier.ods → files/dreimalvier.ods} +0 -0
  63. data/test/{emptysheets.ods → files/emptysheets.ods} +0 -0
  64. data/test/{emptysheets.xls → files/emptysheets.xls} +0 -0
  65. data/test/{emptysheets.xlsx → files/emptysheets.xlsx} +0 -0
  66. data/test/files/emptysheets.xml +105 -0
  67. data/test/files/excel2003.xml +21140 -0
  68. data/test/{false_encoding.xls → files/false_encoding.xls} +0 -0
  69. data/test/files/false_encoding.xml +132 -0
  70. data/test/{formula.ods → files/formula.ods} +0 -0
  71. data/test/{formula.xls → files/formula.xls} +0 -0
  72. data/test/{formula.xlsx → files/formula.xlsx} +0 -0
  73. data/test/files/formula.xml +134 -0
  74. data/test/files/formula_parse_error.xls +0 -0
  75. data/test/files/formula_parse_error.xml +1833 -0
  76. data/test/{formula_string_error.xlsx → files/formula_string_error.xlsx} +0 -0
  77. data/test/{html-escape.ods → files/html-escape.ods} +0 -0
  78. data/test/{matrix.ods → files/matrix.ods} +0 -0
  79. data/test/{matrix.xls → files/matrix.xls} +0 -0
  80. data/test/{named_cells.ods → files/named_cells.ods} +0 -0
  81. data/test/{named_cells.xls → files/named_cells.xls} +0 -0
  82. data/test/{named_cells.xlsx → files/named_cells.xlsx} +0 -0
  83. data/test/{no_spreadsheet_file.txt → files/no_spreadsheet_file.txt} +0 -0
  84. data/test/{numbers1.csv → files/numbers1.csv} +0 -0
  85. data/test/{numbers1.ods → files/numbers1.ods} +0 -0
  86. data/test/{numbers1.xls → files/numbers1.xls} +0 -0
  87. data/test/{numbers1.xlsx → files/numbers1.xlsx} +0 -0
  88. data/test/files/numbers1.xml +312 -0
  89. data/test/{only_one_sheet.ods → files/only_one_sheet.ods} +0 -0
  90. data/test/{only_one_sheet.xls → files/only_one_sheet.xls} +0 -0
  91. data/test/{only_one_sheet.xlsx → files/only_one_sheet.xlsx} +0 -0
  92. data/test/files/only_one_sheet.xml +67 -0
  93. data/test/{paragraph.ods → files/paragraph.ods} +0 -0
  94. data/test/{paragraph.xls → files/paragraph.xls} +0 -0
  95. data/test/{paragraph.xlsx → files/paragraph.xlsx} +0 -0
  96. data/test/files/paragraph.xml +127 -0
  97. data/test/{prova.xls → files/prova.xls} +0 -0
  98. data/test/{ric.ods → files/ric.ods} +0 -0
  99. data/test/{simple_spreadsheet.ods → files/simple_spreadsheet.ods} +0 -0
  100. data/test/{simple_spreadsheet.xls → files/simple_spreadsheet.xls} +0 -0
  101. data/test/{simple_spreadsheet.xlsx → files/simple_spreadsheet.xlsx} +0 -0
  102. data/test/files/simple_spreadsheet.xml +225 -0
  103. data/test/{simple_spreadsheet_from_italo.ods → files/simple_spreadsheet_from_italo.ods} +0 -0
  104. data/test/{simple_spreadsheet_from_italo.xls → files/simple_spreadsheet_from_italo.xls} +0 -0
  105. data/test/files/simple_spreadsheet_from_italo.xml +242 -0
  106. data/test/{so_datetime.csv → files/so_datetime.csv} +0 -0
  107. data/test/{style.ods → files/style.ods} +0 -0
  108. data/test/{style.xls → files/style.xls} +0 -0
  109. data/test/{style.xlsx → files/style.xlsx} +0 -0
  110. data/test/files/style.xml +154 -0
  111. data/test/{time-test.csv → files/time-test.csv} +0 -0
  112. data/test/{time-test.ods → files/time-test.ods} +0 -0
  113. data/test/{time-test.xls → files/time-test.xls} +0 -0
  114. data/test/{time-test.xlsx → files/time-test.xlsx} +0 -0
  115. data/test/files/time-test.xml +131 -0
  116. data/test/{type_excel.ods → files/type_excel.ods} +0 -0
  117. data/test/{type_excel.xlsx → files/type_excel.xlsx} +0 -0
  118. data/test/{type_excelx.ods → files/type_excelx.ods} +0 -0
  119. data/test/{type_excelx.xls → files/type_excelx.xls} +0 -0
  120. data/test/{type_openoffice.xls → files/type_openoffice.xls} +0 -0
  121. data/test/{type_openoffice.xlsx → files/type_openoffice.xlsx} +0 -0
  122. data/test/{whitespace.ods → files/whitespace.ods} +0 -0
  123. data/test/{whitespace.xls → files/whitespace.xls} +0 -0
  124. data/test/{whitespace.xlsx → files/whitespace.xlsx} +0 -0
  125. data/test/files/whitespace.xml +184 -0
  126. data/test/test_generic_spreadsheet.rb +257 -0
  127. data/test/test_helper.rb +167 -27
  128. data/test/test_roo.rb +1178 -930
  129. data/website/index.html +385 -0
  130. data/website/index.txt +423 -0
  131. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  132. data/website/stylesheets/screen.css +130 -0
  133. data/website/template.rhtml +48 -0
  134. metadata +151 -121
  135. data/README.txt +0 -110
  136. data/lib/roo/.csv.rb.swp +0 -0
@@ -0,0 +1,257 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+
4
+ class TestGenericSpreadsheet < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @klass = Class.new(Roo::GenericSpreadsheet) do
8
+ def initialize(filename='some_file')
9
+ super
10
+ @filename = filename
11
+ end
12
+
13
+ def read_cells(sheet=nil)
14
+ @cells_read[sheet] = true
15
+ end
16
+
17
+ def cell(row, col, sheet=nil)
18
+ sheet ||= @default_sheet
19
+ @cell[sheet][[row,col]]
20
+ end
21
+
22
+ def celltype(row, col, sheet=nil)
23
+ sheet ||= @default_sheet
24
+ @cell_type[sheet][[row,col]]
25
+ end
26
+
27
+ def sheets
28
+ ['my_sheet','blank sheet']
29
+ end
30
+ end
31
+ @oo = @klass.new
32
+ setup_test_sheet(@oo)
33
+ end
34
+
35
+ context 'Roo::GenericSpreadsheet.letter_to_number(letter)' do
36
+ should "give us 1 for 'A' and 'a'" do
37
+ assert_equal 1, Roo::GenericSpreadsheet.letter_to_number('A')
38
+ assert_equal 1, Roo::GenericSpreadsheet.letter_to_number('a')
39
+ end
40
+
41
+ should "give us the correct value for 'Z'" do
42
+ assert_equal 26, Roo::GenericSpreadsheet.letter_to_number('Z')
43
+ end
44
+
45
+ should "give us the correct value for 'AA' regardless of case mixing" do
46
+ assert_equal 27, Roo::GenericSpreadsheet.letter_to_number('AA')
47
+ assert_equal 27, Roo::GenericSpreadsheet.letter_to_number('aA')
48
+ assert_equal 27, Roo::GenericSpreadsheet.letter_to_number('Aa')
49
+ assert_equal 27, Roo::GenericSpreadsheet.letter_to_number('aa')
50
+ end
51
+
52
+ should "give us the correct value for 'AB'" do
53
+ assert_equal 28, Roo::GenericSpreadsheet.letter_to_number('AB')
54
+ end
55
+
56
+ should "give us the correct value for 'AZ'" do
57
+ assert_equal 26*2, Roo::GenericSpreadsheet.letter_to_number('AZ')
58
+ end
59
+
60
+ should "give us the correct value for 'BZ'" do
61
+ assert_equal 26*3, Roo::GenericSpreadsheet.letter_to_number('BZ')
62
+ end
63
+
64
+ should "give us the correct value for 'ZZ'" do
65
+ assert_equal 26**2 + 26,Roo::GenericSpreadsheet.letter_to_number('ZZ')
66
+ end
67
+ end
68
+
69
+ context "Roo::GenericSpreadsheet.number_to_letter" do
70
+ Roo::GenericSpreadsheet::LETTERS.each_with_index do |l,i|
71
+ should "return '#{l}' when passed #{i+1}" do
72
+ assert_equal l,Roo::GenericSpreadsheet.number_to_letter(i+1)
73
+ end
74
+ end
75
+
76
+ should "return 'AA' when passed 27" do
77
+ assert_equal 'AA',Roo::GenericSpreadsheet.number_to_letter(27)
78
+ end
79
+
80
+ should "return 'AZ' when passed #{26*2}" do
81
+ assert_equal 'AZ', Roo::GenericSpreadsheet.number_to_letter(26*2)
82
+ end
83
+
84
+ should "return 'BZ' when passed #{26*3}" do
85
+ assert_equal 'BZ', Roo::GenericSpreadsheet.number_to_letter(26*3)
86
+ end
87
+
88
+ should "return 'ZZ' when passed #{26**2 + 26}" do
89
+ assert_equal 'ZZ',Roo::GenericSpreadsheet.number_to_letter(26**2 + 26)
90
+ end
91
+
92
+ should "return 'AAA' when passed #{26**2 + 27}" do
93
+ assert_equal 'AAA',Roo::GenericSpreadsheet.number_to_letter(26**2 + 27)
94
+ end
95
+
96
+ should "return 'ZZZ' when passed #{26**3 + 26**2 + 26}" do
97
+ assert_equal 'ZZZ',Roo::GenericSpreadsheet.number_to_letter(26**3 + 26**2 + 26)
98
+ end
99
+
100
+ should "return the correct letter when passed a Float" do
101
+ assert_equal 'A',Roo::GenericSpreadsheet.number_to_letter(1.0)
102
+ end
103
+ end
104
+
105
+ def test_setting_invalid_type_does_not_update_cell
106
+ @oo.set(1,1,1)
107
+ assert_raise(ArgumentError){@oo.set(1,1, :invalid_type)}
108
+ assert_equal 1, @oo.cell(1,1)
109
+ assert_equal :float, @oo.celltype(1,1)
110
+ end
111
+
112
+ def test_first_row
113
+ assert_equal 5,@oo.first_row
114
+ end
115
+
116
+ def test_last_row
117
+ assert_equal 16,@oo.last_row
118
+ end
119
+
120
+ def test_first_column
121
+ assert_equal 1,@oo.first_column
122
+ end
123
+
124
+ def test_first_column_as_letter
125
+ assert_equal 'A', @oo.first_column_as_letter
126
+ end
127
+
128
+ def test_last_column
129
+ assert_equal 7, @oo.last_column
130
+ end
131
+
132
+ def test_last_column_as_letter
133
+ assert_equal 'G', @oo.last_column_as_letter
134
+ end
135
+
136
+ #TODO: inkonsequente Lieferung Fixnum/Float
137
+ def test_rows
138
+ assert_equal [41.0,42.0,43.0,44.0,45.0, nil, nil], @oo.row(12)
139
+ assert_equal [nil, nil, "dreiundvierzig", "vierundvierzig", "fuenfundvierzig", nil, nil], @oo.row(16)
140
+ end
141
+
142
+ def test_empty_eh
143
+ assert @oo.empty?(1,1)
144
+ assert !@oo.empty?(8,3)
145
+ assert @oo.empty?("A",11)
146
+ assert !@oo.empty?("A",12)
147
+ end
148
+
149
+ def test_reload
150
+ @oo.reload
151
+ assert @oo.instance_variable_get(:@cell).empty?
152
+ end
153
+
154
+ def test_to_yaml
155
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), @oo.to_yaml({}, 5,1,5,1)
156
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), @oo.to_yaml({}, 8,3,8,3)
157
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), @oo.to_yaml({}, 12,3,12,3)
158
+ assert_equal \
159
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
160
+ yaml_entry(12,4,"float",44.0) +
161
+ yaml_entry(12,5,"float",45.0), @oo.to_yaml({}, 12,3,12)
162
+ assert_equal \
163
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
164
+ yaml_entry(12,4,"float",44.0)+
165
+ yaml_entry(12,5,"float",45.0)+
166
+ yaml_entry(15,3,"float",43.0)+
167
+ yaml_entry(15,4,"float",44.0)+
168
+ yaml_entry(15,5,"float",45.0)+
169
+ yaml_entry(16,3,"string","dreiundvierzig")+
170
+ yaml_entry(16,4,"string","vierundvierzig")+
171
+ yaml_entry(16,5,"string","fuenfundvierzig"), @oo.to_yaml({}, 12,3)
172
+ end
173
+
174
+ def test_to_csv
175
+ assert_equal expected_csv,@oo.to_csv
176
+ end
177
+ protected
178
+ def setup_test_sheet(workbook=nil)
179
+ workbook ||= @oo
180
+ %w{sheet_values sheet_types cells_read}.each do |meth|
181
+ send("set_#{meth}".to_sym,workbook)
182
+ end
183
+ end
184
+
185
+ def set_sheet_values(workbook)
186
+ vals = workbook.instance_variable_get(:@cell)
187
+ vals[workbook.default_sheet][[5,1]] = Date.civil(1961,11,21).to_s
188
+
189
+ vals[workbook.default_sheet][[8,3]] = "thisisc8"
190
+ vals[workbook.default_sheet][[8,7]] = "thisisg8"
191
+
192
+ vals[workbook.default_sheet][[12,1]] = 41.0
193
+ vals[workbook.default_sheet][[12,2]] = 42.0
194
+ vals[workbook.default_sheet][[12,3]] = 43.0
195
+ vals[workbook.default_sheet][[12,4]] = 44.0
196
+ vals[workbook.default_sheet][[12,5]] = 45.0
197
+
198
+ vals[workbook.default_sheet][[15,3]] = 43.0
199
+ vals[workbook.default_sheet][[15,4]] = 44.0
200
+ vals[workbook.default_sheet][[15,5]] = 45.0
201
+
202
+ vals[workbook.default_sheet][[16,3]] = "dreiundvierzig"
203
+ vals[workbook.default_sheet][[16,4]] = "vierundvierzig"
204
+ vals[workbook.default_sheet][[16,5]] = "fuenfundvierzig"
205
+ end
206
+
207
+ def set_sheet_types(workbook)
208
+ types = workbook.instance_variable_get(:@cell_type)
209
+ types[workbook.default_sheet][[5,1]] = :date
210
+
211
+ types[workbook.default_sheet][[8,3]] = :string
212
+ types[workbook.default_sheet][[8,7]] = :string
213
+
214
+ types[workbook.default_sheet][[12,1]] = :float
215
+ types[workbook.default_sheet][[12,2]] = :float
216
+ types[workbook.default_sheet][[12,3]] = :float
217
+ types[workbook.default_sheet][[12,4]] = :float
218
+ types[workbook.default_sheet][[12,5]] = :float
219
+
220
+ types[workbook.default_sheet][[15,3]] = :float
221
+ types[workbook.default_sheet][[15,4]] = :float
222
+ types[workbook.default_sheet][[15,5]] = :float
223
+
224
+ types[workbook.default_sheet][[16,3]] = :string
225
+ types[workbook.default_sheet][[16,4]] = :string
226
+ types[workbook.default_sheet][[16,5]] = :string
227
+ end
228
+
229
+ def set_first_row(workbook)
230
+ row_hash = workbook.instance_variable_get(:@first_row)
231
+ row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[0]}.min
232
+ end
233
+
234
+ def set_last_row(workbook)
235
+ row_hash = workbook.instance_variable_get(:@last_row)
236
+ row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[0]}.max
237
+ end
238
+
239
+ def set_first_col(workbook)
240
+ col_hash = workbook.instance_variable_get(:@first_column)
241
+ col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[1]}.min
242
+ end
243
+
244
+ def set_last_col(workbook)
245
+ col_hash = workbook.instance_variable_get(:@last_column)
246
+ col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[1]}.max
247
+ end
248
+
249
+ def set_cells_read(workbook)
250
+ read_hash = workbook.instance_variable_get(:@cells_read)
251
+ read_hash[workbook.default_sheet] = true
252
+ end
253
+
254
+ def expected_csv
255
+ ",,,,,,\n,,,,,,\n,,,,,,\n,,,,,,\n1961-11-21,,,,,,\n,,,,,,\n,,,,,,\n,,\"thisisc8\",,,,\"thisisg8\"\n,,,,,,\n,,,,,,\n,,,,,,\n41,42,43,44,45,,\n,,,,,,\n,,,,,,\n,,43,44,45,,\n,,\"dreiundvierzig\",\"vierundvierzig\",\"fuenfundvierzig\",,\n"
256
+ end
257
+ end
data/test/test_helper.rb CHANGED
@@ -1,16 +1,63 @@
1
+ # require deps
2
+ require 'rubygems'
3
+ require 'tmpdir'
1
4
  require 'test/unit'
5
+ require 'shoulda'
6
+ require 'fileutils'
7
+ require 'timeout'
8
+ require 'logger'
9
+ require 'date'
10
+
11
+ # require gem files
2
12
  require File.dirname(__FILE__) + '/../lib/roo'
3
13
 
4
- # helper method
5
- def after(d)
6
- yield if DateTime.now > d
14
+ TESTDIR = File.join(File.dirname(__FILE__), 'files')
15
+
16
+ LOG_DIR = File.join(File.dirname(__FILE__),'log')
17
+ LOG_FILE = File.join(LOG_DIR,'roo.log')
18
+
19
+ test_dirs = Dir.glob(File.dirname(__FILE__)+'/*')
20
+ unless test_dirs.include?(LOG_DIR)
21
+ Dir.mkdir(LOG_DIR)
7
22
  end
8
-
9
- # helper method
10
- def before(d)
11
- yield if DateTime.now <= d
23
+
24
+ $log = Logger.new(LOG_FILE)
25
+
26
+ #$log.level = Logger::WARN
27
+ $log.level = Logger::DEBUG
28
+
29
+ DISPLAY_LOG = false
30
+ DB_LOG = false
31
+
32
+ if DB_LOG
33
+ require 'activerecord'
34
+
35
+ def activerecord_connect
36
+ ActiveRecord::Base.establish_connection(:adapter => "mysql",
37
+ :database => "test_runs",
38
+ :host => "localhost",
39
+ :username => "root",
40
+ :socket => "/var/run/mysqld/mysqld.sock")
41
+ end
42
+
43
+ class Testrun < ActiveRecord::Base
44
+ end
45
+ end
46
+
47
+
48
+ class Roo::Csv
49
+ remove_method :cell_postprocessing
50
+ def cell_postprocessing(row,col,value)
51
+ if row==1 and col==1
52
+ return value.to_f
53
+ end
54
+ if row==1 and col==2
55
+ return value.to_s
56
+ end
57
+ return value
58
+ end
12
59
  end
13
-
60
+
14
61
  # helper method
15
62
  def local_only
16
63
  if ENV["roo_local"] == "thomas-p"
@@ -22,28 +69,121 @@ end
22
69
  # output is an empty string if the files are equal
23
70
  # otherwise differences a printen (not compatible to
24
71
  # the diff command)
25
- def diff(fn1,fn2)
72
+ def file_diff(fn1,fn2)
26
73
  result = ''
27
- f1 = File.open(fn1)
28
- f2 = File.open(fn2)
29
- while f1.eof? == false and f2.eof? == false
30
- line1 = f1.gets
31
- line2 = f2.gets
32
- result << "<#{line1}\n>#{line2}\n" if line1 != line2
33
- end
34
- if f1.eof? == false
35
- while f1.eof? == false
36
- line1 = f1.gets
37
- result << "<#{line1}\n"
74
+ File.open(fn1) do |f1|
75
+ File.open(fn2) do |f2|
76
+ while f1.eof? == false and f2.eof? == false
77
+ line1 = f1.gets.chomp
78
+ line2 = f2.gets.chomp
79
+ result << "<#{line1}\n>#{line2}\n" if line1 != line2
80
+ end
81
+ if f1.eof? == false
82
+ while f1.eof? == false
83
+ line1 = f1.gets
84
+ result << "<#{line1}\n"
85
+ end
86
+ end
87
+ if f2.eof? == false
88
+ while f2.eof? == false
89
+ line2 = f2.gets
90
+ result ">#{line2}\n"
91
+ end
92
+ end
38
93
  end
39
94
  end
40
- if f2.eof? == false
41
- while f2.eof? == false
42
- line2 = f2.gets
43
- result ">#{line2}\n"
95
+ result
96
+ end
97
+
98
+ class File
99
+ def File.delete_if_exist(filename)
100
+ if File.exist?(filename)
101
+ File.delete(filename)
44
102
  end
45
103
  end
46
- f1.close
47
- f2.close
48
- result
49
104
  end
105
+
106
+ # :nodoc
107
+ class Fixnum
108
+ def minutes
109
+ self * 60
110
+ end
111
+ end
112
+
113
+ class Test::Unit::TestCase
114
+ def key_of(spreadsheetname)
115
+ return {
116
+ #'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
117
+ 'formula' => 'o10837434939102457526.3022866619437760118',
118
+ #"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
119
+ "write.me" => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
120
+ #'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
121
+ 'numbers1' => 'o10837434939102457526.4784396906364855777',
122
+ #'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
123
+ 'borders' => "o10837434939102457526.664868920231926255",
124
+ #'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
125
+ 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
126
+ 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
127
+ #"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
128
+ "only_one_sheet" => "o10837434939102457526.762705759906130135",
129
+ #'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
130
+ 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
131
+ #'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
132
+ 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
133
+ 'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ",
134
+ 'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
135
+ }[spreadsheetname]
136
+ # 'numbers1' => "o10837434939102457526.4784396906364855777",
137
+ # 'borders' => "o10837434939102457526.664868920231926255",
138
+ # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
139
+ # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
140
+ # "only_one_sheet" => "o10837434939102457526.762705759906130135",
141
+ # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
142
+ # 'formula' => 'o10837434939102457526.3022866619437760118',
143
+ # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
144
+ # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
145
+ rescue
146
+ raise "unknown spreadsheetname: #{spreadsheetname}"
147
+ end
148
+
149
+ def yaml_entry(row,col,type,value)
150
+ "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
151
+ end
152
+
153
+ if DB_LOG
154
+ if ! (defined?(@connected) and @connected)
155
+ activerecord_connect
156
+ else
157
+ @connected = true
158
+ end
159
+ end
160
+ # alias unlogged_run run
161
+ # def run(result, &block)
162
+ # t1 = Time.now
163
+ # if DISPLAY_LOG
164
+ # v1,v2,_ = RUBY_VERSION.split('.')
165
+ # if v1.to_i > 1 or
166
+ # (v1.to_i == 1 and v2.to_i > 8)
167
+ # # Ruby 1.9.x
168
+ # print "RUNNING #{self.class} #{self.__name__} \t#{Time.now.to_s}"
169
+ # else
170
+ # # Ruby < 1.9.x
171
+ # print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
172
+ # end
173
+ # STDOUT.flush
174
+ # end
175
+ # unlogged_run result, &block
176
+ # t2 = Time.now
177
+ # if DISPLAY_LOG
178
+ # puts "\t#{t2-t1} seconds"
179
+ # end
180
+ # if DB_LOG
181
+ # Testrun.create(
182
+ # :class_name => self.class.to_s,
183
+ # :test_name => @method_name,
184
+ # :start => t1,
185
+ # :duration => t2-t1
186
+ # )
187
+ # end
188
+ # end
189
+ end