roo 1.3.11 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +15 -6
- data/Manifest.txt +53 -0
- data/README.txt +97 -0
- data/Rakefile +45 -0
- data/bin/roo +8 -0
- data/lib/roo.rb +55 -9
- data/lib/roo/excel.rb +44 -40
- data/lib/roo/excelx.rb +99 -60
- data/lib/roo/generic_spreadsheet.rb +29 -1
- data/lib/roo/google.rb +71 -117
- data/lib/roo/openoffice.rb +79 -27
- data/lib/roo/version.rb +9 -9
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- data/test/1900_base.xls +0 -0
- data/test/1904_base.xls +0 -0
- data/test/Bibelbund.csv +0 -0
- data/test/bode-v1.ods.zip +0 -0
- data/test/bode-v1.xls.zip +0 -0
- data/test/boolean.xls +0 -0
- data/test/datetime.xls +0 -0
- data/test/named_cells.ods +0 -0
- data/test/numbers1.csv +0 -0
- data/test/{bad_excel_date.xls → prova.xls} +0 -0
- data/test/test_helper.rb +1 -1
- data/test/test_roo.rb +365 -256
- data/test/whitespace.xls +0 -0
- metadata +48 -30
- data/README.markdown +0 -55
- data/examples/roo_soap_client.rb +0 -53
- data/examples/roo_soap_server.rb +0 -29
- data/examples/write_me.rb +0 -33
- data/test/formula_parse_error.xls +0 -0
- data/test/skipped_tests.rb +0 -789
data/tasks/spec.rake
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
|
3
|
+
require 'spec/rake/verify_rcov'
|
4
|
+
|
5
|
+
namespace :spec do
|
6
|
+
|
7
|
+
desc 'Run all specs with basic output'
|
8
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
9
|
+
t.ruby_opts = PROJ.ruby_opts
|
10
|
+
t.spec_opts = PROJ.spec.opts
|
11
|
+
t.spec_files = PROJ.spec.files
|
12
|
+
t.libs += PROJ.libs
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Run all specs with text output'
|
16
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
17
|
+
t.ruby_opts = PROJ.ruby_opts
|
18
|
+
t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
|
19
|
+
t.spec_files = PROJ.spec.files
|
20
|
+
t.libs += PROJ.libs
|
21
|
+
end
|
22
|
+
|
23
|
+
if HAVE_RCOV
|
24
|
+
desc 'Run all specs with RCov'
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
26
|
+
t.ruby_opts = PROJ.ruby_opts
|
27
|
+
t.spec_opts = PROJ.spec.opts
|
28
|
+
t.spec_files = PROJ.spec.files
|
29
|
+
t.libs += PROJ.libs
|
30
|
+
t.rcov = true
|
31
|
+
t.rcov_dir = PROJ.rcov.dir
|
32
|
+
t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
|
33
|
+
end
|
34
|
+
|
35
|
+
RCov::VerifyTask.new(:verify) do |t|
|
36
|
+
t.threshold = PROJ.rcov.threshold
|
37
|
+
t.index_html = File.join(PROJ.rcov.dir, 'index.html')
|
38
|
+
t.require_exact_threshold = PROJ.rcov.threshold_exact
|
39
|
+
end
|
40
|
+
|
41
|
+
task :verify => :rcov
|
42
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
43
|
+
end
|
44
|
+
|
45
|
+
end # namespace :spec
|
46
|
+
|
47
|
+
desc 'Alias to spec:run'
|
48
|
+
task :spec => 'spec:run'
|
49
|
+
|
50
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
51
|
+
|
52
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
53
|
+
|
54
|
+
# EOF
|
data/tasks/svn.rake
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
if HAVE_SVN
|
3
|
+
|
4
|
+
unless PROJ.svn.root
|
5
|
+
info = %x/svn info ./
|
6
|
+
m = %r/^Repository Root:\s+(.*)$/.match(info)
|
7
|
+
PROJ.svn.root = (m.nil? ? '' : m[1])
|
8
|
+
end
|
9
|
+
PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
|
10
|
+
|
11
|
+
namespace :svn do
|
12
|
+
|
13
|
+
# A prerequisites task that all other tasks depend upon
|
14
|
+
task :prereqs
|
15
|
+
|
16
|
+
desc 'Show tags from the SVN repository'
|
17
|
+
task :show_tags => 'svn:prereqs' do |t|
|
18
|
+
tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
|
19
|
+
tags.gsub!(%r/\/$/, '')
|
20
|
+
tags = tags.split("\n").sort {|a,b| b <=> a}
|
21
|
+
puts tags
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Create a new tag in the SVN repository'
|
25
|
+
task :create_tag => 'svn:prereqs' do |t|
|
26
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
27
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
28
|
+
|
29
|
+
svn = PROJ.svn
|
30
|
+
trunk = File.join(svn.root, svn.trunk)
|
31
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
32
|
+
tag = File.join(svn.root, svn.tags, tag)
|
33
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
34
|
+
|
35
|
+
puts "Creating SVN tag '#{tag}'"
|
36
|
+
unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
|
37
|
+
abort "Tag creation failed"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end # namespace :svn
|
42
|
+
|
43
|
+
task 'gem:release' => 'svn:create_tag'
|
44
|
+
|
45
|
+
end # if PROJ.svn.path
|
46
|
+
|
47
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
10
|
+
else PROJ.test.files end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test.opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
|
19
|
+
opts = opts.join(' ')
|
20
|
+
files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
21
|
+
else PROJ.test.files end
|
22
|
+
files = files.join(' ')
|
23
|
+
sh "#{RCOV} #{files} #{opts}"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# EOF
|
data/tasks/zentest.rake
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
if HAVE_ZENTEST
|
2
|
+
|
3
|
+
# --------------------------------------------------------------------------
|
4
|
+
if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
|
5
|
+
require 'autotest'
|
6
|
+
|
7
|
+
namespace :test do
|
8
|
+
task :autotest do
|
9
|
+
Autotest.run
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Run the autotest loop"
|
14
|
+
task :autotest => 'test:autotest'
|
15
|
+
|
16
|
+
end # if test
|
17
|
+
|
18
|
+
# --------------------------------------------------------------------------
|
19
|
+
if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
|
20
|
+
require 'autotest/rspec'
|
21
|
+
|
22
|
+
namespace :spec do
|
23
|
+
task :autotest do
|
24
|
+
load '.autotest' if test(?f, '.autotest')
|
25
|
+
Autotest::Rspec.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Run the autotest loop"
|
30
|
+
task :autotest => 'spec:autotest'
|
31
|
+
|
32
|
+
end # if rspec
|
33
|
+
|
34
|
+
end # if HAVE_ZENTEST
|
35
|
+
|
36
|
+
# EOF
|
data/test/1900_base.xls
CHANGED
File without changes
|
data/test/1904_base.xls
CHANGED
File without changes
|
data/test/Bibelbund.csv
CHANGED
File without changes
|
data/test/bode-v1.ods.zip
CHANGED
File without changes
|
data/test/bode-v1.xls.zip
CHANGED
File without changes
|
data/test/boolean.xls
CHANGED
File without changes
|
data/test/datetime.xls
CHANGED
Binary file
|
Binary file
|
data/test/numbers1.csv
CHANGED
File without changes
|
Binary file
|
data/test/test_helper.rb
CHANGED
data/test/test_roo.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
|
2
3
|
# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
|
3
4
|
# Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
|
4
5
|
# zum Testen eignete.
|
@@ -8,15 +9,14 @@
|
|
8
9
|
# (like 'diff') must be changed (or commented out ;-)) if you want to run
|
9
10
|
# the tests under another OS
|
10
11
|
#
|
11
|
-
|
12
|
-
|
12
|
+
require './lib/roo'
|
13
13
|
#TODO
|
14
14
|
# Look at formulas in excel - does not work with date/time
|
15
15
|
|
16
16
|
|
17
17
|
# Dump warnings that come from the test to open files
|
18
18
|
# with the wrong spreadsheet class
|
19
|
-
STDERR.reopen "/dev/null","w"
|
19
|
+
#STDERR.reopen "/dev/null","w"
|
20
20
|
|
21
21
|
TESTDIR = File.dirname(__FILE__)
|
22
22
|
require TESTDIR + '/test_helper.rb'
|
@@ -25,8 +25,8 @@ require 'fileutils'
|
|
25
25
|
require 'timeout'
|
26
26
|
require 'logger'
|
27
27
|
$log = Logger.new(File.join(ENV['HOME'],"roo.log"))
|
28
|
-
|
29
|
-
|
28
|
+
#$log.level = Logger::WARN
|
29
|
+
$log.level = Logger::DEBUG
|
30
30
|
|
31
31
|
DISPLAY_LOG = false
|
32
32
|
DB_LOG = false
|
@@ -55,26 +55,34 @@ class Test::Unit::TestCase
|
|
55
55
|
begin
|
56
56
|
|
57
57
|
return {
|
58
|
-
'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
'
|
58
|
+
#'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
|
59
|
+
'formula' => 'o10837434939102457526.3022866619437760118',
|
60
|
+
#"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
|
61
|
+
"write.me" => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
|
62
|
+
#'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
|
63
|
+
'numbers1' => 'o10837434939102457526.4784396906364855777',
|
64
|
+
#'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
|
65
|
+
'borders' => "o10837434939102457526.664868920231926255",
|
66
|
+
#'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
|
67
|
+
'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
63
68
|
'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
|
64
|
-
"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
|
65
|
-
|
66
|
-
'
|
69
|
+
#"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
|
70
|
+
"only_one_sheet" => "o10837434939102457526.762705759906130135",
|
71
|
+
#'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
|
72
|
+
'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
73
|
+
#'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
|
74
|
+
'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
67
75
|
'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ"
|
68
76
|
}[spreadsheetname]
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
77
|
+
# 'numbers1' => "o10837434939102457526.4784396906364855777",
|
78
|
+
# 'borders' => "o10837434939102457526.664868920231926255",
|
79
|
+
# 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
80
|
+
# 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
|
81
|
+
# "only_one_sheet" => "o10837434939102457526.762705759906130135",
|
82
|
+
# "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
|
83
|
+
# 'formula' => 'o10837434939102457526.3022866619437760118',
|
84
|
+
# 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
85
|
+
# 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
78
86
|
rescue
|
79
87
|
raise "unknown spreadsheetname: #{spreadsheetname}"
|
80
88
|
end
|
@@ -130,11 +138,11 @@ class TestRoo < Test::Unit::TestCase
|
|
130
138
|
|
131
139
|
OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
|
132
140
|
EXCEL = true # do Excel Tests?
|
133
|
-
GOOGLE =
|
141
|
+
GOOGLE = true # do Google-Spreadsheet Tests?
|
134
142
|
EXCELX = true # do Excel-X Tests? (.xlsx-files)
|
135
143
|
|
136
144
|
ONLINE = true
|
137
|
-
LONG_RUN =
|
145
|
+
LONG_RUN = true
|
138
146
|
GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
|
139
147
|
|
140
148
|
def setup
|
@@ -150,24 +158,13 @@ class TestRoo < Test::Unit::TestCase
|
|
150
158
|
# call a block of code for each spreadsheet type
|
151
159
|
# and yield a reference to the roo object
|
152
160
|
def with_each_spreadsheet(options)
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
def with_public_google_spreadsheet(&block)
|
162
|
-
user = ENV['GOOGLE_MAIL']
|
163
|
-
pass = ENV['GOOGLE_PASSWORD']
|
164
|
-
ENV['GOOGLE_MAIL'] = ''
|
165
|
-
ENV['GOOGLE_PASSWORD'] = ''
|
166
|
-
block.call
|
167
|
-
ENV['GOOGLE_MAIL'] = user
|
168
|
-
ENV['GOOGLE_PASSWORD'] = pass
|
161
|
+
options[:format] ||= [:excel, :excelx, :openoffice, :google]
|
162
|
+
options[:format] = [options[:format]] if options[:format].class == Symbol
|
163
|
+
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
|
164
|
+
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
|
165
|
+
yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
|
166
|
+
yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
|
169
167
|
end
|
170
|
-
|
171
168
|
# Using Date.strptime so check that it's using the method
|
172
169
|
# with the value set in date_format
|
173
170
|
def test_date
|
@@ -223,11 +220,14 @@ class TestRoo < Test::Unit::TestCase
|
|
223
220
|
oo.default_sheet = sh
|
224
221
|
assert_equal sh, oo.default_sheet
|
225
222
|
}
|
226
|
-
end
|
223
|
+
end
|
227
224
|
end
|
228
|
-
|
225
|
+
|
229
226
|
def test_cells
|
230
|
-
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
227
|
+
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
228
|
+
# warum ist Auswaehlen erstes sheet hier nicht
|
229
|
+
# mehr drin?
|
230
|
+
oo.default_sheet = oo.sheets.first
|
231
231
|
assert_equal 1, oo.cell(1,1)
|
232
232
|
assert_equal 2, oo.cell(1,2)
|
233
233
|
assert_equal 3, oo.cell(1,3)
|
@@ -258,9 +258,9 @@ class TestRoo < Test::Unit::TestCase
|
|
258
258
|
end
|
259
259
|
|
260
260
|
def test_celltype
|
261
|
-
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
261
|
+
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
262
262
|
assert_equal :string, oo.celltype(2,6)
|
263
|
-
end
|
263
|
+
end
|
264
264
|
end
|
265
265
|
|
266
266
|
def test_cell_address
|
@@ -285,12 +285,13 @@ class TestRoo < Test::Unit::TestCase
|
|
285
285
|
def test_office_version
|
286
286
|
with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
|
287
287
|
assert_equal "1.0", oo.officeversion
|
288
|
-
end
|
288
|
+
end
|
289
289
|
end
|
290
290
|
|
291
291
|
#TODO: inkonsequente Lieferung Fixnum/Float
|
292
292
|
def test_rows
|
293
293
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
294
|
+
oo.default_sheet = oo.sheets.first
|
294
295
|
assert_equal 41, oo.cell('a',12)
|
295
296
|
assert_equal 42, oo.cell('b',12)
|
296
297
|
assert_equal 43, oo.cell('c',12)
|
@@ -308,36 +309,42 @@ class TestRoo < Test::Unit::TestCase
|
|
308
309
|
|
309
310
|
def test_last_row
|
310
311
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
312
|
+
oo.default_sheet = oo.sheets.first
|
311
313
|
assert_equal 18, oo.last_row
|
312
314
|
end
|
313
315
|
end
|
314
316
|
|
315
317
|
def test_last_column
|
316
318
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
319
|
+
oo.default_sheet = oo.sheets.first
|
317
320
|
assert_equal 7, oo.last_column
|
318
321
|
end
|
319
322
|
end
|
320
323
|
|
321
324
|
def test_last_column_as_letter
|
322
325
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
326
|
+
oo.default_sheet = oo.sheets.first
|
323
327
|
assert_equal 'G', oo.last_column_as_letter
|
324
328
|
end
|
325
329
|
end
|
326
330
|
|
327
331
|
def test_first_row
|
328
332
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
333
|
+
oo.default_sheet = oo.sheets.first
|
329
334
|
assert_equal 1, oo.first_row
|
330
335
|
end
|
331
336
|
end
|
332
337
|
|
333
338
|
def test_first_column
|
334
339
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
340
|
+
oo.default_sheet = oo.sheets.first
|
335
341
|
assert_equal 1, oo.first_column
|
336
342
|
end
|
337
343
|
end
|
338
344
|
|
339
345
|
def test_first_column_as_letter
|
340
346
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
347
|
+
oo.default_sheet = oo.sheets.first
|
341
348
|
assert_equal 'A', oo.first_column_as_letter
|
342
349
|
end
|
343
350
|
end
|
@@ -354,15 +361,19 @@ class TestRoo < Test::Unit::TestCase
|
|
354
361
|
if oo.class == Excel
|
355
362
|
assert_raise(RuntimeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
|
356
363
|
assert_raise(RuntimeError) { dummy = oo.formula('C',5,"non existing sheet name")}
|
357
|
-
else
|
364
|
+
else
|
358
365
|
assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
|
359
366
|
assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
|
360
|
-
|
361
|
-
|
367
|
+
begin
|
368
|
+
assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")} unless oo.class == Google
|
369
|
+
rescue NameError
|
370
|
+
#
|
371
|
+
end
|
372
|
+
assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
|
362
373
|
end
|
363
374
|
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
|
364
375
|
end
|
365
|
-
end
|
376
|
+
end
|
366
377
|
|
367
378
|
def test_boundaries
|
368
379
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
@@ -395,13 +406,14 @@ class TestRoo < Test::Unit::TestCase
|
|
395
406
|
def test_empty_eh
|
396
407
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
397
408
|
assert oo.empty?('a',14)
|
398
|
-
assert !oo.empty?('a',15)
|
409
|
+
assert ! oo.empty?('a',15)
|
399
410
|
assert oo.empty?('a',20)
|
400
411
|
end
|
401
412
|
end
|
402
413
|
|
403
414
|
def test_reload
|
404
415
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
416
|
+
oo.default_sheet = oo.sheets.first
|
405
417
|
assert_equal 1, oo.cell(1,1)
|
406
418
|
oo.reload
|
407
419
|
assert_equal 1, oo.cell(1,1)
|
@@ -512,6 +524,7 @@ class TestRoo < Test::Unit::TestCase
|
|
512
524
|
|
513
525
|
def test_formula_google
|
514
526
|
with_each_spreadsheet(:name=>'formula', :format=>:google) do |oo|
|
527
|
+
oo.default_sheet = oo.sheets.first
|
515
528
|
assert_equal 1, oo.cell('A',1)
|
516
529
|
assert_equal 2, oo.cell('A',2)
|
517
530
|
assert_equal 3, oo.cell('A',3)
|
@@ -619,6 +632,7 @@ class TestRoo < Test::Unit::TestCase
|
|
619
632
|
|
620
633
|
def test_to_yaml
|
621
634
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
635
|
+
oo.default_sheet = oo.sheets.first
|
622
636
|
assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
|
623
637
|
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
|
624
638
|
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
|
@@ -659,9 +673,9 @@ class TestRoo < Test::Unit::TestCase
|
|
659
673
|
excel = Excel.new(url, :zip)
|
660
674
|
excel.default_sheet = excel.sheets.first
|
661
675
|
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
|
662
|
-
ensure
|
676
|
+
ensure
|
663
677
|
excel.remove_tmp
|
664
|
-
end
|
678
|
+
end
|
665
679
|
end
|
666
680
|
end
|
667
681
|
end
|
@@ -676,7 +690,7 @@ class TestRoo < Test::Unit::TestCase
|
|
676
690
|
assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
|
677
691
|
ensure
|
678
692
|
sheet.remove_tmp
|
679
|
-
end
|
693
|
+
end
|
680
694
|
end
|
681
695
|
end
|
682
696
|
end
|
@@ -688,8 +702,8 @@ class TestRoo < Test::Unit::TestCase
|
|
688
702
|
assert oo
|
689
703
|
assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
|
690
704
|
ensure
|
691
|
-
oo.remove_tmp
|
692
|
-
end
|
705
|
+
oo.remove_tmp if oo
|
706
|
+
end
|
693
707
|
end
|
694
708
|
end
|
695
709
|
|
@@ -699,9 +713,9 @@ class TestRoo < Test::Unit::TestCase
|
|
699
713
|
oo = Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
|
700
714
|
assert oo
|
701
715
|
assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
|
702
|
-
ensure
|
716
|
+
ensure
|
703
717
|
oo.remove_tmp
|
704
|
-
end
|
718
|
+
end
|
705
719
|
end
|
706
720
|
end
|
707
721
|
|
@@ -761,21 +775,25 @@ class TestRoo < Test::Unit::TestCase
|
|
761
775
|
# assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
|
762
776
|
#end
|
763
777
|
end
|
764
|
-
|
778
|
+
|
765
779
|
def test_huge_document_to_csv
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
780
|
+
after Date.new(2009,10,1) do
|
781
|
+
if LONG_RUN
|
782
|
+
with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
|
783
|
+
:excel,
|
784
|
+
:excelx]) do |oo|
|
785
|
+
assert_nothing_raised(Timeout::Error) {
|
786
|
+
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
|
787
|
+
File.delete_if_exist("/tmp/Bibelbund.csv")
|
788
|
+
assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
|
789
|
+
assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
|
790
|
+
assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
|
791
|
+
assert oo.to_csv("/tmp/Bibelbund.csv")
|
792
|
+
assert File.exists?("/tmp/Bibelbund.csv")
|
793
|
+
assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`, "error in class #{oo.class}"
|
794
|
+
end
|
795
|
+
}
|
796
|
+
end
|
779
797
|
end
|
780
798
|
end
|
781
799
|
end
|
@@ -790,7 +808,7 @@ class TestRoo < Test::Unit::TestCase
|
|
790
808
|
assert oo.to_csv("/tmp/numbers1.csv")
|
791
809
|
assert File.exists?("/tmp/numbers1.csv")
|
792
810
|
assert_equal "", `diff #{master} /tmp/numbers1.csv`
|
793
|
-
end
|
811
|
+
end
|
794
812
|
end
|
795
813
|
|
796
814
|
def test_bug_mehrere_datum
|
@@ -826,7 +844,7 @@ class TestRoo < Test::Unit::TestCase
|
|
826
844
|
assert_equal "ABC", oo.cell('C',6)
|
827
845
|
assert_equal "ABC", oo.cell('D',6)
|
828
846
|
assert_equal "ABC", oo.cell('E',6)
|
829
|
-
end
|
847
|
+
end
|
830
848
|
end
|
831
849
|
|
832
850
|
def test_multiple_sheets
|
@@ -883,7 +901,9 @@ class TestRoo < Test::Unit::TestCase
|
|
883
901
|
|
884
902
|
def test_find_by_row_huge_document
|
885
903
|
if LONG_RUN
|
886
|
-
with_each_spreadsheet(:name=>'Bibelbund'
|
904
|
+
with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
|
905
|
+
:excel,
|
906
|
+
:excelx]) do |oo|
|
887
907
|
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
|
888
908
|
oo.default_sheet = oo.sheets.first
|
889
909
|
rec = oo.find 20
|
@@ -917,7 +937,9 @@ class TestRoo < Test::Unit::TestCase
|
|
917
937
|
|
918
938
|
def test_find_by_conditions
|
919
939
|
if LONG_RUN
|
920
|
-
with_each_spreadsheet(:name=>'Bibelbund'
|
940
|
+
with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
|
941
|
+
:excel,
|
942
|
+
:excelx]) do |oo|
|
921
943
|
assert_nothing_raised(Timeout::Error) {
|
922
944
|
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
|
923
945
|
#-----------------------------------------------------------------
|
@@ -1012,6 +1034,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1012
1034
|
with_each_spreadsheet(:name=>'Bibelbund', :format=>:excelx) do |oo|
|
1013
1035
|
assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
|
1014
1036
|
assert_equal '1981-4', oo.cell(13,'D')
|
1037
|
+
assert_equal String, oo.excelx_type(13,'E')[1].class
|
1015
1038
|
assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
|
1016
1039
|
assert_equal '428', oo.excelx_value(13,'E')
|
1017
1040
|
assert_equal 428.0, oo.cell(13,'E')
|
@@ -1028,7 +1051,9 @@ class TestRoo < Test::Unit::TestCase
|
|
1028
1051
|
|
1029
1052
|
def test_column_huge_document
|
1030
1053
|
if LONG_RUN
|
1031
|
-
with_each_spreadsheet(:name=>'Bibelbund'
|
1054
|
+
with_each_spreadsheet(:name=>'Bibelbund', :format=>[:openoffice,
|
1055
|
+
:excel,
|
1056
|
+
:excelx]) do |oo|
|
1032
1057
|
assert_nothing_raised(Timeout::Error) {
|
1033
1058
|
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
|
1034
1059
|
oo.default_sheet = oo.sheets.first
|
@@ -1043,7 +1068,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1043
1068
|
def test_simple_spreadsheet_find_by_condition
|
1044
1069
|
with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
|
1045
1070
|
oo.header_line = 3
|
1046
|
-
oo.date_format = '%m/%d/%Y' if oo.class == Google
|
1071
|
+
# oo.date_format = '%m/%d/%Y' if oo.class == Google
|
1047
1072
|
erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
|
1048
1073
|
assert_equal Date.new(2007,05,07), erg[1]['Date']
|
1049
1074
|
assert_equal 10.75 , erg[1]['Start time']
|
@@ -1054,7 +1079,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1054
1079
|
end
|
1055
1080
|
end
|
1056
1081
|
|
1057
|
-
# Ruby-spreadsheet now allows us to at least give the current value
|
1082
|
+
# Ruby-spreadsheet now allows us to at least give the current value
|
1058
1083
|
# from a cell with a formula (no possible with parseexcel)
|
1059
1084
|
def test_bug_false_borders_with_formulas
|
1060
1085
|
with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
|
@@ -1077,7 +1102,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1077
1102
|
#DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('B',1)
|
1078
1103
|
#DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", oo.formula('B',1)
|
1079
1104
|
|
1080
|
-
assert_kind_of DateTime, oo.cell('C',1)
|
1105
|
+
assert_kind_of DateTime, oo.cell('C',1)
|
1081
1106
|
#DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('C',1)
|
1082
1107
|
#DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", oo.formula('C',1)
|
1083
1108
|
|
@@ -1089,7 +1114,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1089
1114
|
assert_equal 'R2', oo.cell('B',3)
|
1090
1115
|
assert_equal 'R3', oo.cell('C',3)
|
1091
1116
|
assert_equal 'R4', oo.cell('D',3)
|
1092
|
-
end
|
1117
|
+
end
|
1093
1118
|
end
|
1094
1119
|
|
1095
1120
|
def test_excel_does_not_support_formulas
|
@@ -1097,7 +1122,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1097
1122
|
assert_raise(RuntimeError) { void = oo.formula('a',1) }
|
1098
1123
|
assert_raise(RuntimeError) { void = oo.formula?('a',1) }
|
1099
1124
|
assert_raise(RuntimeError) { void = oo.formulas(oo.sheets.first) }
|
1100
|
-
end
|
1125
|
+
end
|
1101
1126
|
end
|
1102
1127
|
|
1103
1128
|
def get_extension(oo)
|
@@ -1108,7 +1133,7 @@ class TestRoo < Test::Unit::TestCase
|
|
1108
1133
|
".xls"
|
1109
1134
|
when Excelx
|
1110
1135
|
".xlsx"
|
1111
|
-
when Google
|
1136
|
+
when Google
|
1112
1137
|
""
|
1113
1138
|
end
|
1114
1139
|
end
|
@@ -1145,10 +1170,14 @@ class TestRoo < Test::Unit::TestCase
|
|
1145
1170
|
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
1146
1171
|
ext = get_extension(oo)
|
1147
1172
|
expected = sprintf(expected_templ,ext)
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1173
|
+
begin
|
1174
|
+
if oo.class == Google
|
1175
|
+
assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
|
1176
|
+
else
|
1177
|
+
assert_equal expected, oo.info
|
1178
|
+
end
|
1179
|
+
rescue NameError
|
1180
|
+
#
|
1152
1181
|
end
|
1153
1182
|
end
|
1154
1183
|
end
|
@@ -1200,17 +1229,17 @@ class TestRoo < Test::Unit::TestCase
|
|
1200
1229
|
}
|
1201
1230
|
end
|
1202
1231
|
if GOOGLE
|
1203
|
-
|
1204
|
-
|
1205
|
-
# oo = Google.new('testnichtvorhanden')
|
1206
|
-
# }
|
1232
|
+
# assert_raise(Net::HTTPServerException) {
|
1233
|
+
# oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
|
1234
|
+
# oo = Google.new('testnichtvorhanden')
|
1235
|
+
# }
|
1207
1236
|
end
|
1208
1237
|
end
|
1209
1238
|
|
1210
1239
|
def test_write_google
|
1211
1240
|
# write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
|
1212
|
-
|
1213
1241
|
with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
|
1242
|
+
oo.default_sheet = oo.sheets.first
|
1214
1243
|
oo.set_value(1,1,"hello from the tests")
|
1215
1244
|
assert_equal "hello from the tests", oo.cell(1,1)
|
1216
1245
|
oo.set_value(1,1, 1.0)
|
@@ -1250,13 +1279,13 @@ class TestRoo < Test::Unit::TestCase
|
|
1250
1279
|
def test_set_value_for_non_existing_sheet_google
|
1251
1280
|
with_each_spreadsheet(:name=>'ptu6bbahNZpY0N0RrxQbWdw', :format=>:google) do |oo|
|
1252
1281
|
assert_raise(RangeError) { oo.set_value(1,1,"dummy","no_sheet") }
|
1253
|
-
end
|
1282
|
+
end
|
1254
1283
|
end
|
1255
1284
|
|
1256
1285
|
def test_bug_bbu
|
1257
1286
|
with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx, :excel]) do |oo|
|
1258
1287
|
assert_nothing_raised() {
|
1259
|
-
|
1288
|
+
assert_equal "File: bbu#{get_extension(oo)}
|
1260
1289
|
Number of sheets: 3
|
1261
1290
|
Sheets: 2007_12, Tabelle2, Tabelle3
|
1262
1291
|
Sheet 1:
|
@@ -1268,14 +1297,14 @@ Sheet 2:
|
|
1268
1297
|
- empty -
|
1269
1298
|
Sheet 3:
|
1270
1299
|
- empty -", oo.info
|
1271
|
-
|
1300
|
+
}
|
1272
1301
|
|
1273
1302
|
oo.default_sheet = oo.sheets[1] # empty sheet
|
1274
1303
|
assert_nil oo.first_row
|
1275
1304
|
assert_nil oo.last_row
|
1276
1305
|
assert_nil oo.first_column
|
1277
1306
|
assert_nil oo.last_column
|
1278
|
-
end
|
1307
|
+
end
|
1279
1308
|
end
|
1280
1309
|
|
1281
1310
|
|
@@ -1298,8 +1327,8 @@ Sheet 3:
|
|
1298
1327
|
assert_equal "", `diff #{TESTDIR}/time-test.csv /tmp/time-test.csv`
|
1299
1328
|
ensure
|
1300
1329
|
File.delete_if_exist("/tmp/time-test.csv")
|
1301
|
-
end
|
1302
|
-
end
|
1330
|
+
end
|
1331
|
+
end
|
1303
1332
|
end
|
1304
1333
|
|
1305
1334
|
def test_date_time_yaml
|
@@ -1355,12 +1384,15 @@ Sheet 3:
|
|
1355
1384
|
end
|
1356
1385
|
|
1357
1386
|
def test_no_remaining_tmp_files_google
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1387
|
+
after Date.new(2009,11,1) do
|
1388
|
+
# Exception ist irgendwie anders, nochmal ansehen TODO:
|
1389
|
+
if GOOGLE
|
1390
|
+
assert_nothing_raised() {
|
1391
|
+
oo = Google.new(key_of("no_spreadsheet_file.txt"))
|
1392
|
+
}
|
1393
|
+
a=Dir.glob("oo_*")
|
1394
|
+
assert_equal [], a
|
1395
|
+
end
|
1364
1396
|
end
|
1365
1397
|
end
|
1366
1398
|
|
@@ -1384,32 +1416,36 @@ Sheet 3:
|
|
1384
1416
|
end
|
1385
1417
|
|
1386
1418
|
def test_to_xml
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
all_cells[x][:
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1419
|
+
after Date.new(2009,10,1) do
|
1420
|
+
with_each_spreadsheet(:name=>'numbers1', :encoding => 'utf8') do |oo|
|
1421
|
+
assert_nothing_raised {oo.to_xml}
|
1422
|
+
sheetname = oo.sheets.first
|
1423
|
+
# doc = XML::Parser.string(oo.to_xml).parse
|
1424
|
+
doc = Nokogiri::XML(oo.to_xml)
|
1425
|
+
# doc.root.each_element {|xml_sheet|
|
1426
|
+
doc.root.each {|xml_sheet|
|
1427
|
+
all_cells = init_all_cells(oo, sheetname)
|
1428
|
+
x = 0
|
1429
|
+
assert_equal sheetname, xml_sheet.attributes['name']
|
1430
|
+
xml_sheet.each_element {|cell|
|
1431
|
+
expected = [all_cells[x][:row],
|
1432
|
+
all_cells[x][:column],
|
1433
|
+
all_cells[x][:content],
|
1434
|
+
all_cells[x][:type],
|
1435
|
+
]
|
1436
|
+
result = [
|
1437
|
+
cell.attributes['row'],
|
1438
|
+
cell.attributes['column'],
|
1439
|
+
cell.content,
|
1440
|
+
cell.attributes['type'],
|
1441
|
+
]
|
1442
|
+
assert_equal expected, result
|
1443
|
+
x += 1
|
1444
|
+
} # end of sheet
|
1445
|
+
sheetname = oo.sheets[oo.sheets.index(sheetname)+1]
|
1446
|
+
}
|
1447
|
+
end
|
1448
|
+
end
|
1413
1449
|
end
|
1414
1450
|
|
1415
1451
|
def test_bug_row_column_fixnum_float
|
@@ -1532,13 +1568,13 @@ Sheet 3:
|
|
1532
1568
|
end
|
1533
1569
|
|
1534
1570
|
def test_bug_last_row_excel
|
1535
|
-
with_each_spreadsheet(:name=>'time-test', :format=>:excel) do |oo|
|
1571
|
+
with_each_spreadsheet(:name=>'time-test', :format=>:excel) do |oo|
|
1536
1572
|
assert_equal 2, oo.last_row
|
1537
1573
|
end
|
1538
1574
|
end
|
1539
1575
|
|
1540
1576
|
def test_bug_to_xml_with_empty_sheets
|
1541
|
-
with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excel]) do |oo|
|
1577
|
+
with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excel]) do |oo|
|
1542
1578
|
oo.sheets.each { |sheet|
|
1543
1579
|
assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
|
1544
1580
|
assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
|
@@ -1556,7 +1592,7 @@ Sheet 3:
|
|
1556
1592
|
def test_bug_simple_spreadsheet_time_bug
|
1557
1593
|
# really a bug? are cells really of type time?
|
1558
1594
|
# No! :float must be the correct type
|
1559
|
-
with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
|
1595
|
+
with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
|
1560
1596
|
# puts oo.cell('B',5).to_s
|
1561
1597
|
# assert_equal :time, oo.celltype('B',5)
|
1562
1598
|
assert_equal :float, oo.celltype('B',5)
|
@@ -1570,39 +1606,41 @@ Sheet 3:
|
|
1570
1606
|
end
|
1571
1607
|
|
1572
1608
|
def test_simple2_excelx
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1609
|
+
after Date.new(2009,10,15) do
|
1610
|
+
with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
|
1611
|
+
assert_equal [:numeric_or_formula, "yyyy\\-mm\\-dd"], oo.excelx_type('A',4)
|
1612
|
+
assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('B',4)
|
1613
|
+
assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('c',4)
|
1614
|
+
assert_equal [:numeric_or_formula, "General"], oo.excelx_type('d',4)
|
1615
|
+
assert_equal [:numeric_or_formula, "General"], oo.excelx_type('e',4)
|
1616
|
+
assert_equal :string, oo.excelx_type('f',4)
|
1617
|
+
|
1618
|
+
assert_equal "39209", oo.excelx_value('a',4)
|
1619
|
+
assert_equal "yyyy\\-mm\\-dd", oo.excelx_format('a',4)
|
1620
|
+
assert_equal "9.25", oo.excelx_value('b',4)
|
1621
|
+
assert_equal "10.25", oo.excelx_value('c',4)
|
1622
|
+
assert_equal "0", oo.excelx_value('d',4)
|
1623
|
+
#... Sum-Spalte
|
1624
|
+
# assert_equal "Task 1", oo.excelx_value('f',4)
|
1625
|
+
assert_equal "Task 1", oo.cell('f',4)
|
1626
|
+
assert_equal Date.new(2007,05,07), oo.cell('a',4)
|
1627
|
+
assert_equal "9.25", oo.excelx_value('b',4)
|
1628
|
+
assert_equal "#,##0.00", oo.excelx_format('b',4)
|
1629
|
+
assert_equal 9.25, oo.cell('b',4)
|
1630
|
+
assert_equal :float, oo.celltype('b',4)
|
1631
|
+
assert_equal :float, oo.celltype('d',4)
|
1632
|
+
assert_equal 0, oo.cell('d',4)
|
1633
|
+
assert_equal :formula, oo.celltype('e',4)
|
1634
|
+
assert_equal 1, oo.cell('e',4)
|
1635
|
+
assert_equal 'C4-B4-D4', oo.formula('e',4)
|
1636
|
+
assert_equal :string, oo.celltype('f',4)
|
1637
|
+
assert_equal "Task 1", oo.cell('f',4)
|
1638
|
+
end
|
1601
1639
|
end
|
1602
1640
|
end
|
1603
1641
|
|
1604
1642
|
def test_datetime
|
1605
|
-
with_each_spreadsheet(:name=>'datetime') do |oo|
|
1643
|
+
with_each_spreadsheet(:name=>'datetime') do |oo|
|
1606
1644
|
val = oo.cell('c',3)
|
1607
1645
|
assert_kind_of DateTime, val
|
1608
1646
|
assert_equal :datetime, oo.celltype('c',3)
|
@@ -1631,38 +1669,43 @@ Sheet 3:
|
|
1631
1669
|
end
|
1632
1670
|
|
1633
1671
|
def test_cell_openoffice_html_escape
|
1634
|
-
with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
|
1672
|
+
with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
|
1635
1673
|
assert_equal "'", oo.cell(1,1)
|
1636
1674
|
assert_equal "&", oo.cell(2,1)
|
1637
1675
|
assert_equal ">", oo.cell(3,1)
|
1638
1676
|
assert_equal "<", oo.cell(4,1)
|
1639
1677
|
assert_equal "`", oo.cell(5,1)
|
1640
1678
|
# test_openoffice_zipped will catch issues with "
|
1641
|
-
end
|
1642
|
-
end
|
1679
|
+
end
|
1680
|
+
end
|
1643
1681
|
|
1644
1682
|
def test_cell_boolean
|
1645
|
-
with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
|
1646
|
-
if oo.class == Excelx
|
1647
|
-
assert_equal "TRUE", oo.cell(1,1)
|
1648
|
-
assert_equal "FALSE", oo.cell(2,1)
|
1683
|
+
with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
|
1684
|
+
if oo.class == Excelx
|
1685
|
+
assert_equal "TRUE", oo.cell(1,1), "failure in "+oo.class.to_s
|
1686
|
+
assert_equal "FALSE", oo.cell(2,1), "failure in "+oo.class.to_s
|
1649
1687
|
else
|
1650
|
-
assert_equal "true", oo.cell(1,1)
|
1651
|
-
assert_equal "false", oo.cell(2,1)
|
1688
|
+
assert_equal "true", oo.cell(1,1), "failure in "+oo.class.to_s
|
1689
|
+
assert_equal "false", oo.cell(2,1), "failure in "+oo.class.to_s
|
1652
1690
|
end
|
1653
1691
|
end
|
1654
1692
|
end
|
1655
1693
|
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1694
|
+
def test_cell_multiline
|
1695
|
+
with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excel, :excelx]) do |oo|
|
1696
|
+
assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
|
1697
|
+
assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
|
1698
|
+
assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
|
1699
|
+
end
|
1700
|
+
end
|
1663
1701
|
|
1664
1702
|
def test_cell_styles
|
1665
|
-
|
1703
|
+
# styles only valid in excel spreadsheets?
|
1704
|
+
# TODO: what todo with other spreadsheet types
|
1705
|
+
with_each_spreadsheet(:name=>'style', :format=>[# :openoffice,
|
1706
|
+
:excel,
|
1707
|
+
# :excelx
|
1708
|
+
]) do |oo|
|
1666
1709
|
# bold
|
1667
1710
|
assert_equal true, oo.font(1,1).bold?
|
1668
1711
|
assert_equal false, oo.font(1,1).italic?
|
@@ -1717,106 +1760,172 @@ Sheet 3:
|
|
1717
1760
|
assert_equal false, oo.font(11,4).bold?
|
1718
1761
|
assert_equal false, oo.font(11,4).italic?
|
1719
1762
|
assert_equal false, oo.font(11,4).underline?
|
1720
|
-
end
|
1763
|
+
end
|
1721
1764
|
end
|
1722
1765
|
|
1723
|
-
# If a cell has a date-like string but is preceeded by a '
|
1766
|
+
# If a cell has a date-like string but is preceeded by a '
|
1724
1767
|
# to force that date to be treated like a string, we were getting an exception.
|
1725
1768
|
# This test just checks for that exception to make sure it's not raised in this case
|
1726
1769
|
def test_date_to_float_conversion
|
1727
|
-
with_each_spreadsheet(:name=>'datetime_floatconv', :format=>:excel) do |oo|
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
end
|
1734
|
-
|
1735
|
-
# Need to extend to other formats
|
1770
|
+
with_each_spreadsheet(:name=>'datetime_floatconv', :format=>:excel) do |oo|
|
1771
|
+
assert_nothing_raised(NoMethodError) do
|
1772
|
+
oo.cell('a',1)
|
1773
|
+
oo.cell('a',2)
|
1774
|
+
end
|
1775
|
+
end
|
1776
|
+
end
|
1777
|
+
|
1778
|
+
# Need to extend to other formats
|
1736
1779
|
def test_row_whitespace
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1780
|
+
# auf dieses Dokument habe ich keinen Zugriff TODO:
|
1781
|
+
after Date.new(2009,11,1) do
|
1782
|
+
with_each_spreadsheet(:name=>'whitespace') do |oo|
|
1783
|
+
oo.default_sheet = "Sheet1"
|
1784
|
+
assert_equal [nil, nil, nil, nil, nil, nil], oo.row(1)
|
1785
|
+
assert_equal [nil, nil, nil, nil, nil, nil], oo.row(2)
|
1786
|
+
assert_equal ["Date", "Start time", "End time", "Pause", "Sum", "Comment"], oo.row(3)
|
1787
|
+
assert_equal [Date.new(2007,5,7), 9.25, 10.25, 0.0, 1.0, "Task 1"], oo.row(4)
|
1788
|
+
assert_equal [nil, nil, nil, nil, nil, nil], oo.row(5)
|
1789
|
+
assert_equal [Date.new(2007,5,7), 10.75, 10.75, 0.0, 0.0, "Task 1"], oo.row(6)
|
1790
|
+
oo.default_sheet = "Sheet2"
|
1791
|
+
assert_equal ["Date", nil, "Start time"], oo.row(1)
|
1792
|
+
assert_equal [Date.new(2007,5,7), nil, 9.25], oo.row(2)
|
1793
|
+
assert_equal [Date.new(2007,5,7), nil, 10.75], oo.row(3)
|
1794
|
+
end
|
1749
1795
|
end
|
1750
1796
|
end
|
1751
1797
|
|
1752
1798
|
def test_col_whitespace
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1799
|
+
after Date.new(2009,11,20) do
|
1800
|
+
#TODO:
|
1801
|
+
# kein Zugriff auf Dokument whitespace
|
1802
|
+
with_each_spreadsheet(:name=>'whitespace') do |oo|
|
1803
|
+
oo.default_sheet = "Sheet1"
|
1804
|
+
assert_equal ["Date", Date.new(2007,5,7), nil, Date.new(2007,5,7)], oo.column(1)
|
1805
|
+
assert_equal ["Start time", 9.25, nil, 10.75], oo.column(2)
|
1806
|
+
assert_equal ["End time", 10.25, nil, 10.75], oo.column(3)
|
1807
|
+
assert_equal ["Pause", 0.0, nil, 0.0], oo.column(4)
|
1808
|
+
assert_equal ["Sum", 1.0, nil, 0.0], oo.column(5)
|
1809
|
+
assert_equal ["Comment","Task 1", nil, "Task 1"], oo.column(6)
|
1810
|
+
oo.default_sheet = "Sheet2"
|
1811
|
+
assert_equal [nil, nil, nil], oo.column(1)
|
1812
|
+
assert_equal [nil, nil, nil], oo.column(2)
|
1813
|
+
assert_equal ["Date", Date.new(2007,5,7), Date.new(2007,5,7)], oo.column(3)
|
1814
|
+
assert_equal [nil, nil, nil], oo.column(4)
|
1815
|
+
assert_equal [ "Start time", 9.25, 10.75], oo.column(5)
|
1816
|
+
end
|
1767
1817
|
end
|
1768
1818
|
end
|
1769
1819
|
|
1770
|
-
|
1771
|
-
def test_ruby_spreadsheet_formula_bug
|
1772
|
-
with_each_spreadsheet(:name=>'formula_parse_error', :format=>:excel) do |oo|
|
1773
|
-
assert_equal '5026', oo.cell(2,3)
|
1774
|
-
assert_equal '5026', oo.cell(3,3)
|
1775
|
-
end
|
1776
|
-
end
|
1777
|
-
|
1778
|
-
|
1779
|
-
# Excel has two base date formats one from 1900 and the other from 1904.
|
1820
|
+
# Excel has two base date formats one from 1900 and the other from 1904.
|
1780
1821
|
# There's a MS bug that 1900 base dates include an extra day due to erroneously
|
1781
|
-
# including 1900 as a leap yar.
|
1822
|
+
# including 1900 as a leap yar.
|
1782
1823
|
def test_base_dates_in_excel
|
1783
|
-
with_each_spreadsheet(:name=>'1900_base', :format=>:excel) do |oo|
|
1824
|
+
with_each_spreadsheet(:name=>'1900_base', :format=>:excel) do |oo|
|
1784
1825
|
assert_equal Date.new(2009,06,15), oo.cell(1,1)
|
1785
|
-
assert_equal Date.new(
|
1826
|
+
#we don't want to to 'interpret' formulas assert_equal Date.new(Time.now.year,Time.now.month,Time.now.day), oo.cell(2,1) #formula for TODAY()
|
1827
|
+
# if we test TODAY() we have also have to calculate
|
1828
|
+
# other date calculations
|
1829
|
+
#
|
1786
1830
|
assert_equal :date, oo.celltype(1,1)
|
1787
|
-
end
|
1788
|
-
with_each_spreadsheet(:name=>'1904_base', :format=>:excel) do |oo|
|
1831
|
+
end
|
1832
|
+
with_each_spreadsheet(:name=>'1904_base', :format=>:excel) do |oo|
|
1789
1833
|
assert_equal Date.new(2009,06,15), oo.cell(1,1)
|
1790
|
-
|
1834
|
+
# see comment above
|
1835
|
+
# assert_equal Date.new(Time.now.year,Time.now.month,Time.now.day), oo.cell(2,1) #formula for TODAY()
|
1791
1836
|
assert_equal :date, oo.celltype(1,1)
|
1792
|
-
end
|
1837
|
+
end
|
1793
1838
|
end
|
1794
1839
|
|
1795
|
-
|
1796
|
-
|
1797
|
-
with_each_spreadsheet(:name=>'bad_exceL_date', :format=>:excel) do |oo|
|
1840
|
+
def test_bad_date
|
1841
|
+
with_each_spreadsheet(:name=>'prova', :format=>:excel) do |oo|
|
1798
1842
|
assert_nothing_raised(ArgumentError) {
|
1799
1843
|
assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
|
1800
1844
|
}
|
1845
|
+
end # each
|
1846
|
+
end
|
1847
|
+
|
1848
|
+
def test_cell_methods
|
1849
|
+
with_each_spreadsheet(:name=>'numbers1') do |oo|
|
1850
|
+
assert_equal 10, oo.a4 # cell(4,'A')
|
1851
|
+
assert_equal 11, oo.b4 # cell(4,'B')
|
1852
|
+
assert_equal 12, oo.c4 # cell(4,'C')
|
1853
|
+
assert_equal 13, oo.d4 # cell(4,'D')
|
1854
|
+
assert_equal 14, oo.e4 # cell(4,'E')
|
1855
|
+
assert_equal 'ABC', oo.c6('Sheet5')
|
1856
|
+
|
1857
|
+
assert_raises(ArgumentError) {
|
1858
|
+
# a42a is not a valid cell name, should raise ArgumentError
|
1859
|
+
assert_equal 9999, oo.a42a
|
1860
|
+
}
|
1861
|
+
end
|
1862
|
+
|
1863
|
+
end
|
1864
|
+
|
1865
|
+
|
1866
|
+
# compare large spreadsheets
|
1867
|
+
def test_compare_large_spreadsheets
|
1868
|
+
after Date.new(2009,11,1) do
|
1869
|
+
# problematisch, weil Formeln in Excel nicht unterstützt werden
|
1870
|
+
if LONG_RUN
|
1871
|
+
qq = Openoffice.new(File.join('test',"Bibelbund.ods"))
|
1872
|
+
with_each_spreadsheet(:name=>'Bibelbund') do |oo|
|
1873
|
+
# p "comparing Bibelbund.ods with #{oo.class}"
|
1874
|
+
oo.sheets.each do |sh|
|
1875
|
+
oo.first_row.upto(oo.last_row) do |row|
|
1876
|
+
oo.first_column.upto(oo.last_column) do |col|
|
1877
|
+
c1 = qq.cell(row,col,sh)
|
1878
|
+
c1.force_encoding("UTF-8") if c1.class == String
|
1879
|
+
c2 = oo.cell(row,col,sh)
|
1880
|
+
c2.force_encoding("UTF-8") if c2.class == String
|
1881
|
+
assert_equal c1, c2, "diff in #{sh}/#{row}/#{col}}"
|
1882
|
+
assert_equal qq.celltype(row,col,sh), oo.celltype(row,col,sh)
|
1883
|
+
assert_equal qq.formula?(row,col,sh), oo.formula?(row,col,sh)
|
1884
|
+
end
|
1885
|
+
end
|
1886
|
+
end
|
1887
|
+
end
|
1888
|
+
end # LONG_RUN
|
1889
|
+
end
|
1890
|
+
end
|
1891
|
+
|
1892
|
+
def test_labeled_cells
|
1893
|
+
# TODO: more spreadsheet types
|
1894
|
+
with_each_spreadsheet(:name=>'named_cells', :format=>:openoffice) do |oo|
|
1895
|
+
oo.default_sheet = oo.sheets.first
|
1896
|
+
begin
|
1897
|
+
row,col = oo.label('anton')
|
1898
|
+
rescue ArgumentError
|
1899
|
+
puts "labels error at #{oo.class}"
|
1900
|
+
raise
|
1901
|
+
end
|
1902
|
+
assert_equal 5, row
|
1903
|
+
assert_equal 3, col
|
1904
|
+
|
1905
|
+
row,col = oo.label('anton')
|
1906
|
+
assert_equal 'Anton', oo.cell(row,col)
|
1907
|
+
|
1908
|
+
row,col = oo.label('berta')
|
1909
|
+
assert_equal 'Bertha', oo.cell(row,col)
|
1910
|
+
|
1911
|
+
row,col = oo.label('caesar')
|
1912
|
+
assert_equal 'Cäsar', oo.cell(row,col)
|
1913
|
+
|
1914
|
+
# a not defined label:
|
1915
|
+
row,col = oo.label('never')
|
1916
|
+
assert_nil row
|
1917
|
+
assert_nil col
|
1918
|
+
|
1919
|
+
row,col,sheet = oo.label('anton')
|
1920
|
+
assert_equal 5, row
|
1921
|
+
assert_equal 3, col
|
1922
|
+
assert_equal "Sheet1", sheet
|
1923
|
+
#
|
1924
|
+
# assert_equal "Anton", oo.label('anton')
|
1925
|
+
after Date.new(2009,12,12) do
|
1926
|
+
assert_equal "Anton", oo.anton
|
1927
|
+
end
|
1801
1928
|
end
|
1802
1929
|
end
|
1803
1930
|
|
1804
|
-
def test_public_google_doc
|
1805
|
-
with_public_google_spreadsheet do
|
1806
|
-
assert_raise(GoogleHTTPError) { Google.new("foo") }
|
1807
|
-
assert_raise(GoogleReadError) { Google.new(key_of('numbers1'))}
|
1808
|
-
assert_nothing_raised { Google.new("0AncOJVyN5MMMcjZtN0hGbFVPd3N0MFJUVVR1aFEwT3c") } # use spreadsheet key (private)
|
1809
|
-
assert_nothing_raised { Google.new(key_of('write.me')) } # use spreadsheet key (public)
|
1810
|
-
end
|
1811
|
-
end
|
1812
|
-
|
1813
|
-
def test_public_google_doc_write
|
1814
|
-
with_public_google_spreadsheet do
|
1815
|
-
assert_raise(GoogleWriteError) {
|
1816
|
-
oo = Google.new(key_of('write.me'))
|
1817
|
-
oo.set_value(1,1,'test')
|
1818
|
-
}
|
1819
|
-
end
|
1820
|
-
end
|
1821
|
-
|
1822
1931
|
end # class
|