roo-google 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +17 -0
- data/.simplecov +4 -0
- data/.travis.yml +12 -0
- data/Gemfile +32 -0
- data/Guardfile +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +23 -0
- data/defaults.reek +11 -0
- data/lib/roo-google.rb +6 -0
- data/lib/roo/google.rb +244 -0
- data/lib/roo/google/version.rb +3 -0
- data/roo-google.gemspec +26 -0
- data/spec/fixtures/vcr_cassettes/google_drive.yml +165 -0
- data/spec/fixtures/vcr_cassettes/google_drive_access_token.yml +73 -0
- data/spec/fixtures/vcr_cassettes/google_drive_numbers1.yml +31552 -0
- data/spec/fixtures/vcr_cassettes/google_drive_set.yml +2430 -0
- data/spec/fixtures/vcr_cassettes/gsubjectgle_drive_set.yml +504 -0
- data/spec/lib/roo/google_spec.rb +113 -0
- data/spec/spec_helper.rb +8 -0
- data/test/test_helper.rb +134 -0
- data/test/test_roo_google.rb +361 -0
- metadata +142 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Roo::Google do
|
4
|
+
def key_of(spreadsheetname)
|
5
|
+
{
|
6
|
+
'write.me' => '0AvDjm7u2fQg_dEZOc0Z0bU1CeWEtYUZOOVdtTkoxaEE',
|
7
|
+
'numbers1' => '0AvDjm7u2fQg_dGJLQnhqMUJlYTNzSGh3cF95NWRlQUE',
|
8
|
+
'matrix' => '0AvDjm7u2fQg_dFF0bDVQbXN0dTd5eHpqcG4tckR1M2c'
|
9
|
+
}[spreadsheetname]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:access_token) { 'ya29.UAG8d0gmCfJrTzgwQdWTHqG7fDoilKh-aJDSBAmVdre1CDfUHz0ouOwANUVVDnyWVZKSGa_EBUYZqw' }
|
13
|
+
let(:key) { '0AvDjm7u2fQg_dGs2Qm5XQno3WDFVUnJsMG5KWXVZZnc' }
|
14
|
+
subject { described_class.new(key, access_token: access_token) }
|
15
|
+
|
16
|
+
context '.new' do
|
17
|
+
context 'given an access token' do
|
18
|
+
|
19
|
+
subject {
|
20
|
+
described_class.new(key, access_token: access_token)
|
21
|
+
}
|
22
|
+
|
23
|
+
it 'creates an instance' do
|
24
|
+
VCR.use_cassette('google_drive_access_token') do
|
25
|
+
expect(subject).to be_a(described_class)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.set' do
|
32
|
+
let(:key) { '0AvDjm7u2fQg_dGs2Qm5XQno3WDFVUnJsMG5KWXVZZnc' }
|
33
|
+
|
34
|
+
it 'records the value' do
|
35
|
+
VCR.use_cassette('google_drive_set') do
|
36
|
+
expect(subject.cell(1, 1)).to eq('1x1')
|
37
|
+
expect(subject.cell(1, 2)).to eq('1x2')
|
38
|
+
expect(subject.cell(2, 1)).to eq('2x1')
|
39
|
+
expect(subject.cell(2, 2)).to eq('2x2')
|
40
|
+
subject.set(1, 1, '1x1')
|
41
|
+
subject.set(1, 2, '1x2')
|
42
|
+
subject.set(2, 1, '2x1')
|
43
|
+
subject.set(2, 2, '2x2')
|
44
|
+
expect(subject.cell(1, 1)).to eq('1x1')
|
45
|
+
expect(subject.cell(1, 2)).to eq('1x2')
|
46
|
+
expect(subject.cell(2, 1)).to eq('2x1')
|
47
|
+
expect(subject.cell(2, 2)).to eq('2x2')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context '#date?' do
|
53
|
+
{
|
54
|
+
'DDMMYYYY' => { format: nil, values: ['21/11/1962', '11/21/1962'] },
|
55
|
+
'MMDDYYYY' => { format: '%m/%d/%Y', values: ['11/21/1962', '21/11/1962'] },
|
56
|
+
'YYYYMMDD' => { format: '%Y-%m-%d', values: ['1962-11-21', '1962-21-11'] }
|
57
|
+
}.each do |title, data|
|
58
|
+
context title do
|
59
|
+
before :each do
|
60
|
+
subject.date_format = data[:format] if data[:format]
|
61
|
+
end
|
62
|
+
it "should accept #{data[:values][0]}" do
|
63
|
+
expect(subject.date?(data[:values][0])).to be_truthy
|
64
|
+
end
|
65
|
+
it "should not accept #{data[:values][1]}" do
|
66
|
+
expect(subject.date?(data[:values][1])).to be_falsey
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'numbers1 document' do
|
73
|
+
before :all do
|
74
|
+
VCR.insert_cassette('google_drive_numbers1')
|
75
|
+
end
|
76
|
+
let(:key) { key_of('numbers1') }
|
77
|
+
it 'check date fields' do
|
78
|
+
expect(subject.celltype(5,1)).to eq(:date)
|
79
|
+
expect(subject.cell(5,1)).to eq(Date.new(1961, 11, 21))
|
80
|
+
expect(subject.cell(5,1).to_s).to eq('1961-11-21')
|
81
|
+
end
|
82
|
+
it 'check datetime fields' do
|
83
|
+
expect(subject.celltype(18,3)).to eq(:datetime)
|
84
|
+
expect(subject.cell(18,3)).to eq(DateTime.new(2014, 12, 12, 12, 12, 0))
|
85
|
+
end
|
86
|
+
it 'check time fields' do
|
87
|
+
# 13:46:12
|
88
|
+
expect(subject.celltype(18,4)).to eq(:time)
|
89
|
+
expect(subject.cell(18,4)).to eq(49572)
|
90
|
+
end
|
91
|
+
it 'should check float' do
|
92
|
+
expect(subject.celltype(2,7)).to eq(:float)
|
93
|
+
end
|
94
|
+
it 'should check string' do
|
95
|
+
expect(subject.celltype(2,6)).to eq(:string)
|
96
|
+
expect(subject.cell(2,6)).to eq('test')
|
97
|
+
end
|
98
|
+
it 'should check formula' do
|
99
|
+
expect(subject.celltype(1,'F')).to eq(:formula)
|
100
|
+
expect(subject.cell(1,'F')).to eq(20)
|
101
|
+
expect(subject.formula(1,'F')).to eq('=SUM(RC[-5]:RC[-1])')
|
102
|
+
end
|
103
|
+
it 'check empty?' do
|
104
|
+
expect(subject.empty?(2,7)).to be_falsey
|
105
|
+
expect(subject.empty?(2,6)).to be_falsey
|
106
|
+
expect(subject.empty?(18,4)).to be_falsey
|
107
|
+
expect(subject.empty?(18,5)).to be_truthy
|
108
|
+
end
|
109
|
+
after :all do
|
110
|
+
VCR.eject_cassette('google_drive_numbers1')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
# require deps
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'shoulda'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'timeout'
|
9
|
+
require 'logger'
|
10
|
+
require 'date'
|
11
|
+
require 'webmock/minitest'
|
12
|
+
|
13
|
+
# require gem files
|
14
|
+
require 'roo-google'
|
15
|
+
|
16
|
+
TESTDIR = File.join(File.dirname(__FILE__), 'files')
|
17
|
+
|
18
|
+
# very simple diff implementation
|
19
|
+
# output is an empty string if the files are equal
|
20
|
+
# otherwise differences a printen (not compatible to
|
21
|
+
# the diff command)
|
22
|
+
def file_diff(fn1, fn2)
|
23
|
+
result = ''
|
24
|
+
File.open(fn1) do |f1|
|
25
|
+
File.open(fn2) do |f2|
|
26
|
+
while f1.eof? == false && f2.eof? == false
|
27
|
+
line1 = f1.gets.chomp
|
28
|
+
line2 = f2.gets.chomp
|
29
|
+
result << "<#{line1}\n>#{line2}\n" if line1 != line2
|
30
|
+
end
|
31
|
+
if f1.eof? == false
|
32
|
+
while f1.eof? == false
|
33
|
+
line1 = f1.gets
|
34
|
+
result << "<#{line1}\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
if f2.eof? == false
|
38
|
+
while f2.eof? == false
|
39
|
+
line2 = f2.gets
|
40
|
+
result << ">#{line2}\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def with_each_spreadsheet(name)
|
49
|
+
yield ::Roo::Spreadsheet.open(File.join(TESTDIR, key_of(name)), extension: :google)
|
50
|
+
end
|
51
|
+
|
52
|
+
def key_of(spreadsheetname)
|
53
|
+
{
|
54
|
+
# 'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
|
55
|
+
'formula' => 'o10837434939102457526.3022866619437760118',
|
56
|
+
# "write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
|
57
|
+
'write.me' => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
|
58
|
+
# 'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
|
59
|
+
'numbers1' => 'o10837434939102457526.4784396906364855777',
|
60
|
+
# 'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
|
61
|
+
'borders' => 'o10837434939102457526.664868920231926255',
|
62
|
+
# 'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
|
63
|
+
'simple_spreadsheet' => 'ptu6bbahNZpYe-L1vEBmgGA',
|
64
|
+
'testnichtvorhandenBibelbund.ods' => 'invalidkeyforanyspreadsheet', # !!! intentionally false key
|
65
|
+
# "only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
|
66
|
+
'only_one_sheet' => 'o10837434939102457526.762705759906130135',
|
67
|
+
# 'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
|
68
|
+
'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
69
|
+
# 'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
|
70
|
+
'datetime' => 'ptu6bbahNZpYQEtZwzL_dZQ',
|
71
|
+
'whitespace' => 'rZyQaoFebVGeHKzjG6e9gRQ',
|
72
|
+
'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
|
73
|
+
# 'numbers1' => "o10837434939102457526.4784396906364855777",
|
74
|
+
# 'borders' => "o10837434939102457526.664868920231926255",
|
75
|
+
# 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
76
|
+
# 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
|
77
|
+
# "only_one_sheet" => "o10837434939102457526.762705759906130135",
|
78
|
+
# "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
|
79
|
+
# 'formula' => 'o10837434939102457526.3022866619437760118',
|
80
|
+
# 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
81
|
+
# 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
82
|
+
}.fetch(spreadsheetname)
|
83
|
+
rescue KeyError
|
84
|
+
raise "unknown spreadsheetname: #{spreadsheetname}"
|
85
|
+
end
|
86
|
+
|
87
|
+
class File
|
88
|
+
def self.delete_if_exist(filename)
|
89
|
+
if File.exist?(filename)
|
90
|
+
File.delete(filename)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# class Test::Unit::TestCase
|
96
|
+
# def key_of(spreadsheetname)
|
97
|
+
# {
|
98
|
+
# #'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
|
99
|
+
# 'formula' => 'o10837434939102457526.3022866619437760118',
|
100
|
+
# #"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
|
101
|
+
# "write.me" => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
|
102
|
+
# #'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
|
103
|
+
# 'numbers1' => 'o10837434939102457526.4784396906364855777',
|
104
|
+
# #'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
|
105
|
+
# 'borders' => "o10837434939102457526.664868920231926255",
|
106
|
+
# #'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
|
107
|
+
# 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
108
|
+
# 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
|
109
|
+
# #"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
|
110
|
+
# "only_one_sheet" => "o10837434939102457526.762705759906130135",
|
111
|
+
# #'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
|
112
|
+
# 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
113
|
+
# #'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
|
114
|
+
# 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
115
|
+
# 'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ",
|
116
|
+
# 'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
|
117
|
+
# # 'numbers1' => "o10837434939102457526.4784396906364855777",
|
118
|
+
# # 'borders' => "o10837434939102457526.664868920231926255",
|
119
|
+
# # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
|
120
|
+
# # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
|
121
|
+
# # "only_one_sheet" => "o10837434939102457526.762705759906130135",
|
122
|
+
# # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
|
123
|
+
# # 'formula' => 'o10837434939102457526.3022866619437760118',
|
124
|
+
# # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
|
125
|
+
# # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
|
126
|
+
# }.fetch(spreadsheetname)
|
127
|
+
# rescue KeyError
|
128
|
+
# raise "unknown spreadsheetname: #{spreadsheetname}"
|
129
|
+
# end
|
130
|
+
|
131
|
+
# def yaml_entry(row,col,type,value)
|
132
|
+
# "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
|
133
|
+
# end
|
134
|
+
# end
|
@@ -0,0 +1,361 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRooGoogle < MiniTest::Test
|
4
|
+
def test_simple_google
|
5
|
+
go = Roo::Google.new('egal')
|
6
|
+
assert_equal '42', go.cell(1, 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_formula_google
|
10
|
+
with_each_spreadsheet('formula') do |oo|
|
11
|
+
oo.default_sheet = oo.sheets.first
|
12
|
+
assert_equal 1, oo.cell('A', 1)
|
13
|
+
assert_equal 2, oo.cell('A', 2)
|
14
|
+
assert_equal 3, oo.cell('A', 3)
|
15
|
+
assert_equal 4, oo.cell('A', 4)
|
16
|
+
assert_equal 5, oo.cell('A', 5)
|
17
|
+
assert_equal 6, oo.cell('A', 6)
|
18
|
+
# assert_equal 21, oo.cell('A',7)
|
19
|
+
assert_equal 21.0, oo.cell('A', 7) # TODO: better solution Fixnum/Float
|
20
|
+
assert_equal :formula, oo.celltype('A', 7)
|
21
|
+
# assert_equal "=[Sheet2.A1]", oo.formula('C',7)
|
22
|
+
# !!! different from formulas in OpenOffice
|
23
|
+
# was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
|
24
|
+
# has Google changed their format of formulas/references to other sheets?
|
25
|
+
assert_equal '=Sheet2!R[-6]C[-2]', oo.formula('C', 7)
|
26
|
+
assert_nil oo.formula('A', 6)
|
27
|
+
# assert_equal [[7, 1, "=SUM([.A1:.A6])"],
|
28
|
+
# [7, 2, "=SUM([.$A$1:.B6])"],
|
29
|
+
# [7, 3, "=[Sheet2.A1]"],
|
30
|
+
# [8, 2, "=SUM([.$A$1:.B7])"],
|
31
|
+
# ], oo.formulas(oo.sheets.first)
|
32
|
+
# different format than in openoffice spreadsheets:
|
33
|
+
# was:
|
34
|
+
# assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
|
35
|
+
# [7, 2, "=SUM(R1C1:R[-1]C[0])"],
|
36
|
+
# [7, 3, "=sheet2!R[-6]C[-2]"],
|
37
|
+
# [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
|
38
|
+
# oo.formulas(oo.sheets.first)
|
39
|
+
assert_equal [[7, 1, '=SUM(R[-6]C:R[-1]C)'],
|
40
|
+
[7, 2, '=SUM(R1C1:R[-1]C)'],
|
41
|
+
[7, 3, '=Sheet2!R[-6]C[-2]'],
|
42
|
+
[8, 2, '=SUM(R1C1:R[-1]C)']],
|
43
|
+
oo.formulas(oo.sheets.first)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_write_google
|
48
|
+
# write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
|
49
|
+
with_each_spreadsheet('write.me') do |oo|
|
50
|
+
oo.default_sheet = oo.sheets.first
|
51
|
+
oo.set(1, 1, 'hello from the tests')
|
52
|
+
assert_equal 'hello from the tests', oo.cell(1, 1)
|
53
|
+
oo.set(1, 1, 1.0)
|
54
|
+
assert_equal 1.0, oo.cell(1, 1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_bug_set_with_more_than_one_sheet_google
|
59
|
+
# write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
|
60
|
+
with_each_spreadsheet('write.me') do |oo|
|
61
|
+
content1 = 'AAA'
|
62
|
+
content2 = 'BBB'
|
63
|
+
oo.default_sheet = oo.sheets.first
|
64
|
+
oo.set(1, 1, content1)
|
65
|
+
oo.default_sheet = oo.sheets[1]
|
66
|
+
oo.set(1, 1, content2) # in the second sheet
|
67
|
+
oo.default_sheet = oo.sheets.first
|
68
|
+
assert_equal content1, oo.cell(1, 1)
|
69
|
+
oo.default_sheet = oo.sheets[1]
|
70
|
+
assert_equal content2, oo.cell(1, 1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_set_with_sheet_argument_google
|
75
|
+
with_each_spreadsheet('write.me') do |oo|
|
76
|
+
random_row = rand(10) + 1
|
77
|
+
random_column = rand(10) + 1
|
78
|
+
content1 = 'ABC'
|
79
|
+
content2 = 'DEF'
|
80
|
+
oo.set(random_row, random_column, content1, oo.sheets.first)
|
81
|
+
oo.set(random_row, random_column, content2, oo.sheets[1])
|
82
|
+
assert_equal content1, oo.cell(random_row, random_column, oo.sheets.first)
|
83
|
+
assert_equal content2, oo.cell(random_row, random_column, oo.sheets[1])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_set_for_non_existing_sheet_google
|
88
|
+
with_each_spreadsheet('ptu6bbahNZpY0N0RrxQbWdw') do |oo|
|
89
|
+
assert_raises(RangeError) { oo.set(1, 1, 'dummy', 'no_sheet') }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
require 'matrix'
|
94
|
+
def test_matrix
|
95
|
+
with_each_spreadsheet('matrix') do |oo|
|
96
|
+
oo.default_sheet = oo.sheets.first
|
97
|
+
assert_equal Matrix[
|
98
|
+
[1.0, 2.0, 3.0],
|
99
|
+
[4.0, 5.0, 6.0],
|
100
|
+
[7.0, 8.0, 9.0]], oo.to_matrix
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_matrix_selected_range
|
105
|
+
with_each_spreadsheet('matrix') do |oo|
|
106
|
+
oo.default_sheet = 'Sheet2'
|
107
|
+
assert_equal Matrix[
|
108
|
+
[1.0, 2.0, 3.0],
|
109
|
+
[4.0, 5.0, 6.0],
|
110
|
+
[7.0, 8.0, 9.0]], oo.to_matrix(3, 4, 5, 6)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_matrix_all_nil
|
115
|
+
with_each_spreadsheet('matrix') do |oo|
|
116
|
+
oo.default_sheet = 'Sheet2'
|
117
|
+
assert_equal Matrix[
|
118
|
+
[nil, nil, nil],
|
119
|
+
[nil, nil, nil],
|
120
|
+
[nil, nil, nil]], oo.to_matrix(10, 10, 12, 12)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_matrix_values_and_nil
|
125
|
+
with_each_spreadsheet('matrix') do |oo|
|
126
|
+
oo.default_sheet = 'Sheet3'
|
127
|
+
assert_equal Matrix[
|
128
|
+
[1.0, nil, 3.0],
|
129
|
+
[4.0, 5.0, 6.0],
|
130
|
+
[7.0, 8.0, nil]], oo.to_matrix(1, 1, 3, 3)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_matrix_specifying_sheet
|
135
|
+
with_each_spreadsheet('matrix') do |oo|
|
136
|
+
oo.default_sheet = oo.sheets.first
|
137
|
+
assert_equal Matrix[
|
138
|
+
[1.0, nil, 3.0],
|
139
|
+
[4.0, 5.0, 6.0],
|
140
|
+
[7.0, 8.0, nil]], oo.to_matrix(nil, nil, nil, nil, 'Sheet3')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# #formulas of an empty sheet should return an empty array and not result in
|
145
|
+
# an error message
|
146
|
+
# 2011-06-24
|
147
|
+
def test_bug_formulas_empty_sheet
|
148
|
+
with_each_spreadsheet('emptysheets') do |oo|
|
149
|
+
assert_nothing_raised(NoMethodError) do
|
150
|
+
oo.default_sheet = oo.sheets.first
|
151
|
+
oo.formulas
|
152
|
+
end
|
153
|
+
assert_equal([], oo.formulas)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# #to_yaml of an empty sheet should return an empty string and not result in
|
158
|
+
# an error message
|
159
|
+
# 2011-06-24
|
160
|
+
def test_bug_to_yaml_empty_sheet
|
161
|
+
with_each_spreadsheet('emptysheets') do |oo|
|
162
|
+
assert_nothing_raised(NoMethodError) do
|
163
|
+
oo.default_sheet = oo.sheets.first
|
164
|
+
oo.to_yaml
|
165
|
+
end
|
166
|
+
assert_equal('', oo.to_yaml)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# #to_matrix of an empty sheet should return an empty matrix and not result in
|
171
|
+
# an error message
|
172
|
+
# 2011-06-25
|
173
|
+
def test_bug_to_matrix_empty_sheet
|
174
|
+
with_each_spreadsheet('emptysheets') do |oo|
|
175
|
+
assert_nothing_raised(NoMethodError) do
|
176
|
+
oo.default_sheet = oo.sheets.first
|
177
|
+
oo.to_matrix
|
178
|
+
end
|
179
|
+
assert_equal(Matrix.empty(0, 0), oo.to_matrix)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# 2011-08-03
|
184
|
+
def test_bug_datetime_to_csv
|
185
|
+
with_each_spreadsheet('datetime') do |oo|
|
186
|
+
Dir.mktmpdir do |tempdir|
|
187
|
+
datetime_csv_file = File.join(tempdir, 'datetime.csv')
|
188
|
+
|
189
|
+
assert oo.to_csv(datetime_csv_file)
|
190
|
+
assert File.exist?(datetime_csv_file)
|
191
|
+
assert_equal '', file_diff('test/files/so_datetime.csv', datetime_csv_file)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Using Date.strptime so check that it's using the method
|
197
|
+
# with the value set in date_format
|
198
|
+
def test_date
|
199
|
+
with_each_spreadsheet('numbers1') do |oo|
|
200
|
+
# should default to DDMMYYYY
|
201
|
+
assert oo.date?('21/11/1962')
|
202
|
+
assert !oo.date?('11/21/1962')
|
203
|
+
oo.date_format = '%m/%d/%Y'
|
204
|
+
assert !oo.date?('21/11/1962')
|
205
|
+
assert oo.date?('11/21/1962')
|
206
|
+
oo.date_format = '%Y-%m-%d'
|
207
|
+
assert(oo.date?('1962-11-21'))
|
208
|
+
assert(!oo.date?('1962-21-11'))
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_sheets
|
213
|
+
with_each_spreadsheet('numbers1') do |oo|
|
214
|
+
assert_equal ['Tabelle1', 'Name of Sheet 2', 'Sheet3', 'Sheet4', 'Sheet5'], oo.sheets
|
215
|
+
assert_raises(RangeError) { oo.default_sheet = 'no_sheet' }
|
216
|
+
assert_raises(TypeError) { oo.default_sheet = [1, 2, 3] }
|
217
|
+
oo.sheets.each do |sh|
|
218
|
+
oo.default_sheet = sh
|
219
|
+
assert_equal sh, oo.default_sheet
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_cells
|
225
|
+
with_each_spreadsheet('numbers1') do |oo|
|
226
|
+
# warum ist Auswaehlen erstes sheet hier nicht
|
227
|
+
# mehr drin?
|
228
|
+
oo.default_sheet = oo.sheets.first
|
229
|
+
assert_equal 1, oo.cell(1, 1)
|
230
|
+
assert_equal 2, oo.cell(1, 2)
|
231
|
+
assert_equal 3, oo.cell(1, 3)
|
232
|
+
assert_equal 4, oo.cell(1, 4)
|
233
|
+
assert_equal 5, oo.cell(2, 1)
|
234
|
+
assert_equal 6, oo.cell(2, 2)
|
235
|
+
assert_equal 7, oo.cell(2, 3)
|
236
|
+
assert_equal 8, oo.cell(2, 4)
|
237
|
+
assert_equal 9, oo.cell(2, 5)
|
238
|
+
assert_equal 'test', oo.cell(2, 6)
|
239
|
+
assert_equal :string, oo.celltype(2, 6)
|
240
|
+
assert_equal 11, oo.cell(2, 7)
|
241
|
+
unless oo.is_a? Roo::CSV
|
242
|
+
assert_equal :float, oo.celltype(2, 7)
|
243
|
+
end
|
244
|
+
assert_equal 10, oo.cell(4, 1)
|
245
|
+
assert_equal 11, oo.cell(4, 2)
|
246
|
+
assert_equal 12, oo.cell(4, 3)
|
247
|
+
assert_equal 13, oo.cell(4, 4)
|
248
|
+
assert_equal 14, oo.cell(4, 5)
|
249
|
+
assert_equal 10, oo.cell(4, 'A')
|
250
|
+
assert_equal 11, oo.cell(4, 'B')
|
251
|
+
assert_equal 12, oo.cell(4, 'C')
|
252
|
+
assert_equal 13, oo.cell(4, 'D')
|
253
|
+
assert_equal 14, oo.cell(4, 'E')
|
254
|
+
unless oo.is_a? Roo::CSV
|
255
|
+
assert_equal :date, oo.celltype(5, 1)
|
256
|
+
assert_equal Date.new(1961, 11, 21), oo.cell(5, 1)
|
257
|
+
assert_equal '1961-11-21', oo.cell(5, 1).to_s
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_celltype
|
263
|
+
with_each_spreadsheet('numbers1') do |oo|
|
264
|
+
assert_equal :string, oo.celltype(2, 6)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_cell_address
|
269
|
+
with_each_spreadsheet('numbers1') do |oo|
|
270
|
+
assert_equal 'tata', oo.cell(6, 1)
|
271
|
+
assert_equal 'tata', oo.cell(6, 'A')
|
272
|
+
assert_equal 'tata', oo.cell('A', 6)
|
273
|
+
assert_equal 'tata', oo.cell(6, 'a')
|
274
|
+
assert_equal 'tata', oo.cell('a', 6)
|
275
|
+
assert_raises(ArgumentError) { assert_equal 'tata', oo.cell('a', 'f') }
|
276
|
+
assert_raises(ArgumentError) { assert_equal 'tata', oo.cell('f', 'a') }
|
277
|
+
assert_equal 'thisisc8', oo.cell(8, 3)
|
278
|
+
assert_equal 'thisisc8', oo.cell(8, 'C')
|
279
|
+
assert_equal 'thisisc8', oo.cell('C', 8)
|
280
|
+
assert_equal 'thisisc8', oo.cell(8, 'c')
|
281
|
+
assert_equal 'thisisc8', oo.cell('c', 8)
|
282
|
+
assert_equal 'thisisd9', oo.cell('d', 9)
|
283
|
+
assert_equal 'thisisa11', oo.cell('a', 11)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_sheetname
|
288
|
+
with_each_spreadsheet('numbers1') do |oo|
|
289
|
+
oo.default_sheet = 'Name of Sheet 2'
|
290
|
+
assert_equal 'I am sheet 2', oo.cell('C', 5)
|
291
|
+
assert_raises(RangeError) { oo.default_sheet = 'non existing sheet name' }
|
292
|
+
assert_raises(RangeError) { oo.default_sheet = 'non existing sheet name' }
|
293
|
+
assert_raises(RangeError) { oo.cell('C', 5, 'non existing sheet name') }
|
294
|
+
assert_raises(RangeError) { oo.celltype('C', 5, 'non existing sheet name') }
|
295
|
+
assert_raises(RangeError) { oo.empty?('C', 5, 'non existing sheet name') }
|
296
|
+
assert_raises(RangeError) { oo.formula?('C', 5, 'non existing sheet name') }
|
297
|
+
assert_raises(RangeError) { oo.formula('C', 5, 'non existing sheet name') }
|
298
|
+
assert_raises(RangeError) { oo.set('C', 5, 42, 'non existing sheet name') }
|
299
|
+
assert_raises(RangeError) { oo.formulas('non existing sheet name') }
|
300
|
+
assert_raises(RangeError) { oo.to_yaml({}, 1, 1, 1, 1, 'non existing sheet name') }
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_argument_error
|
305
|
+
with_each_spreadsheet('numbers1') do |oo|
|
306
|
+
assert_nothing_raised(ArgumentError) { oo.default_sheet = 'Tabelle1' }
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_bug_italo_ve
|
311
|
+
with_each_spreadsheet('numbers1') do |oo|
|
312
|
+
oo.default_sheet = 'Sheet5'
|
313
|
+
assert_equal 1, oo.cell('A', 1)
|
314
|
+
assert_equal 5, oo.cell('b', 1)
|
315
|
+
assert_equal 5, oo.cell('c', 1)
|
316
|
+
assert_equal 2, oo.cell('a', 2)
|
317
|
+
assert_equal 3, oo.cell('a', 3)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_borders_sheets
|
322
|
+
with_each_spreadsheet('borders') do |oo|
|
323
|
+
oo.default_sheet = oo.sheets[1]
|
324
|
+
assert_equal 6, oo.first_row
|
325
|
+
assert_equal 11, oo.last_row
|
326
|
+
assert_equal 4, oo.first_column
|
327
|
+
assert_equal 8, oo.last_column
|
328
|
+
|
329
|
+
oo.default_sheet = oo.sheets.first
|
330
|
+
assert_equal 5, oo.first_row
|
331
|
+
assert_equal 10, oo.last_row
|
332
|
+
assert_equal 3, oo.first_column
|
333
|
+
assert_equal 7, oo.last_column
|
334
|
+
|
335
|
+
oo.default_sheet = oo.sheets[2]
|
336
|
+
assert_equal 7, oo.first_row
|
337
|
+
assert_equal 12, oo.last_row
|
338
|
+
assert_equal 5, oo.first_column
|
339
|
+
assert_equal 9, oo.last_column
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_only_one_sheet
|
344
|
+
with_each_spreadsheet('only_one_sheet') do |oo|
|
345
|
+
assert_equal 42, oo.cell('B', 4)
|
346
|
+
assert_equal 43, oo.cell('C', 4)
|
347
|
+
assert_equal 44, oo.cell('D', 4)
|
348
|
+
oo.default_sheet = oo.sheets.first
|
349
|
+
assert_equal 42, oo.cell('B', 4)
|
350
|
+
assert_equal 43, oo.cell('C', 4)
|
351
|
+
assert_equal 44, oo.cell('D', 4)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_should_raise_file_not_found_error
|
356
|
+
assert_raises(Net::HTTPServerException) do
|
357
|
+
Roo::Google.new(key_of('testnichtvorhanden' + 'Bibelbund.ods'))
|
358
|
+
Roo::Google.new('testnichtvorhanden')
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|