roo 1.13.2 → 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +17 -0
  3. data/.github/issue_template.md +16 -0
  4. data/.github/pull_request_template.md +14 -0
  5. data/.github/workflows/pull-request.yml +15 -0
  6. data/.github/workflows/ruby.yml +34 -0
  7. data/.gitignore +11 -0
  8. data/.rubocop.yml +186 -0
  9. data/.simplecov +4 -0
  10. data/CHANGELOG.md +702 -0
  11. data/Gemfile +18 -12
  12. data/Guardfile +23 -0
  13. data/LICENSE +5 -1
  14. data/README.md +328 -0
  15. data/Rakefile +23 -23
  16. data/examples/roo_soap_client.rb +28 -31
  17. data/examples/roo_soap_server.rb +4 -6
  18. data/examples/write_me.rb +9 -10
  19. data/lib/roo/base.rb +317 -504
  20. data/lib/roo/constants.rb +7 -0
  21. data/lib/roo/csv.rb +141 -113
  22. data/lib/roo/errors.rb +11 -0
  23. data/lib/roo/excelx/cell/base.rb +108 -0
  24. data/lib/roo/excelx/cell/boolean.rb +30 -0
  25. data/lib/roo/excelx/cell/date.rb +28 -0
  26. data/lib/roo/excelx/cell/datetime.rb +107 -0
  27. data/lib/roo/excelx/cell/empty.rb +20 -0
  28. data/lib/roo/excelx/cell/number.rb +99 -0
  29. data/lib/roo/excelx/cell/string.rb +19 -0
  30. data/lib/roo/excelx/cell/time.rb +44 -0
  31. data/lib/roo/excelx/cell.rb +110 -0
  32. data/lib/roo/excelx/comments.rb +55 -0
  33. data/lib/roo/excelx/coordinate.rb +19 -0
  34. data/lib/roo/excelx/extractor.rb +39 -0
  35. data/lib/roo/excelx/format.rb +71 -0
  36. data/lib/roo/excelx/images.rb +26 -0
  37. data/lib/roo/excelx/relationships.rb +33 -0
  38. data/lib/roo/excelx/shared.rb +39 -0
  39. data/lib/roo/excelx/shared_strings.rb +151 -0
  40. data/lib/roo/excelx/sheet.rb +151 -0
  41. data/lib/roo/excelx/sheet_doc.rb +257 -0
  42. data/lib/roo/excelx/styles.rb +64 -0
  43. data/lib/roo/excelx/workbook.rb +64 -0
  44. data/lib/roo/excelx.rb +407 -601
  45. data/lib/roo/font.rb +17 -0
  46. data/lib/roo/formatters/base.rb +15 -0
  47. data/lib/roo/formatters/csv.rb +84 -0
  48. data/lib/roo/formatters/matrix.rb +23 -0
  49. data/lib/roo/formatters/xml.rb +31 -0
  50. data/lib/roo/formatters/yaml.rb +40 -0
  51. data/lib/roo/helpers/default_attr_reader.rb +20 -0
  52. data/lib/roo/helpers/weak_instance_cache.rb +41 -0
  53. data/lib/roo/libre_office.rb +4 -0
  54. data/lib/roo/link.rb +34 -0
  55. data/lib/roo/open_office.rb +631 -0
  56. data/lib/roo/spreadsheet.rb +28 -23
  57. data/lib/roo/tempdir.rb +24 -0
  58. data/lib/roo/utils.rb +128 -0
  59. data/lib/roo/version.rb +3 -0
  60. data/lib/roo.rb +26 -24
  61. data/roo.gemspec +29 -203
  62. data/spec/helpers.rb +5 -0
  63. data/spec/lib/roo/base_spec.rb +291 -3
  64. data/spec/lib/roo/csv_spec.rb +38 -11
  65. data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
  66. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  67. data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
  68. data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
  69. data/spec/lib/roo/excelx_spec.rb +672 -11
  70. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  71. data/spec/lib/roo/openoffice_spec.rb +30 -8
  72. data/spec/lib/roo/spreadsheet_spec.rb +60 -12
  73. data/spec/lib/roo/strict_spec.rb +43 -0
  74. data/spec/lib/roo/utils_spec.rb +119 -0
  75. data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
  76. data/spec/lib/roo_spec.rb +0 -0
  77. data/spec/spec_helper.rb +7 -6
  78. data/test/all_ss.rb +12 -11
  79. data/test/excelx/cell/test_attr_reader_default.rb +72 -0
  80. data/test/excelx/cell/test_base.rb +68 -0
  81. data/test/excelx/cell/test_boolean.rb +36 -0
  82. data/test/excelx/cell/test_date.rb +38 -0
  83. data/test/excelx/cell/test_datetime.rb +45 -0
  84. data/test/excelx/cell/test_empty.rb +18 -0
  85. data/test/excelx/cell/test_number.rb +90 -0
  86. data/test/excelx/cell/test_string.rb +48 -0
  87. data/test/excelx/cell/test_time.rb +30 -0
  88. data/test/excelx/test_coordinate.rb +51 -0
  89. data/test/formatters/test_csv.rb +136 -0
  90. data/test/formatters/test_matrix.rb +76 -0
  91. data/test/formatters/test_xml.rb +78 -0
  92. data/test/formatters/test_yaml.rb +20 -0
  93. data/test/helpers/test_accessing_files.rb +81 -0
  94. data/test/helpers/test_comments.rb +43 -0
  95. data/test/helpers/test_formulas.rb +9 -0
  96. data/test/helpers/test_labels.rb +103 -0
  97. data/test/helpers/test_sheets.rb +55 -0
  98. data/test/helpers/test_styles.rb +62 -0
  99. data/test/roo/test_base.rb +182 -0
  100. data/test/roo/test_csv.rb +88 -0
  101. data/test/roo/test_excelx.rb +360 -0
  102. data/test/roo/test_libre_office.rb +9 -0
  103. data/test/roo/test_open_office.rb +289 -0
  104. data/test/test_helper.rb +123 -59
  105. data/test/test_roo.rb +392 -2292
  106. metadata +153 -298
  107. data/CHANGELOG +0 -417
  108. data/Gemfile.lock +0 -78
  109. data/README.markdown +0 -126
  110. data/VERSION +0 -1
  111. data/lib/roo/excel.rb +0 -355
  112. data/lib/roo/excel2003xml.rb +0 -300
  113. data/lib/roo/google.rb +0 -292
  114. data/lib/roo/openoffice.rb +0 -496
  115. data/lib/roo/roo_rails_helper.rb +0 -83
  116. data/lib/roo/worksheet.rb +0 -18
  117. data/scripts/txt2html +0 -67
  118. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  119. data/spec/lib/roo/excel_spec.rb +0 -17
  120. data/spec/lib/roo/google_spec.rb +0 -64
  121. data/test/files/1900_base.xls +0 -0
  122. data/test/files/1900_base.xlsx +0 -0
  123. data/test/files/1904_base.xls +0 -0
  124. data/test/files/1904_base.xlsx +0 -0
  125. data/test/files/Bibelbund.csv +0 -3741
  126. data/test/files/Bibelbund.ods +0 -0
  127. data/test/files/Bibelbund.xls +0 -0
  128. data/test/files/Bibelbund.xlsx +0 -0
  129. data/test/files/Bibelbund.xml +0 -62518
  130. data/test/files/Bibelbund1.ods +0 -0
  131. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  132. data/test/files/bad_excel_date.xls +0 -0
  133. data/test/files/bbu.ods +0 -0
  134. data/test/files/bbu.xls +0 -0
  135. data/test/files/bbu.xlsx +0 -0
  136. data/test/files/bbu.xml +0 -152
  137. data/test/files/bode-v1.ods.zip +0 -0
  138. data/test/files/bode-v1.xls.zip +0 -0
  139. data/test/files/boolean.csv +0 -2
  140. data/test/files/boolean.ods +0 -0
  141. data/test/files/boolean.xls +0 -0
  142. data/test/files/boolean.xlsx +0 -0
  143. data/test/files/boolean.xml +0 -112
  144. data/test/files/borders.ods +0 -0
  145. data/test/files/borders.xls +0 -0
  146. data/test/files/borders.xlsx +0 -0
  147. data/test/files/borders.xml +0 -144
  148. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  149. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  150. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  151. data/test/files/comments.ods +0 -0
  152. data/test/files/comments.xls +0 -0
  153. data/test/files/comments.xlsx +0 -0
  154. data/test/files/csvtypes.csv +0 -1
  155. data/test/files/datetime.ods +0 -0
  156. data/test/files/datetime.xls +0 -0
  157. data/test/files/datetime.xlsx +0 -0
  158. data/test/files/datetime.xml +0 -142
  159. data/test/files/datetime_floatconv.xls +0 -0
  160. data/test/files/datetime_floatconv.xml +0 -148
  161. data/test/files/dreimalvier.ods +0 -0
  162. data/test/files/emptysheets.ods +0 -0
  163. data/test/files/emptysheets.xls +0 -0
  164. data/test/files/emptysheets.xlsx +0 -0
  165. data/test/files/emptysheets.xml +0 -105
  166. data/test/files/excel2003.xml +0 -21140
  167. data/test/files/false_encoding.xls +0 -0
  168. data/test/files/false_encoding.xml +0 -132
  169. data/test/files/file_item_error.xlsx +0 -0
  170. data/test/files/formula.ods +0 -0
  171. data/test/files/formula.xls +0 -0
  172. data/test/files/formula.xlsx +0 -0
  173. data/test/files/formula.xml +0 -134
  174. data/test/files/formula_parse_error.xls +0 -0
  175. data/test/files/formula_parse_error.xml +0 -1833
  176. data/test/files/formula_string_error.xlsx +0 -0
  177. data/test/files/html-escape.ods +0 -0
  178. data/test/files/link.xls +0 -0
  179. data/test/files/link.xlsx +0 -0
  180. data/test/files/matrix.ods +0 -0
  181. data/test/files/matrix.xls +0 -0
  182. data/test/files/named_cells.ods +0 -0
  183. data/test/files/named_cells.xls +0 -0
  184. data/test/files/named_cells.xlsx +0 -0
  185. data/test/files/no_spreadsheet_file.txt +0 -1
  186. data/test/files/numbers1.csv +0 -18
  187. data/test/files/numbers1.ods +0 -0
  188. data/test/files/numbers1.xls +0 -0
  189. data/test/files/numbers1.xlsx +0 -0
  190. data/test/files/numbers1.xml +0 -312
  191. data/test/files/numeric-link.xlsx +0 -0
  192. data/test/files/only_one_sheet.ods +0 -0
  193. data/test/files/only_one_sheet.xls +0 -0
  194. data/test/files/only_one_sheet.xlsx +0 -0
  195. data/test/files/only_one_sheet.xml +0 -67
  196. data/test/files/paragraph.ods +0 -0
  197. data/test/files/paragraph.xls +0 -0
  198. data/test/files/paragraph.xlsx +0 -0
  199. data/test/files/paragraph.xml +0 -127
  200. data/test/files/prova.xls +0 -0
  201. data/test/files/ric.ods +0 -0
  202. data/test/files/simple_spreadsheet.ods +0 -0
  203. data/test/files/simple_spreadsheet.xls +0 -0
  204. data/test/files/simple_spreadsheet.xlsx +0 -0
  205. data/test/files/simple_spreadsheet.xml +0 -225
  206. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  207. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  208. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  209. data/test/files/so_datetime.csv +0 -7
  210. data/test/files/style.ods +0 -0
  211. data/test/files/style.xls +0 -0
  212. data/test/files/style.xlsx +0 -0
  213. data/test/files/style.xml +0 -154
  214. data/test/files/time-test.csv +0 -2
  215. data/test/files/time-test.ods +0 -0
  216. data/test/files/time-test.xls +0 -0
  217. data/test/files/time-test.xlsx +0 -0
  218. data/test/files/time-test.xml +0 -131
  219. data/test/files/type_excel.ods +0 -0
  220. data/test/files/type_excel.xlsx +0 -0
  221. data/test/files/type_excelx.ods +0 -0
  222. data/test/files/type_excelx.xls +0 -0
  223. data/test/files/type_openoffice.xls +0 -0
  224. data/test/files/type_openoffice.xlsx +0 -0
  225. data/test/files/whitespace.ods +0 -0
  226. data/test/files/whitespace.xls +0 -0
  227. data/test/files/whitespace.xlsx +0 -0
  228. data/test/files/whitespace.xml +0 -184
  229. data/test/rm_sub_test.rb +0 -12
  230. data/test/rm_test.rb +0 -7
  231. data/test/test_generic_spreadsheet.rb +0 -259
  232. data/website/index.html +0 -385
  233. data/website/index.txt +0 -423
  234. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  235. data/website/stylesheets/screen.css +0 -130
  236. data/website/template.rhtml +0 -48
@@ -0,0 +1,81 @@
1
+ # Tests for "Accessing Files" which includes opening and closing files.
2
+ module TestAccesingFiles
3
+ def test_close
4
+ with_each_spreadsheet(name: "numbers1") do |oo|
5
+ next unless (tempdir = oo.instance_variable_get("@tmpdir"))
6
+ oo.close
7
+ refute File.exist?(tempdir), "Expected #{tempdir} to be cleaned up"
8
+ end
9
+ end
10
+
11
+ # NOTE: Ruby 2.4.0 changed the way GC works. The last Roo object created by
12
+ # with_each_spreadsheet wasn't getting GC'd until after the process
13
+ # ended.
14
+ #
15
+ # That behavior change broke this test. In order to fix it, I forked the
16
+ # process and passed the temp directories from the forked process in
17
+ # order to check if they were removed properly.
18
+ def test_finalize
19
+ skip if defined? JRUBY_VERSION
20
+
21
+ read, write = IO.pipe
22
+ pid = Process.fork do
23
+ with_each_spreadsheet(name: "numbers1") do |oo|
24
+ write.puts oo.instance_variable_get("@tmpdir")
25
+ end
26
+ end
27
+
28
+ Process.wait(pid)
29
+ write.close
30
+ tempdirs = read.read.split("\n")
31
+ read.close
32
+
33
+ refute tempdirs.empty?
34
+ tempdirs.each do |tempdir|
35
+ refute File.exist?(tempdir), "Expected #{tempdir} to be cleaned up"
36
+ end
37
+ end
38
+
39
+ def test_finalize_twice
40
+ skip if defined? JRUBY_VERSION
41
+
42
+ instance = Class.new { include Roo::Tempdir }.new
43
+
44
+ tempdir = instance.make_tempdir(instance, "my_temp_prefix", nil)
45
+ assert File.exist?(tempdir), "Expected #{tempdir} to initially exist"
46
+
47
+ pid = Process.fork do
48
+ # Inside the forked process finalize does not affect the parent process's state, but does
49
+ # delete the tempfile on disk
50
+ instance.finalize_tempdirs(instance.object_id)
51
+ end
52
+
53
+ Process.wait(pid)
54
+ refute File.exist?(tempdir), "Expected #{tempdir} to have been cleaned up by child process"
55
+
56
+ instance.finalize_tempdirs(instance.object_id)
57
+ refute File.exist?(tempdir), "Expected #{tempdir} to still have been cleaned up"
58
+ end
59
+
60
+ def test_cleanup_on_error
61
+ # NOTE: This test was occasionally failing because when it started running
62
+ # other tests would have already added folders to the temp directory,
63
+ # polluting the directory. You'd end up in a situation where there
64
+ # would be less folders AFTER this ran than originally started.
65
+ #
66
+ # Instead, just use a custom temp directory to test the functionality.
67
+ ENV["ROO_TMP"] = Dir.tmpdir + "/test_cleanup_on_error"
68
+ Dir.mkdir(ENV["ROO_TMP"]) unless File.exist?(ENV["ROO_TMP"])
69
+ expected_dir_contents = Dir.open(ENV["ROO_TMP"]).to_a
70
+ with_each_spreadsheet(name: "non_existent_file", ignore_errors: true) {}
71
+
72
+ assert_equal expected_dir_contents, Dir.open(ENV["ROO_TMP"]).to_a
73
+ Dir.rmdir ENV["ROO_TMP"] if File.exist?(ENV["ROO_TMP"])
74
+ ENV.delete "ROO_TMP"
75
+ end
76
+
77
+ def test_name_with_leading_slash
78
+ xlsx = Roo::Excelx.new(File.join(TESTDIR, "/name_with_leading_slash.xlsx"))
79
+ assert_equal 1, xlsx.sheets.count
80
+ end
81
+ end
@@ -0,0 +1,43 @@
1
+ module TestComments
2
+ def test_comment
3
+ options = { name: "comments", format: [:openoffice, :libreoffice, :excelx] }
4
+ with_each_spreadsheet(options) do |oo|
5
+ assert_equal "Kommentar fuer B4", oo.comment("b", 4)
6
+ assert_equal "Kommentar fuer B5", oo.comment("b", 5)
7
+ end
8
+ end
9
+
10
+ def test_no_comment
11
+ options = { name: "comments", format: [:openoffice, :excelx] }
12
+ with_each_spreadsheet(options) do |oo|
13
+ # There are no comments at the second sheet.
14
+ assert_nil oo.comment("b", 4, oo.sheets[1])
15
+ end
16
+ end
17
+
18
+ def test_comments
19
+ options = { name: "comments", format: [:openoffice, :libreoffice, :excelx] }
20
+ expexted_comments = [
21
+ [4, 2, "Kommentar fuer B4"],
22
+ [5, 2, "Kommentar fuer B5"],
23
+ ]
24
+
25
+ with_each_spreadsheet(options) do |oo|
26
+ assert_equal expexted_comments, oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
27
+ end
28
+ end
29
+
30
+ def test_empty_sheet_comments
31
+ options = { name: "emptysheets", format: [:openoffice, :excelx] }
32
+ with_each_spreadsheet(options) do |oo|
33
+ assert_equal [], oo.comments, "An empty sheet's formulas should be an empty array"
34
+ end
35
+ end
36
+
37
+ def test_comments_from_google_sheet_exported_as_xlsx
38
+ expected_comments = [[1, 1, "this is a comment\n\t-Steven Daniels"]]
39
+ with_each_spreadsheet(name: "comments-google", format: [:excelx]) do |oo|
40
+ assert_equal expected_comments, oo.comments(oo.sheets.first), "comments error in class #{oo.class}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module TestFormulas
2
+ def test_empty_sheet_formulas
3
+ options = { name: "emptysheets", format: [:openoffice, :excelx] }
4
+ with_each_spreadsheet(options) do |oo|
5
+ oo.default_sheet = oo.sheets.first
6
+ assert_equal [], oo.formulas, "An empty sheet's formulas should be an empty array"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,103 @@
1
+ module TestLabels
2
+ def test_labels
3
+ options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
4
+ expected_labels = [
5
+ ["anton", [5, 3, "Sheet1"]],
6
+ ["berta", [4, 2, "Sheet1"]],
7
+ ["caesar", [7, 2, "Sheet1"]],
8
+ ]
9
+ with_each_spreadsheet(options) do |oo|
10
+ assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
11
+ end
12
+ end
13
+
14
+ def test_labeled_cells
15
+ options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
16
+ with_each_spreadsheet(options) do |oo|
17
+ oo.default_sheet = oo.sheets.first
18
+ begin
19
+ row, col = oo.label("anton")
20
+ rescue ArgumentError
21
+ puts "labels error at #{oo.class}"
22
+ raise
23
+ end
24
+ assert_equal 5, row
25
+ assert_equal 3, col
26
+
27
+ row, col = oo.label("anton")
28
+ assert_equal "Anton", oo.cell(row, col)
29
+
30
+ row, col = oo.label("berta")
31
+ assert_equal "Bertha", oo.cell(row, col)
32
+
33
+ row, col = oo.label("caesar")
34
+ assert_equal "Cäsar", oo.cell(row, col)
35
+
36
+ row, col = oo.label("never")
37
+ assert_nil row
38
+ assert_nil col
39
+
40
+ row, col, sheet = oo.label("anton")
41
+ assert_equal 5, row
42
+ assert_equal 3, col
43
+ assert_equal "Sheet1", sheet
44
+
45
+ assert_equal "Anton", oo.anton
46
+ assert_raises(NoMethodError) do
47
+ row, col = oo.never
48
+ end
49
+
50
+ # Reihenfolge row, col,sheet analog zu #label
51
+ expected_labels = [
52
+ ["anton", [5, 3, "Sheet1"]],
53
+ ["berta", [4, 2, "Sheet1"]],
54
+ ["caesar", [7, 2, "Sheet1"]],
55
+ ]
56
+ assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
57
+ end
58
+ end
59
+
60
+ def test_label
61
+ options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
62
+ with_each_spreadsheet(options) do |oo|
63
+ begin
64
+ row, col = oo.label("anton")
65
+ rescue ArgumentError
66
+ puts "labels error at #{oo.class}"
67
+ raise
68
+ end
69
+
70
+ assert_equal 5, row, "error with label in class #{oo.class}"
71
+ assert_equal 3, col, "error with label in class #{oo.class}"
72
+
73
+ row, col = oo.label("anton")
74
+ assert_equal "Anton", oo.cell(row, col), "error with label in class #{oo.class}"
75
+
76
+ row, col = oo.label("berta")
77
+ assert_equal "Bertha", oo.cell(row, col), "error with label in class #{oo.class}"
78
+
79
+ row, col = oo.label("caesar")
80
+ assert_equal "Cäsar", oo.cell(row, col), "error with label in class #{oo.class}"
81
+
82
+ row, col = oo.label("never")
83
+ assert_nil row
84
+ assert_nil col
85
+
86
+ row, col, sheet = oo.label("anton")
87
+ assert_equal 5, row
88
+ assert_equal 3, col
89
+ assert_equal "Sheet1", sheet
90
+ end
91
+ end
92
+
93
+ def test_method_missing_anton
94
+ options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
95
+ with_each_spreadsheet(options) do |oo|
96
+ # oo.default_sheet = oo.sheets.first
97
+ assert_equal "Anton", oo.anton
98
+ assert_raises(NoMethodError) do
99
+ oo.never
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,55 @@
1
+ # NOTE: Putting these tests into modules in order to share them across different
2
+ # test classes, i.e. both TestRooExcelx and TestRooOpenOffice should run
3
+ # sheet related tests.
4
+ #
5
+ # This will allow me to reuse these test cases when I add new classes for
6
+ # Roo's future API.
7
+ # Sheet related tests
8
+ module TestSheets
9
+ def test_sheets
10
+ sheet_names = ["Tabelle1", "Name of Sheet 2", "Sheet3", "Sheet4", "Sheet5"]
11
+ with_each_spreadsheet(name: "numbers1") do |oo|
12
+ assert_equal sheet_names, oo.sheets
13
+ assert_raises(RangeError) { oo.default_sheet = "no_sheet" }
14
+ assert_raises(TypeError) { oo.default_sheet = [1, 2, 3] }
15
+ oo.sheets.each do |sheet_name|
16
+ oo.default_sheet = sheet_name
17
+ assert_equal sheet_name, oo.default_sheet
18
+ end
19
+ end
20
+ end
21
+
22
+ def test_sheetname
23
+ bad_sheet_name = "non existing sheet name"
24
+ with_each_spreadsheet(name: "numbers1") do |oo|
25
+ oo.default_sheet = "Name of Sheet 2"
26
+ assert_equal "I am sheet 2", oo.cell("C", 5)
27
+ assert_raises(RangeError) { oo.default_sheet = bad_sheet_name }
28
+ assert_raises(RangeError) { oo.default_sheet = bad_sheet_name }
29
+ assert_raises(RangeError) { oo.cell("C", 5, bad_sheet_name) }
30
+ assert_raises(RangeError) { oo.celltype("C", 5, bad_sheet_name) }
31
+ assert_raises(RangeError) { oo.empty?("C", 5, bad_sheet_name) }
32
+ assert_raises(RangeError) { oo.formula?("C", 5, bad_sheet_name) }
33
+ assert_raises(RangeError) { oo.formula("C", 5, bad_sheet_name) }
34
+ assert_raises(RangeError) { oo.set("C", 5, 42, bad_sheet_name) }
35
+ assert_raises(RangeError) { oo.formulas(bad_sheet_name) }
36
+ assert_raises(RangeError) { oo.to_yaml({}, 1, 1, 1, 1, bad_sheet_name) }
37
+ end
38
+ end
39
+
40
+ def test_info_doesnt_set_default_sheet
41
+ sheet_name = "Sheet3"
42
+ with_each_spreadsheet(name: "numbers1") do |oo|
43
+ oo.default_sheet = sheet_name
44
+ oo.info
45
+ assert_equal sheet_name, oo.default_sheet
46
+ end
47
+ end
48
+
49
+ def test_bug_numbered_sheet_names
50
+ options = { name: "bug-numbered-sheet-names", format: :excelx }
51
+ with_each_spreadsheet(options) do |oo|
52
+ oo.each_with_pagename {}
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ module TestStyles
2
+ def test_cell_styles
3
+ # styles only valid in excel spreadsheets?
4
+ # TODO: what todo with other spreadsheet types
5
+ with_each_spreadsheet(name: "style", format: [:excelx]) do |oo|
6
+ # bold
7
+ assert_equal true, oo.font(1, 1).bold?
8
+ assert_equal false, oo.font(1, 1).italic?
9
+ assert_equal false, oo.font(1, 1).underline?
10
+
11
+ # italic
12
+ assert_equal false, oo.font(2, 1).bold?
13
+ assert_equal true, oo.font(2, 1).italic?
14
+ assert_equal false, oo.font(2, 1).underline?
15
+
16
+ # normal
17
+ assert_equal false, oo.font(3, 1).bold?
18
+ assert_equal false, oo.font(3, 1).italic?
19
+ assert_equal false, oo.font(3, 1).underline?
20
+
21
+ # underline
22
+ assert_equal false, oo.font(4, 1).bold?
23
+ assert_equal false, oo.font(4, 1).italic?
24
+ assert_equal true, oo.font(4, 1).underline?
25
+
26
+ # bold italic
27
+ assert_equal true, oo.font(5, 1).bold?
28
+ assert_equal true, oo.font(5, 1).italic?
29
+ assert_equal false, oo.font(5, 1).underline?
30
+
31
+ # bold underline
32
+ assert_equal true, oo.font(6, 1).bold?
33
+ assert_equal false, oo.font(6, 1).italic?
34
+ assert_equal true, oo.font(6, 1).underline?
35
+
36
+ # italic underline
37
+ assert_equal false, oo.font(7, 1).bold?
38
+ assert_equal true, oo.font(7, 1).italic?
39
+ assert_equal true, oo.font(7, 1).underline?
40
+
41
+ # bolded row
42
+ assert_equal true, oo.font(8, 1).bold?
43
+ assert_equal false, oo.font(8, 1).italic?
44
+ assert_equal false, oo.font(8, 1).underline?
45
+
46
+ # bolded col
47
+ assert_equal true, oo.font(9, 2).bold?
48
+ assert_equal false, oo.font(9, 2).italic?
49
+ assert_equal false, oo.font(9, 2).underline?
50
+
51
+ # bolded row, italic col
52
+ assert_equal true, oo.font(10, 3).bold?
53
+ assert_equal true, oo.font(10, 3).italic?
54
+ assert_equal false, oo.font(10, 3).underline?
55
+
56
+ # normal
57
+ assert_equal false, oo.font(11, 4).bold?
58
+ assert_equal false, oo.font(11, 4).italic?
59
+ assert_equal false, oo.font(11, 4).underline?
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,182 @@
1
+ require "test_helper"
2
+
3
+ class TestRooBase < Minitest::Test
4
+ def test_info
5
+ # NOTE: unfortunately, the ods and xlsx versions of numbers1 are not
6
+ # identical, so this test fails for Open Office.
7
+ expected_templ = File.read("#{TESTDIR}/expected_results/numbers_info.yml")
8
+ with_each_spreadsheet(name: "numbers1", format: [:excelx]) do |workbook|
9
+ ext = get_extension(workbook)
10
+ expected = Kernel.format(expected_templ, ext)
11
+ assert_equal expected.strip, workbook.info.strip
12
+ end
13
+ end
14
+
15
+ def test_column
16
+ with_each_spreadsheet(name: "numbers1") do |workbook|
17
+ expected = [1.0, 5.0, nil, 10.0, Date.new(1961, 11, 21), "tata", nil, nil, nil, nil, "thisisa11", 41.0, nil, nil, 41.0, "einundvierzig", nil, Date.new(2007, 5, 31)]
18
+ assert_equal expected, workbook.column(1)
19
+ assert_equal expected, workbook.column("a")
20
+ end
21
+ end
22
+
23
+ def test_column_huge_document
24
+ skip_long_test
25
+ with_each_spreadsheet(name: "Bibelbund", format: [:openoffice, :excelx]) do |workbook|
26
+ workbook.default_sheet = workbook.sheets.first
27
+ assert_equal 3735, workbook.column("a").size
28
+ end
29
+ end
30
+
31
+ def test_simple_spreadsheet_find_by_condition
32
+ with_each_spreadsheet(name: "simple_spreadsheet") do |workbook|
33
+ workbook.header_line = 3
34
+ results = workbook.find(:all, conditions: { "Comment" => "Task 1" })
35
+ assert_equal Date.new(2007, 05, 07), results[1]["Date"]
36
+ assert_equal 10.75, results[1]["Start time"]
37
+ assert_equal 12.50, results[1]["End time"]
38
+ assert_equal 0, results[1]["Pause"]
39
+ assert_equal 1.75, results[1]["Sum"]
40
+ assert_equal "Task 1", results[1]["Comment"]
41
+ end
42
+ end
43
+
44
+ def test_bug_bbu
45
+ expected_templ = File.read("#{TESTDIR}/expected_results/bbu_info.txt")
46
+ with_each_spreadsheet(name: "bbu", format: [:openoffice, :excelx]) do |workbook|
47
+ ext = get_extension(workbook)
48
+ expected_result = Kernel.format(expected_templ, ext)
49
+ assert_equal expected_result.strip, workbook.info.strip
50
+
51
+ workbook.default_sheet = workbook.sheets[1] # empty sheet
52
+ assert_nil workbook.first_row
53
+ assert_nil workbook.last_row
54
+ assert_nil workbook.first_column
55
+ assert_nil workbook.last_column
56
+ end
57
+ end
58
+
59
+ def test_find_by_row_huge_document
60
+ skip_long_test
61
+ options = { name: "Bibelbund", format: [:openoffice, :excelx] }
62
+ with_each_spreadsheet(options) do |workbook|
63
+ workbook.default_sheet = workbook.sheets.first
64
+ result = workbook.find 20
65
+ assert result
66
+ assert_equal "Brief aus dem Sekretariat", result[0]
67
+
68
+ result = workbook.find 22
69
+ assert result
70
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.", result[0]
71
+ end
72
+ end
73
+
74
+ def test_find_by_row
75
+ with_each_spreadsheet(name: "numbers1") do |workbook|
76
+ workbook.header_line = nil
77
+ result = workbook.find 16
78
+ assert result
79
+ assert_nil workbook.header_line
80
+ # keine Headerlines in diesem Beispiel definiert
81
+ assert_equal "einundvierzig", result[0]
82
+ # assert_equal false, results
83
+ result = workbook.find 15
84
+ assert result
85
+ assert_equal 41, result[0]
86
+ end
87
+ end
88
+
89
+ def test_find_by_row_if_header_line_is_not_nil
90
+ with_each_spreadsheet(name: "numbers1") do |workbook|
91
+ workbook.header_line = 2
92
+ refute_nil workbook.header_line
93
+ results = workbook.find 1
94
+ assert results
95
+ assert_equal 5, results[0]
96
+ assert_equal 6, results[1]
97
+ results = workbook.find 15
98
+ assert results
99
+ assert_equal "einundvierzig", results[0]
100
+ end
101
+ end
102
+
103
+ def test_find_by_conditions
104
+ skip_long_test
105
+ expected_results = [
106
+ {
107
+ "VERFASSER" => "Almassy, Annelene von",
108
+ "INTERNET" => nil,
109
+ "SEITE" => 316.0,
110
+ "KENNUNG" => "Aus dem Bibelbund",
111
+ "OBJEKT" => "Bibel+Gem",
112
+ "PC" => "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
113
+ "NUMMER" => "1982-3",
114
+ "TITEL" => "Brief aus dem Sekretariat"
115
+ },
116
+ {
117
+ "VERFASSER" => "Almassy, Annelene von",
118
+ "INTERNET" => nil,
119
+ "SEITE" => 222.0,
120
+ "KENNUNG" => "Aus dem Bibelbund",
121
+ "OBJEKT" => "Bibel+Gem",
122
+ "PC" => "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
123
+ "NUMMER" => "1983-2",
124
+ "TITEL" => "Brief aus dem Sekretariat"
125
+ }
126
+ ]
127
+
128
+ expected_results_size = 2
129
+ options = { name: "Bibelbund", format: [:openoffice, :excelx] }
130
+ with_each_spreadsheet(options) do |workbook|
131
+ results = workbook.find(:all, conditions: { "TITEL" => "Brief aus dem Sekretariat" })
132
+ assert_equal expected_results_size, results.size
133
+ assert_equal expected_results, results
134
+
135
+ conditions = {
136
+ "TITEL" => "Brief aus dem Sekretariat",
137
+ "VERFASSER" => "Almassy, Annelene von"
138
+ }
139
+ results = workbook.find(:all, conditions: conditions)
140
+ assert_equal expected_results, results
141
+ assert_equal expected_results_size, results.size
142
+
143
+ results = workbook.find(:all, conditions: { "VERFASSER" => "Almassy, Annelene von" })
144
+ assert_equal 13, results.size
145
+ end
146
+ end
147
+
148
+ def test_find_by_conditions_with_array_option
149
+ expected_results = [
150
+ [
151
+ "Brief aus dem Sekretariat",
152
+ "Almassy, Annelene von",
153
+ "Bibel+Gem",
154
+ "1982-3",
155
+ 316.0,
156
+ nil,
157
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
158
+ "Aus dem Bibelbund",
159
+ ],
160
+ [
161
+ "Brief aus dem Sekretariat",
162
+ "Almassy, Annelene von",
163
+ "Bibel+Gem",
164
+ "1983-2",
165
+ 222.0,
166
+ nil,
167
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
168
+ "Aus dem Bibelbund",
169
+ ]
170
+ ]
171
+ options = { name: "Bibelbund", format: [:openoffice, :excelx] }
172
+ with_each_spreadsheet(options) do |workbook|
173
+ conditions = {
174
+ "TITEL" => "Brief aus dem Sekretariat",
175
+ "VERFASSER" => "Almassy, Annelene von"
176
+ }
177
+ results = workbook.find(:all, conditions: conditions, array: true)
178
+ assert_equal 2, results.size
179
+ assert_equal expected_results, results
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,88 @@
1
+ require "test_helper"
2
+
3
+ class TestRooCSV < Minitest::Test
4
+ def test_sheets
5
+ file = filename("numbers1")
6
+ workbook = roo_class.new(File.join(TESTDIR, file))
7
+ assert_equal ["default"], workbook.sheets
8
+ assert_raises(RangeError) { workbook.default_sheet = "no_sheet" }
9
+ assert_raises(TypeError) { workbook.default_sheet = [1, 2, 3] }
10
+ workbook.sheets.each do |sh|
11
+ workbook.default_sheet = sh
12
+ assert_equal sh, workbook.default_sheet
13
+ end
14
+ end
15
+
16
+ def test_download_uri_with_query_string
17
+ file = filename("simple_spreadsheet")
18
+ port = 12_347
19
+ url = "#{local_server(port)}/#{file}?query-param=value"
20
+
21
+ start_local_server(file, port) do
22
+ csv = roo_class.new(url)
23
+ assert_equal "Task 1", csv.cell("f", 4)
24
+ assert_equal 1, csv.first_row
25
+ assert_equal 13, csv.last_row
26
+ assert_equal 1, csv.first_column
27
+ assert_equal 6, csv.last_column
28
+ end
29
+ end
30
+
31
+ def test_open_stream
32
+ file = filename("Bibelbund")
33
+ file_contents = File.read File.join(TESTDIR, file)
34
+ stream = StringIO.new(file_contents)
35
+ csv = roo_class.new(stream)
36
+
37
+ assert_equal "Aktuelle Seite", csv.cell("h", 12)
38
+ assert_equal 1, csv.first_row
39
+ assert_equal 3735, csv.last_row
40
+ assert_equal 1, csv.first_column
41
+ assert_equal 8, csv.last_column
42
+ end
43
+
44
+ def test_nil_rows_and_lines_csv
45
+ # x_123
46
+ oo = Roo::CSV.new(File.join(TESTDIR,'Bibelbund.csv'))
47
+ oo.default_sheet = oo.sheets.first
48
+ assert_equal 1, oo.first_row
49
+ assert_equal 3735, oo.last_row
50
+ assert_equal 1, oo.first_column
51
+ assert_equal 8, oo.last_column
52
+ end
53
+
54
+ def test_empty_csv
55
+ # x_123
56
+ oo = Roo::CSV.new(File.join(TESTDIR,'emptysheets.csv'))
57
+ oo.default_sheet = oo.sheets.first
58
+ assert_equal 1, oo.first_row
59
+ assert_equal 1, oo.last_row
60
+ assert_equal 1, oo.first_column
61
+ assert_equal 1, oo.last_column
62
+ end
63
+
64
+ def test_csv_parsing_with_headers
65
+ return unless CSV
66
+ headers = ["TITEL", "VERFASSER", "OBJEKT", "NUMMER", "SEITE", "INTERNET", "PC", "KENNUNG"]
67
+
68
+ oo = Roo::Spreadsheet.open(File.join(TESTDIR, "Bibelbund.csv"))
69
+ parsed = oo.parse(headers: true)
70
+ assert_equal headers, parsed[1].keys
71
+ end
72
+
73
+ def test_iso_8859_1
74
+ file = File.open(File.join(TESTDIR, "iso_8859_1.csv"))
75
+ options = { csv_options: { col_sep: ";", encoding: Encoding::ISO_8859_1 } }
76
+ workbook = Roo::CSV.new(file.path, options)
77
+ result = workbook.last_column
78
+ assert_equal(19, result)
79
+ end
80
+
81
+ def roo_class
82
+ Roo::CSV
83
+ end
84
+
85
+ def filename(name)
86
+ "#{name}.csv"
87
+ end
88
+ end