summaryrefslogtreecommitdiffstats
path: root/test/helpers/test_labels.rb
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2017-06-12 03:37:11 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2017-06-12 03:37:11 -0400
commit8280a21a23d44aa90177e2bc041d0b8dc8556f4b (patch)
treedadef7ee085c0e990a5070bd41b6a5b98c97f4fd /test/helpers/test_labels.rb
Import Upstream version 2.7.1upstream/2.7.1
Diffstat (limited to 'test/helpers/test_labels.rb')
-rw-r--r--test/helpers/test_labels.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/helpers/test_labels.rb b/test/helpers/test_labels.rb
new file mode 100644
index 0000000..1b867b5
--- /dev/null
+++ b/test/helpers/test_labels.rb
@@ -0,0 +1,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