1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
module TestLabels
def test_labels
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
expected_labels = [
["anton", [5, 3, "Sheet1"]],
["berta", [4, 2, "Sheet1"]],
["caesar", [7, 2, "Sheet1"]],
]
with_each_spreadsheet(options) do |oo|
assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
end
end
def test_labeled_cells
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
with_each_spreadsheet(options) do |oo|
oo.default_sheet = oo.sheets.first
begin
row, col = oo.label("anton")
rescue ArgumentError
puts "labels error at #{oo.class}"
raise
end
assert_equal 5, row
assert_equal 3, col
row, col = oo.label("anton")
assert_equal "Anton", oo.cell(row, col)
row, col = oo.label("berta")
assert_equal "Bertha", oo.cell(row, col)
row, col = oo.label("caesar")
assert_equal "Cäsar", oo.cell(row, col)
row, col = oo.label("never")
assert_nil row
assert_nil col
row, col, sheet = oo.label("anton")
assert_equal 5, row
assert_equal 3, col
assert_equal "Sheet1", sheet
assert_equal "Anton", oo.anton
assert_raises(NoMethodError) do
row, col = oo.never
end
# Reihenfolge row, col,sheet analog zu #label
expected_labels = [
["anton", [5, 3, "Sheet1"]],
["berta", [4, 2, "Sheet1"]],
["caesar", [7, 2, "Sheet1"]],
]
assert_equal expected_labels, oo.labels, "error with labels array in class #{oo.class}"
end
end
def test_label
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
with_each_spreadsheet(options) do |oo|
begin
row, col = oo.label("anton")
rescue ArgumentError
puts "labels error at #{oo.class}"
raise
end
assert_equal 5, row, "error with label in class #{oo.class}"
assert_equal 3, col, "error with label in class #{oo.class}"
row, col = oo.label("anton")
assert_equal "Anton", oo.cell(row, col), "error with label in class #{oo.class}"
row, col = oo.label("berta")
assert_equal "Bertha", oo.cell(row, col), "error with label in class #{oo.class}"
row, col = oo.label("caesar")
assert_equal "Cäsar", oo.cell(row, col), "error with label in class #{oo.class}"
row, col = oo.label("never")
assert_nil row
assert_nil col
row, col, sheet = oo.label("anton")
assert_equal 5, row
assert_equal 3, col
assert_equal "Sheet1", sheet
end
end
def test_method_missing_anton
options = { name: "named_cells", format: [:openoffice, :excelx, :libreoffice] }
with_each_spreadsheet(options) do |oo|
# oo.default_sheet = oo.sheets.first
assert_equal "Anton", oo.anton
assert_raises(NoMethodError) do
oo.never
end
end
end
end
|