roo 1.13.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.simplecov +4 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGELOG.md +515 -0
  6. data/Gemfile +16 -10
  7. data/Guardfile +24 -0
  8. data/LICENSE +3 -1
  9. data/README.md +254 -0
  10. data/Rakefile +23 -23
  11. data/examples/roo_soap_client.rb +28 -31
  12. data/examples/roo_soap_server.rb +4 -6
  13. data/examples/write_me.rb +9 -10
  14. data/lib/roo/base.rb +334 -395
  15. data/lib/roo/csv.rb +120 -113
  16. data/lib/roo/excelx/cell.rb +77 -0
  17. data/lib/roo/excelx/comments.rb +22 -0
  18. data/lib/roo/excelx/extractor.rb +22 -0
  19. data/lib/roo/excelx/relationships.rb +25 -0
  20. data/lib/roo/excelx/shared_strings.rb +37 -0
  21. data/lib/roo/excelx/sheet.rb +107 -0
  22. data/lib/roo/excelx/sheet_doc.rb +200 -0
  23. data/lib/roo/excelx/styles.rb +64 -0
  24. data/lib/roo/excelx/workbook.rb +59 -0
  25. data/lib/roo/excelx.rb +413 -597
  26. data/lib/roo/font.rb +17 -0
  27. data/lib/roo/libre_office.rb +5 -0
  28. data/lib/roo/link.rb +15 -0
  29. data/lib/roo/{openoffice.rb → open_office.rb} +681 -496
  30. data/lib/roo/spreadsheet.rb +20 -23
  31. data/lib/roo/utils.rb +78 -0
  32. data/lib/roo/version.rb +3 -0
  33. data/lib/roo.rb +18 -24
  34. data/roo.gemspec +20 -204
  35. data/spec/lib/roo/base_spec.rb +1 -4
  36. data/spec/lib/roo/csv_spec.rb +21 -13
  37. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  38. data/spec/lib/roo/excelx_spec.rb +424 -11
  39. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  40. data/spec/lib/roo/openoffice_spec.rb +13 -8
  41. data/spec/lib/roo/spreadsheet_spec.rb +40 -12
  42. data/spec/lib/roo/utils_spec.rb +106 -0
  43. data/spec/spec_helper.rb +2 -1
  44. data/test/test_generic_spreadsheet.rb +117 -139
  45. data/test/test_helper.rb +9 -56
  46. data/test/test_roo.rb +274 -478
  47. metadata +65 -303
  48. data/CHANGELOG +0 -417
  49. data/Gemfile.lock +0 -78
  50. data/README.markdown +0 -126
  51. data/VERSION +0 -1
  52. data/lib/roo/excel.rb +0 -355
  53. data/lib/roo/excel2003xml.rb +0 -300
  54. data/lib/roo/google.rb +0 -292
  55. data/lib/roo/roo_rails_helper.rb +0 -83
  56. data/lib/roo/worksheet.rb +0 -18
  57. data/scripts/txt2html +0 -67
  58. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  59. data/spec/lib/roo/excel_spec.rb +0 -17
  60. data/spec/lib/roo/google_spec.rb +0 -64
  61. data/test/files/1900_base.xls +0 -0
  62. data/test/files/1900_base.xlsx +0 -0
  63. data/test/files/1904_base.xls +0 -0
  64. data/test/files/1904_base.xlsx +0 -0
  65. data/test/files/Bibelbund.csv +0 -3741
  66. data/test/files/Bibelbund.ods +0 -0
  67. data/test/files/Bibelbund.xls +0 -0
  68. data/test/files/Bibelbund.xlsx +0 -0
  69. data/test/files/Bibelbund.xml +0 -62518
  70. data/test/files/Bibelbund1.ods +0 -0
  71. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  72. data/test/files/bad_excel_date.xls +0 -0
  73. data/test/files/bbu.ods +0 -0
  74. data/test/files/bbu.xls +0 -0
  75. data/test/files/bbu.xlsx +0 -0
  76. data/test/files/bbu.xml +0 -152
  77. data/test/files/bode-v1.ods.zip +0 -0
  78. data/test/files/bode-v1.xls.zip +0 -0
  79. data/test/files/boolean.csv +0 -2
  80. data/test/files/boolean.ods +0 -0
  81. data/test/files/boolean.xls +0 -0
  82. data/test/files/boolean.xlsx +0 -0
  83. data/test/files/boolean.xml +0 -112
  84. data/test/files/borders.ods +0 -0
  85. data/test/files/borders.xls +0 -0
  86. data/test/files/borders.xlsx +0 -0
  87. data/test/files/borders.xml +0 -144
  88. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  89. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  90. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  91. data/test/files/comments.ods +0 -0
  92. data/test/files/comments.xls +0 -0
  93. data/test/files/comments.xlsx +0 -0
  94. data/test/files/csvtypes.csv +0 -1
  95. data/test/files/datetime.ods +0 -0
  96. data/test/files/datetime.xls +0 -0
  97. data/test/files/datetime.xlsx +0 -0
  98. data/test/files/datetime.xml +0 -142
  99. data/test/files/datetime_floatconv.xls +0 -0
  100. data/test/files/datetime_floatconv.xml +0 -148
  101. data/test/files/dreimalvier.ods +0 -0
  102. data/test/files/emptysheets.ods +0 -0
  103. data/test/files/emptysheets.xls +0 -0
  104. data/test/files/emptysheets.xlsx +0 -0
  105. data/test/files/emptysheets.xml +0 -105
  106. data/test/files/excel2003.xml +0 -21140
  107. data/test/files/false_encoding.xls +0 -0
  108. data/test/files/false_encoding.xml +0 -132
  109. data/test/files/file_item_error.xlsx +0 -0
  110. data/test/files/formula.ods +0 -0
  111. data/test/files/formula.xls +0 -0
  112. data/test/files/formula.xlsx +0 -0
  113. data/test/files/formula.xml +0 -134
  114. data/test/files/formula_parse_error.xls +0 -0
  115. data/test/files/formula_parse_error.xml +0 -1833
  116. data/test/files/formula_string_error.xlsx +0 -0
  117. data/test/files/html-escape.ods +0 -0
  118. data/test/files/link.xls +0 -0
  119. data/test/files/link.xlsx +0 -0
  120. data/test/files/matrix.ods +0 -0
  121. data/test/files/matrix.xls +0 -0
  122. data/test/files/named_cells.ods +0 -0
  123. data/test/files/named_cells.xls +0 -0
  124. data/test/files/named_cells.xlsx +0 -0
  125. data/test/files/no_spreadsheet_file.txt +0 -1
  126. data/test/files/numbers1.csv +0 -18
  127. data/test/files/numbers1.ods +0 -0
  128. data/test/files/numbers1.xls +0 -0
  129. data/test/files/numbers1.xlsx +0 -0
  130. data/test/files/numbers1.xml +0 -312
  131. data/test/files/numeric-link.xlsx +0 -0
  132. data/test/files/only_one_sheet.ods +0 -0
  133. data/test/files/only_one_sheet.xls +0 -0
  134. data/test/files/only_one_sheet.xlsx +0 -0
  135. data/test/files/only_one_sheet.xml +0 -67
  136. data/test/files/paragraph.ods +0 -0
  137. data/test/files/paragraph.xls +0 -0
  138. data/test/files/paragraph.xlsx +0 -0
  139. data/test/files/paragraph.xml +0 -127
  140. data/test/files/prova.xls +0 -0
  141. data/test/files/ric.ods +0 -0
  142. data/test/files/simple_spreadsheet.ods +0 -0
  143. data/test/files/simple_spreadsheet.xls +0 -0
  144. data/test/files/simple_spreadsheet.xlsx +0 -0
  145. data/test/files/simple_spreadsheet.xml +0 -225
  146. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  147. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  148. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  149. data/test/files/so_datetime.csv +0 -7
  150. data/test/files/style.ods +0 -0
  151. data/test/files/style.xls +0 -0
  152. data/test/files/style.xlsx +0 -0
  153. data/test/files/style.xml +0 -154
  154. data/test/files/time-test.csv +0 -2
  155. data/test/files/time-test.ods +0 -0
  156. data/test/files/time-test.xls +0 -0
  157. data/test/files/time-test.xlsx +0 -0
  158. data/test/files/time-test.xml +0 -131
  159. data/test/files/type_excel.ods +0 -0
  160. data/test/files/type_excel.xlsx +0 -0
  161. data/test/files/type_excelx.ods +0 -0
  162. data/test/files/type_excelx.xls +0 -0
  163. data/test/files/type_openoffice.xls +0 -0
  164. data/test/files/type_openoffice.xlsx +0 -0
  165. data/test/files/whitespace.ods +0 -0
  166. data/test/files/whitespace.xls +0 -0
  167. data/test/files/whitespace.xlsx +0 -0
  168. data/test/files/whitespace.xml +0 -184
  169. data/test/rm_sub_test.rb +0 -12
  170. data/test/rm_test.rb +0 -7
  171. data/website/index.html +0 -385
  172. data/website/index.txt +0 -423
  173. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  174. data/website/stylesheets/screen.css +0 -130
  175. data/website/template.rhtml +0 -48
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ::Roo::Utils do
4
+ subject { described_class }
5
+
6
+ context '#number_to_letter' do
7
+ ('A'..'Z').to_a.each_with_index do |letter, index|
8
+ it "should return '#{ letter }' when passed #{ index + 1 }" do
9
+ expect(described_class.number_to_letter(index + 1)).to eq(letter)
10
+ end
11
+ end
12
+
13
+ {
14
+ 27 => 'AA', 26*2 => 'AZ', 26*3 => 'BZ', 26**2 + 26 => 'ZZ', 26**2 + 27 => 'AAA',
15
+ 26**3 + 26**2 + 26 => 'ZZZ', 1.0 => 'A', 676 => 'YZ', 677 => 'ZA'
16
+ }.each do |key, value|
17
+ it "should return '#{value}' when passed #{key}" do
18
+ expect(described_class.number_to_letter(key)).to eq(value)
19
+ end
20
+ end
21
+ end
22
+
23
+ context '#letter_to_number' do
24
+ it "should give 1 for 'A' and 'a'" do
25
+ expect(described_class.letter_to_number('A')).to eq(1)
26
+ expect(described_class.letter_to_number('a')).to eq(1)
27
+ end
28
+
29
+ it "should give the correct value for 'Z'" do
30
+ expect(described_class.letter_to_number('Z')).to eq(26)
31
+ end
32
+
33
+ it "should give the correct value for 'AA' regardless of case mixing" do
34
+ %w(AA aA Aa aa).each do |key|
35
+ expect(described_class.letter_to_number(key)).to eq(27)
36
+ end
37
+ end
38
+
39
+ { 'AB' => 28, 'AZ' => 26*2, 'BZ' => 26*3, 'ZZ' => 26**2 + 26 }.each do |key, value|
40
+ it "should give the correct value for '#{key}'" do
41
+ expect(described_class.letter_to_number(key)).to eq(value)
42
+ end
43
+ end
44
+ end
45
+
46
+ context '.split_coordinate' do
47
+ it "returns the expected result" do
48
+ expect(described_class.split_coordinate('A1')).to eq [1, 1]
49
+ expect(described_class.split_coordinate('B2')).to eq [2, 2]
50
+ expect(described_class.split_coordinate('R2')).to eq [2, 18]
51
+ expect(described_class.split_coordinate('AR31')).to eq [31, 18 + 26]
52
+ end
53
+ end
54
+
55
+ context '.split_coord' do
56
+ it "returns the expected result" do
57
+ expect(described_class.split_coord('A1')).to eq ["A", 1]
58
+ expect(described_class.split_coord('B2')).to eq ["B", 2]
59
+ expect(described_class.split_coord('R2')).to eq ["R", 2]
60
+ expect(described_class.split_coord('AR31')).to eq ["AR", 31]
61
+ end
62
+
63
+ it "raises an error when appropriate" do
64
+ expect { described_class.split_coord('A') }.to raise_error(ArgumentError)
65
+ expect { described_class.split_coord('2') }.to raise_error(ArgumentError)
66
+ end
67
+ end
68
+
69
+
70
+ context '.num_cells_in_range' do
71
+ it "returns the expected result" do
72
+ expect(described_class.num_cells_in_range('A1:B2')).to eq 4
73
+ expect(described_class.num_cells_in_range('B2:E3')).to eq 8
74
+ expect(described_class.num_cells_in_range('R2:Z10')).to eq 81
75
+ expect(described_class.num_cells_in_range('AR31:AR32')).to eq 2
76
+ expect(described_class.num_cells_in_range('A1')).to eq 1
77
+ end
78
+
79
+ it "raises an error when appropriate" do
80
+ expect { described_class.num_cells_in_range('A1:B1:B2') }.to raise_error(ArgumentError)
81
+ end
82
+ end
83
+
84
+ context '.load_xml' do
85
+ it 'returns the expected result' do
86
+ expect(described_class.load_xml('test/files/sheet1.xml')).to be_a(Nokogiri::XML::Document)
87
+ expect(described_class.load_xml('test/files/sheet1.xml').
88
+ remove_namespaces!.xpath("/worksheet/dimension").map do |dim|
89
+ dim.attributes["ref"].value end.first).to eq "A1:B11"
90
+ end
91
+ end
92
+
93
+ context '.each_element' do
94
+ it 'returns the expected result' do
95
+ described_class.each_element('test/files/sheet1.xml', 'dimension') do |dim|
96
+ expect(dim.attributes["ref"].value).to eq "A1:B11"
97
+ end
98
+ rows = []
99
+ described_class.each_element('test/files/sheet1.xml', 'row') do |row|
100
+ rows << row
101
+ end
102
+ expect(rows.size).to eq 11
103
+ expect(rows[2].attributes["r"].value).to eq "3"
104
+ end
105
+ end
106
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- require File.expand_path("../../lib/roo", __FILE__)
1
+ require 'simplecov'
2
+ require 'roo'
2
3
 
3
4
  require 'vcr'
4
5
 
@@ -1,124 +1,68 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require File.dirname(__FILE__) + '/test_helper'
3
3
 
4
- class TestBase < Test::Unit::TestCase
5
-
4
+ class TestBase < Minitest::Test
6
5
  def setup
7
6
  @klass = Class.new(Roo::Base) do
8
- def initialize(filename='some_file')
7
+ def initialize(filename = 'some_file')
9
8
  super
10
9
  @filename = filename
11
10
  end
12
11
 
13
- def read_cells(sheet=nil)
12
+ def read_cells(sheet = nil)
14
13
  @cells_read[sheet] = true
15
14
  end
16
15
 
17
- def cell(row, col, sheet=nil)
18
- sheet ||= @default_sheet
19
- @cell[sheet][[row,col]]
16
+ def cell(row, col, sheet = nil)
17
+ sheet ||= default_sheet
18
+ @cell[sheet][[row, col]]
20
19
  end
21
20
 
22
- def celltype(row, col, sheet=nil)
23
- sheet ||= @default_sheet
24
- @cell_type[sheet][[row,col]]
21
+ def celltype(row, col, sheet = nil)
22
+ sheet ||= default_sheet
23
+ @cell_type[sheet][[row, col]]
25
24
  end
26
25
 
27
26
  def sheets
28
- ['my_sheet','blank sheet']
27
+ ['my_sheet', 'blank sheet']
29
28
  end
30
29
  end
31
30
  @oo = @klass.new
32
31
  setup_test_sheet(@oo)
33
32
  end
34
33
 
35
- context 'Roo::Base.letter_to_number(letter)' do
36
- should "give us 1 for 'A' and 'a'" do
37
- assert_equal 1, Roo::Base.letter_to_number('A')
38
- assert_equal 1, Roo::Base.letter_to_number('a')
39
- end
40
-
41
- should "give us the correct value for 'Z'" do
42
- assert_equal 26, Roo::Base.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::Base.letter_to_number('AA')
47
- assert_equal 27, Roo::Base.letter_to_number('aA')
48
- assert_equal 27, Roo::Base.letter_to_number('Aa')
49
- assert_equal 27, Roo::Base.letter_to_number('aa')
50
- end
51
-
52
- should "give us the correct value for 'AB'" do
53
- assert_equal 28, Roo::Base.letter_to_number('AB')
54
- end
55
-
56
- should "give us the correct value for 'AZ'" do
57
- assert_equal 26*2, Roo::Base.letter_to_number('AZ')
34
+ context 'private method Roo::Base.uri?(filename)' do
35
+ should 'return true when passed a filename starts with http(s)://' do
36
+ assert_equal true, @oo.send(:uri?, 'http://example.com/')
37
+ assert_equal true, @oo.send(:uri?, 'https://example.com/')
58
38
  end
59
39
 
60
- should "give us the correct value for 'BZ'" do
61
- assert_equal 26*3, Roo::Base.letter_to_number('BZ')
40
+ should 'return false when passed a filename which does not start with http(s)://' do
41
+ assert_equal false, @oo.send(:uri?, 'example.com')
62
42
  end
63
43
 
64
- should "give us the correct value for 'ZZ'" do
65
- assert_equal 26**2 + 26,Roo::Base.letter_to_number('ZZ')
66
- end
67
- end
68
-
69
- context "Roo::Base.number_to_letter" do
70
- Roo::Base::LETTERS.each_with_index do |l,i|
71
- should "return '#{l}' when passed #{i+1}" do
72
- assert_equal l,Roo::Base.number_to_letter(i+1)
73
- end
74
- end
75
-
76
- should "return 'AA' when passed 27" do
77
- assert_equal 'AA',Roo::Base.number_to_letter(27)
78
- end
79
-
80
- should "return 'AZ' when passed #{26*2}" do
81
- assert_equal 'AZ', Roo::Base.number_to_letter(26*2)
82
- end
83
-
84
- should "return 'BZ' when passed #{26*3}" do
85
- assert_equal 'BZ', Roo::Base.number_to_letter(26*3)
86
- end
87
-
88
- should "return 'ZZ' when passed #{26**2 + 26}" do
89
- assert_equal 'ZZ',Roo::Base.number_to_letter(26**2 + 26)
90
- end
91
-
92
- should "return 'AAA' when passed #{26**2 + 27}" do
93
- assert_equal 'AAA',Roo::Base.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::Base.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::Base.number_to_letter(1.0)
44
+ should 'return false when passed non-String object such as Tempfile' do
45
+ assert_equal false, @oo.send(:uri?, Tempfile.new('test'))
102
46
  end
103
47
  end
104
48
 
105
49
  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)
50
+ @oo.set(1, 1, 1)
51
+ assert_raises(ArgumentError) { @oo.set(1, 1, :invalid_type) }
52
+ assert_equal 1, @oo.cell(1, 1)
53
+ assert_equal :float, @oo.celltype(1, 1)
110
54
  end
111
55
 
112
56
  def test_first_row
113
- assert_equal 5,@oo.first_row
57
+ assert_equal 5, @oo.first_row
114
58
  end
115
59
 
116
60
  def test_last_row
117
- assert_equal 16,@oo.last_row
61
+ assert_equal 16, @oo.last_row
118
62
  end
119
63
 
120
64
  def test_first_column
121
- assert_equal 1,@oo.first_column
65
+ assert_equal 1, @oo.first_column
122
66
  end
123
67
 
124
68
  def test_first_column_as_letter
@@ -133,17 +77,16 @@ class TestBase < Test::Unit::TestCase
133
77
  assert_equal 'G', @oo.last_column_as_letter
134
78
  end
135
79
 
136
- #TODO: inkonsequente Lieferung Fixnum/Float
137
80
  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)
81
+ assert_equal [41.0, 42.0, 43.0, 44.0, 45.0, nil, nil], @oo.row(12)
82
+ assert_equal [nil, '"Hello world!"', 'dreiundvierzig', 'vierundvierzig', 'fuenfundvierzig', nil, nil], @oo.row(16)
140
83
  end
141
84
 
142
85
  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)
86
+ assert @oo.empty?(1, 1)
87
+ assert !@oo.empty?(8, 3)
88
+ assert @oo.empty?('A', 11)
89
+ assert !@oo.empty?('A', 12)
147
90
  end
148
91
 
149
92
  def test_reload
@@ -151,31 +94,43 @@ class TestBase < Test::Unit::TestCase
151
94
  assert @oo.instance_variable_get(:@cell).empty?
152
95
  end
153
96
 
97
+ def test_each
98
+ oo_each = @oo.each
99
+ assert_instance_of Enumerator, oo_each
100
+ assert_equal [nil, '"Hello world!"', 'dreiundvierzig', 'vierundvierzig', 'fuenfundvierzig', nil, nil], oo_each.to_a.last
101
+ end
102
+
154
103
  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)
104
+ assert_equal "--- \n" + yaml_entry(5, 1, 'date', '1961-11-21'), @oo.to_yaml({}, 5, 1, 5, 1)
105
+ assert_equal "--- \n" + yaml_entry(8, 3, 'string', 'thisisc8'), @oo.to_yaml({}, 8, 3, 8, 3)
106
+ assert_equal "--- \n" + yaml_entry(12, 3, 'float', 43.0), @oo.to_yaml({}, 12, 3, 12, 3)
158
107
  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)
108
+ "--- \n" + yaml_entry(12, 3, 'float', 43.0) +
109
+ yaml_entry(12, 4, 'float', 44.0) +
110
+ yaml_entry(12, 5, 'float', 45.0), @oo.to_yaml({}, 12, 3, 12)
162
111
  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)
112
+ "--- \n" + yaml_entry(12, 3, 'float', 43.0) +
113
+ yaml_entry(12, 4, 'float', 44.0) +
114
+ yaml_entry(12, 5, 'float', 45.0) +
115
+ yaml_entry(15, 3, 'float', 43.0) +
116
+ yaml_entry(15, 4, 'float', 44.0) +
117
+ yaml_entry(15, 5, 'float', 45.0) +
118
+ yaml_entry(16, 3, 'string', 'dreiundvierzig') +
119
+ yaml_entry(16, 4, 'string', 'vierundvierzig') +
120
+ yaml_entry(16, 5, 'string', 'fuenfundvierzig'), @oo.to_yaml({}, 12, 3)
172
121
  end
173
122
 
174
123
  def test_to_csv
175
- assert_equal expected_csv,@oo.to_csv
124
+ assert_equal expected_csv, @oo.to_csv
176
125
  end
177
- protected
178
- def setup_test_sheet(workbook=nil)
126
+
127
+ def test_to_csv_with_separator
128
+ assert_equal expected_csv_with_semicolons, @oo.to_csv(nil, ';')
129
+ end
130
+
131
+ protected
132
+
133
+ def setup_test_sheet(workbook = nil)
179
134
  workbook ||= @oo
180
135
  set_sheet_values(workbook)
181
136
  set_sheet_types(workbook)
@@ -184,68 +139,70 @@ protected
184
139
 
185
140
  def set_sheet_values(workbook)
186
141
  workbook.instance_variable_get(:@cell)[workbook.default_sheet] = {
187
- [5,1] => Date.civil(1961,11,21).to_s,
142
+ [5, 1] => Date.civil(1961, 11, 21).to_s,
188
143
 
189
- [8,3] => "thisisc8",
190
- [8,7] => "thisisg8",
144
+ [8, 3] => 'thisisc8',
145
+ [8, 7] => 'thisisg8',
191
146
 
192
- [12,1] => 41.0,
193
- [12,2] => 42.0,
194
- [12,3] => 43.0,
195
- [12,4] => 44.0,
196
- [12,5] => 45.0,
147
+ [12, 1] => 41.0,
148
+ [12, 2] => 42.0,
149
+ [12, 3] => 43.0,
150
+ [12, 4] => 44.0,
151
+ [12, 5] => 45.0,
197
152
 
198
- [15,3] => 43.0,
199
- [15,4] => 44.0,
200
- [15,5] => 45.0,
153
+ [15, 3] => 43.0,
154
+ [15, 4] => 44.0,
155
+ [15, 5] => 45.0,
201
156
 
202
- [16,3] => "dreiundvierzig",
203
- [16,4] => "vierundvierzig",
204
- [16,5] => "fuenfundvierzig"
157
+ [16, 2] => '"Hello world!"',
158
+ [16, 3] => 'dreiundvierzig',
159
+ [16, 4] => 'vierundvierzig',
160
+ [16, 5] => 'fuenfundvierzig'
205
161
  }
206
162
  end
207
163
 
208
164
  def set_sheet_types(workbook)
209
165
  workbook.instance_variable_get(:@cell_type)[workbook.default_sheet] = {
210
- [5,1] => :date,
166
+ [5, 1] => :date,
211
167
 
212
- [8,3] => :string,
213
- [8,7] => :string,
168
+ [8, 3] => :string,
169
+ [8, 7] => :string,
214
170
 
215
- [12,1] => :float,
216
- [12,2] => :float,
217
- [12,3] => :float,
218
- [12,4] => :float,
219
- [12,5] => :float,
171
+ [12, 1] => :float,
172
+ [12, 2] => :float,
173
+ [12, 3] => :float,
174
+ [12, 4] => :float,
175
+ [12, 5] => :float,
220
176
 
221
- [15,3] => :float,
222
- [15,4] => :float,
223
- [15,5] => :float,
177
+ [15, 3] => :float,
178
+ [15, 4] => :float,
179
+ [15, 5] => :float,
224
180
 
225
- [16,3] => :string,
226
- [16,4] => :string,
227
- [16,5] => :string,
181
+ [16, 2] => :string,
182
+ [16, 3] => :string,
183
+ [16, 4] => :string,
184
+ [16, 5] => :string
228
185
  }
229
186
  end
230
187
 
231
188
  def set_first_row(workbook)
232
189
  row_hash = workbook.instance_variable_get(:@first_row)
233
- row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[0]}.min
190
+ row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map { |k, _v| k[0] }.min
234
191
  end
235
192
 
236
193
  def set_last_row(workbook)
237
194
  row_hash = workbook.instance_variable_get(:@last_row)
238
- row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[0]}.max
195
+ row_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map { |k, _v| k[0] }.max
239
196
  end
240
197
 
241
198
  def set_first_col(workbook)
242
199
  col_hash = workbook.instance_variable_get(:@first_column)
243
- col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[1]}.min
200
+ col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map { |k, _v| k[1] }.min
244
201
  end
245
202
 
246
203
  def set_last_col(workbook)
247
204
  col_hash = workbook.instance_variable_get(:@last_column)
248
- col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map{|k,v| k[1]}.max
205
+ col_hash[workbook.default_sheet] = workbook.instance_variable_get(:@cell)[workbook.default_sheet].map { |k, _v| k[1] }.max
249
206
  end
250
207
 
251
208
  def set_cells_read(workbook)
@@ -254,6 +211,27 @@ protected
254
211
  end
255
212
 
256
213
  def expected_csv
257
- ",,,,,,\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"
214
+ <<EOS
215
+ ,,,,,,
216
+ ,,,,,,
217
+ ,,,,,,
218
+ ,,,,,,
219
+ 1961-11-21,,,,,,
220
+ ,,,,,,
221
+ ,,,,,,
222
+ ,,"thisisc8",,,,"thisisg8"
223
+ ,,,,,,
224
+ ,,,,,,
225
+ ,,,,,,
226
+ 41,42,43,44,45,,
227
+ ,,,,,,
228
+ ,,,,,,
229
+ ,,43,44,45,,
230
+ ,"""Hello world!""","dreiundvierzig","vierundvierzig","fuenfundvierzig",,
231
+ EOS
232
+ end
233
+
234
+ def expected_csv_with_semicolons
235
+ expected_csv.gsub(/\,/, ';')
258
236
  end
259
237
  end
data/test/test_helper.rb CHANGED
@@ -1,30 +1,20 @@
1
+ require 'simplecov'
1
2
  # require deps
2
3
  require 'tmpdir'
3
4
  require 'fileutils'
4
- require 'test/unit'
5
+ require 'minitest/autorun'
5
6
  require 'shoulda'
6
7
  require 'fileutils'
7
8
  require 'timeout'
8
9
  require 'logger'
9
10
  require 'date'
10
- require 'webmock/test_unit'
11
+ require 'webmock/minitest'
11
12
 
12
13
  # require gem files
13
- require File.dirname(__FILE__) + '/../lib/roo'
14
+ require 'roo'
14
15
 
15
16
  TESTDIR = File.join(File.dirname(__FILE__), 'files')
16
17
 
17
- LOG_DIR = File.join(File.dirname(__FILE__),'../log')
18
- FileUtils.mkdir_p(LOG_DIR)
19
-
20
- LOG_FILE = File.join(LOG_DIR,'roo_test.log')
21
- $log = Logger.new(LOG_FILE)
22
-
23
- #$log.level = Logger::WARN
24
- $log.level = Logger::DEBUG
25
-
26
- DISPLAY_LOG = false
27
-
28
18
  # very simple diff implementation
29
19
  # output is an empty string if the files are equal
30
20
  # otherwise differences a printen (not compatible to
@@ -47,7 +37,7 @@ def file_diff(fn1,fn2)
47
37
  if f2.eof? == false
48
38
  while f2.eof? == false
49
39
  line2 = f2.gets
50
- result ">#{line2}\n"
40
+ result << ">#{line2}\n"
51
41
  end
52
42
  end
53
43
  end
@@ -55,6 +45,10 @@ def file_diff(fn1,fn2)
55
45
  result
56
46
  end
57
47
 
48
+ def yaml_entry(row,col,type,value)
49
+ "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
50
+ end
51
+
58
52
  class File
59
53
  def File.delete_if_exist(filename)
60
54
  if File.exist?(filename)
@@ -62,44 +56,3 @@ class File
62
56
  end
63
57
  end
64
58
  end
65
-
66
- class Test::Unit::TestCase
67
- def key_of(spreadsheetname)
68
- {
69
- #'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
70
- 'formula' => 'o10837434939102457526.3022866619437760118',
71
- #"write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
72
- "write.me" => '0AkCuGANLc3jFcHR1NmJiYWhOWnBZME4wUnJ4UWJXZHc',
73
- #'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
74
- 'numbers1' => 'o10837434939102457526.4784396906364855777',
75
- #'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
76
- 'borders' => "o10837434939102457526.664868920231926255",
77
- #'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
78
- 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
79
- 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
80
- #"only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
81
- "only_one_sheet" => "o10837434939102457526.762705759906130135",
82
- #'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
83
- 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
84
- #'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
85
- 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
86
- 'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ",
87
- 'matrix' => '0AkCuGANLc3jFdHY3cWtYUkM4bVdadjZ5VGpfTzFEUEE',
88
- # 'numbers1' => "o10837434939102457526.4784396906364855777",
89
- # 'borders' => "o10837434939102457526.664868920231926255",
90
- # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
91
- # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
92
- # "only_one_sheet" => "o10837434939102457526.762705759906130135",
93
- # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
94
- # 'formula' => 'o10837434939102457526.3022866619437760118',
95
- # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
96
- # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
97
- }.fetch(spreadsheetname)
98
- rescue KeyError
99
- raise "unknown spreadsheetname: #{spreadsheetname}"
100
- end
101
-
102
- def yaml_entry(row,col,type,value)
103
- "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
104
- end
105
- end