roo 2.3.0 → 2.10.1
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 +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +16 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/pull-request.yml +15 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +186 -0
- data/CHANGELOG.md +148 -0
- data/Gemfile +4 -4
- data/LICENSE +2 -0
- data/README.md +84 -27
- data/Rakefile +1 -1
- data/lib/roo/base.rb +111 -237
- data/lib/roo/constants.rb +5 -3
- data/lib/roo/csv.rb +106 -85
- data/lib/roo/errors.rb +2 -0
- data/lib/roo/excelx/cell/base.rb +26 -12
- data/lib/roo/excelx/cell/boolean.rb +9 -6
- data/lib/roo/excelx/cell/date.rb +7 -7
- data/lib/roo/excelx/cell/datetime.rb +50 -44
- data/lib/roo/excelx/cell/empty.rb +3 -2
- data/lib/roo/excelx/cell/number.rb +60 -47
- data/lib/roo/excelx/cell/string.rb +3 -3
- data/lib/roo/excelx/cell/time.rb +17 -16
- data/lib/roo/excelx/cell.rb +11 -7
- data/lib/roo/excelx/comments.rb +3 -3
- data/lib/roo/excelx/coordinate.rb +11 -4
- data/lib/roo/excelx/extractor.rb +20 -3
- data/lib/roo/excelx/format.rb +38 -31
- data/lib/roo/excelx/images.rb +26 -0
- data/lib/roo/excelx/relationships.rb +12 -4
- data/lib/roo/excelx/shared.rb +10 -3
- data/lib/roo/excelx/shared_strings.rb +113 -9
- data/lib/roo/excelx/sheet.rb +49 -10
- data/lib/roo/excelx/sheet_doc.rb +101 -48
- data/lib/roo/excelx/styles.rb +4 -4
- data/lib/roo/excelx/workbook.rb +8 -3
- data/lib/roo/excelx.rb +85 -42
- data/lib/roo/formatters/base.rb +15 -0
- data/lib/roo/formatters/csv.rb +84 -0
- data/lib/roo/formatters/matrix.rb +23 -0
- data/lib/roo/formatters/xml.rb +31 -0
- data/lib/roo/formatters/yaml.rb +40 -0
- data/lib/roo/helpers/default_attr_reader.rb +20 -0
- data/lib/roo/helpers/weak_instance_cache.rb +41 -0
- data/lib/roo/open_office.rb +41 -27
- data/lib/roo/spreadsheet.rb +8 -2
- data/lib/roo/tempdir.rb +24 -0
- data/lib/roo/utils.rb +76 -26
- data/lib/roo/version.rb +1 -1
- data/lib/roo.rb +5 -0
- data/roo.gemspec +22 -12
- data/spec/lib/roo/base_spec.rb +65 -3
- data/spec/lib/roo/csv_spec.rb +19 -0
- data/spec/lib/roo/excelx/cell/time_spec.rb +15 -0
- data/spec/lib/roo/excelx/relationships_spec.rb +43 -0
- data/spec/lib/roo/excelx/sheet_doc_spec.rb +11 -0
- data/spec/lib/roo/excelx_spec.rb +237 -5
- data/spec/lib/roo/openoffice_spec.rb +2 -2
- data/spec/lib/roo/spreadsheet_spec.rb +1 -1
- data/spec/lib/roo/strict_spec.rb +43 -0
- data/spec/lib/roo/utils_spec.rb +22 -9
- data/spec/lib/roo/weak_instance_cache_spec.rb +92 -0
- data/spec/lib/roo_spec.rb +0 -0
- data/spec/spec_helper.rb +2 -7
- data/test/excelx/cell/test_attr_reader_default.rb +72 -0
- data/test/excelx/cell/test_base.rb +6 -2
- data/test/excelx/cell/test_boolean.rb +1 -3
- data/test/excelx/cell/test_date.rb +1 -6
- data/test/excelx/cell/test_datetime.rb +7 -10
- data/test/excelx/cell/test_empty.rb +12 -2
- data/test/excelx/cell/test_number.rb +28 -4
- data/test/excelx/cell/test_string.rb +21 -3
- data/test/excelx/cell/test_time.rb +7 -10
- data/test/excelx/test_coordinate.rb +51 -0
- data/test/formatters/test_csv.rb +136 -0
- data/test/formatters/test_matrix.rb +76 -0
- data/test/formatters/test_xml.rb +78 -0
- data/test/formatters/test_yaml.rb +20 -0
- data/test/helpers/test_accessing_files.rb +81 -0
- data/test/helpers/test_comments.rb +43 -0
- data/test/helpers/test_formulas.rb +9 -0
- data/test/helpers/test_labels.rb +103 -0
- data/test/helpers/test_sheets.rb +55 -0
- data/test/helpers/test_styles.rb +62 -0
- data/test/roo/test_base.rb +182 -0
- data/test/roo/test_csv.rb +88 -0
- data/test/roo/test_excelx.rb +360 -0
- data/test/roo/test_libre_office.rb +9 -0
- data/test/roo/test_open_office.rb +289 -0
- data/test/test_helper.rb +129 -14
- data/test/test_roo.rb +60 -1765
- metadata +91 -21
- data/.travis.yml +0 -14
@@ -0,0 +1,76 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "matrix"
|
3
|
+
|
4
|
+
class TestRooFormatterMatrix < Minitest::Test
|
5
|
+
def test_matrix
|
6
|
+
expected_result = Matrix[
|
7
|
+
[1.0, 2.0, 3.0],
|
8
|
+
[4.0, 5.0, 6.0],
|
9
|
+
[7.0, 8.0, 9.0]
|
10
|
+
]
|
11
|
+
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
|
12
|
+
workbook.default_sheet = workbook.sheets.first
|
13
|
+
assert_equal expected_result, workbook.to_matrix
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_matrix_selected_range
|
18
|
+
expected_result = Matrix[
|
19
|
+
[1.0, 2.0, 3.0],
|
20
|
+
[4.0, 5.0, 6.0],
|
21
|
+
[7.0, 8.0, 9.0]
|
22
|
+
]
|
23
|
+
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
|
24
|
+
workbook.default_sheet = "Sheet2"
|
25
|
+
assert_equal expected_result, workbook.to_matrix(3, 4, 5, 6)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_matrix_all_nil
|
30
|
+
expected_result = Matrix[
|
31
|
+
[nil, nil, nil],
|
32
|
+
[nil, nil, nil],
|
33
|
+
[nil, nil, nil]
|
34
|
+
]
|
35
|
+
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
|
36
|
+
workbook.default_sheet = "Sheet2"
|
37
|
+
assert_equal expected_result, workbook.to_matrix(10, 10, 12, 12)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_matrix_values_and_nil
|
42
|
+
expected_result = Matrix[
|
43
|
+
[1.0, nil, 3.0],
|
44
|
+
[4.0, 5.0, 6.0],
|
45
|
+
[7.0, 8.0, nil]
|
46
|
+
]
|
47
|
+
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
|
48
|
+
workbook.default_sheet = "Sheet3"
|
49
|
+
assert_equal expected_result, workbook.to_matrix(1, 1, 3, 3)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_matrix_specifying_sheet
|
54
|
+
expected_result = Matrix[
|
55
|
+
[1.0, nil, 3.0],
|
56
|
+
[4.0, 5.0, 6.0],
|
57
|
+
[7.0, 8.0, nil]
|
58
|
+
]
|
59
|
+
with_each_spreadsheet(name: "matrix", format: :openoffice) do |workbook|
|
60
|
+
workbook.default_sheet = workbook.sheets.first
|
61
|
+
assert_equal expected_result, workbook.to_matrix(nil, nil, nil, nil, "Sheet3")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# #to_matrix of an empty sheet should return an empty matrix and not result in
|
66
|
+
# an error message
|
67
|
+
# 2011-06-25
|
68
|
+
def test_bug_to_matrix_empty_sheet
|
69
|
+
options = { name: "emptysheets", format: [:openoffice, :excelx] }
|
70
|
+
with_each_spreadsheet(options) do |workbook|
|
71
|
+
workbook.default_sheet = workbook.sheets.first
|
72
|
+
workbook.to_matrix
|
73
|
+
assert_equal(Matrix.empty(0, 0), workbook.to_matrix)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRooFormatterXML < Minitest::Test
|
4
|
+
def test_to_xml
|
5
|
+
expected_sheet_count = 5
|
6
|
+
options = { name: "numbers1", encoding: "utf8" }
|
7
|
+
with_each_spreadsheet(options) do |workbook|
|
8
|
+
skip if defined? JRUBY_VERSION
|
9
|
+
workbook.to_xml
|
10
|
+
sheetname = workbook.sheets.first
|
11
|
+
doc = Nokogiri::XML(workbook.to_xml)
|
12
|
+
|
13
|
+
assert_equal expected_sheet_count, doc.xpath("//spreadsheet/sheet").count
|
14
|
+
|
15
|
+
doc.xpath("//spreadsheet/sheet").each do |xml_sheet|
|
16
|
+
all_cells = init_all_cells(workbook, sheetname)
|
17
|
+
cells = xml_sheet.children.reject(&:text?)
|
18
|
+
|
19
|
+
assert_equal sheetname, xml_sheet["name"]
|
20
|
+
assert_equal all_cells.size, cells.size
|
21
|
+
|
22
|
+
cells.each_with_index do |cell, i|
|
23
|
+
expected = [
|
24
|
+
all_cells[i][:row],
|
25
|
+
all_cells[i][:column],
|
26
|
+
all_cells[i][:content],
|
27
|
+
all_cells[i][:type],
|
28
|
+
]
|
29
|
+
result = [
|
30
|
+
cell["row"],
|
31
|
+
cell["column"],
|
32
|
+
cell.text,
|
33
|
+
cell["type"],
|
34
|
+
]
|
35
|
+
|
36
|
+
assert_equal expected, result
|
37
|
+
end # end of sheet
|
38
|
+
sheetname = workbook.sheets[workbook.sheets.index(sheetname) + 1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_bug_to_xml_with_empty_sheets
|
44
|
+
with_each_spreadsheet(name: "emptysheets", format: [:openoffice, :excelx]) do |workbook|
|
45
|
+
workbook.sheets.each do |sheet|
|
46
|
+
assert_nil workbook.first_row, "first_row not nil in sheet #{sheet}"
|
47
|
+
assert_nil workbook.last_row, "last_row not nil in sheet #{sheet}"
|
48
|
+
assert_nil workbook.first_column, "first_column not nil in sheet #{sheet}"
|
49
|
+
assert_nil workbook.last_column, "last_column not nil in sheet #{sheet}"
|
50
|
+
assert_nil workbook.first_row(sheet), "first_row not nil in sheet #{sheet}"
|
51
|
+
assert_nil workbook.last_row(sheet), "last_row not nil in sheet #{sheet}"
|
52
|
+
assert_nil workbook.first_column(sheet), "first_column not nil in sheet #{sheet}"
|
53
|
+
assert_nil workbook.last_column(sheet), "last_column not nil in sheet #{sheet}"
|
54
|
+
end
|
55
|
+
workbook.to_xml
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
|
60
|
+
# Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
|
61
|
+
# nicht immer in der gleichen Reihenfolge erzeugt.
|
62
|
+
def init_all_cells(workbook, sheet)
|
63
|
+
all = []
|
64
|
+
workbook.first_row(sheet).upto(workbook.last_row(sheet)) do |row|
|
65
|
+
workbook.first_column(sheet).upto(workbook.last_column(sheet)) do |col|
|
66
|
+
next if workbook.empty?(row, col, sheet)
|
67
|
+
|
68
|
+
all << {
|
69
|
+
row: row.to_s,
|
70
|
+
column: col.to_s,
|
71
|
+
content: workbook.cell(row, col, sheet).to_s,
|
72
|
+
type: workbook.celltype(row, col, sheet).to_s,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
all
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRooFormatterYAML < Minitest::Test
|
4
|
+
def test_date_time_yaml
|
5
|
+
name = "time-test"
|
6
|
+
expected = File.open(TESTDIR + "/expected_results/#{name}.yml").read
|
7
|
+
with_each_spreadsheet(name: name) do |workbook|
|
8
|
+
assert_equal expected, workbook.to_yaml
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_bug_to_yaml_empty_sheet
|
13
|
+
formats = [:openoffice, :excelx]
|
14
|
+
with_each_spreadsheet(name: "emptysheets", format: formats) do |workbook|
|
15
|
+
workbook.default_sheet = workbook.sheets.first
|
16
|
+
workbook.to_yaml
|
17
|
+
assert_equal "", workbook.to_yaml
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -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
|