summaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/roo/excelx/relationships_spec.rb43
-rwxr-xr-xspec/lib/roo/excelx_spec.rb25
-rw-r--r--spec/lib/roo/utils_spec.rb13
3 files changed, 81 insertions, 0 deletions
diff --git a/spec/lib/roo/excelx/relationships_spec.rb b/spec/lib/roo/excelx/relationships_spec.rb
new file mode 100644
index 0000000..6171d8f
--- /dev/null
+++ b/spec/lib/roo/excelx/relationships_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+describe Roo::Excelx::Relationships do
+ subject(:relationships) { Roo::Excelx::Relationships.new Roo::Excelx.new(path).rels_files[0] }
+
+ describe "#include_type?" do
+ [
+ ["with hyperlink type", "test/files/link.xlsx", true, false],
+ ["with nil path", "test/files/Bibelbund.xlsx", false, false],
+ ["with comments type", "test/files/comments-google.xlsx", false, true],
+ ].each do |context_desc, file_path, hyperlink_value, comments_value|
+ context context_desc do
+ let(:path) { file_path }
+
+ it "should return #{hyperlink_value} for hyperlink" do
+ expect(subject.include_type?("hyperlink")).to be hyperlink_value
+ end
+
+ it "should return #{hyperlink_value} for link" do
+ expect(subject.include_type?("link")).to be hyperlink_value
+ end
+
+ it "should return false for hypelink" do
+ expect(subject.include_type?("hypelink")).to be false
+ end
+
+ it "should return false for coment" do
+ expect(subject.include_type?("coment")).to be false
+ end
+
+ it "should return #{comments_value} for comments" do
+ expect(subject.include_type?("comments")).to be comments_value
+ end
+
+ it "should return #{comments_value} for comment" do
+ expect(subject.include_type?("comment")).to be comments_value
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/roo/excelx_spec.rb b/spec/lib/roo/excelx_spec.rb
index 6c2289f..1b67a4d 100755
--- a/spec/lib/roo/excelx_spec.rb
+++ b/spec/lib/roo/excelx_spec.rb
@@ -379,9 +379,34 @@ describe Roo::Excelx do
expect(subject.hyperlink?(1, 1)).to eq true
expect(subject.hyperlink?(1, 2)).to eq false
end
+
+ context 'defined on cell range' do
+ let(:path) { 'test/files/cell-range-link.xlsx' }
+
+ it 'returns the expected result' do
+ [[false]*3, *[[true, true, false]]*4, [false]*3].each.with_index(1) do |row, row_index|
+ row.each.with_index(1) do |value, col_index|
+ expect(subject.hyperlink?(row_index, col_index)).to eq(value)
+ end
+ end
+ end
+ end
end
describe '#hyperlink' do
+ context 'defined on cell range' do
+ let(:path) { 'test/files/cell-range-link.xlsx' }
+
+ it 'returns the expected result' do
+ link = "http://www.google.com"
+ [[nil]*3, *[[link, link, nil]]*4, [nil]*3].each.with_index(1) do |row, row_index|
+ row.each.with_index(1) do |value, col_index|
+ expect(subject.hyperlink(row_index, col_index)).to eq(value)
+ end
+ end
+ end
+ end
+
context 'without location' do
let(:path) { 'test/files/link.xlsx' }
diff --git a/spec/lib/roo/utils_spec.rb b/spec/lib/roo/utils_spec.rb
index 8f322d4..c000ae7 100644
--- a/spec/lib/roo/utils_spec.rb
+++ b/spec/lib/roo/utils_spec.rb
@@ -90,6 +90,19 @@ RSpec.describe ::Roo::Utils do
end
end
+ context '.coordinates_in_range' do
+ it "returns the expected result" do
+ expect(described_class.coordinates_in_range('').to_a).to eq []
+ expect(described_class.coordinates_in_range('B2').to_a).to eq [[2, 2]]
+ expect(described_class.coordinates_in_range('D2:G3').to_a).to eq [[2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7]]
+ expect(described_class.coordinates_in_range('G3:D2').to_a).to eq []
+ end
+
+ it "raises an error when appropriate" do
+ expect { described_class.coordinates_in_range('D2:G3:I5').to_a }.to raise_error(ArgumentError)
+ end
+ end
+
context '.load_xml' do
it 'returns the expected result' do
expect(described_class.load_xml('test/files/sheet1.xml')).to be_a(Nokogiri::XML::Document)