From dddfa903d2b856146f05ffb4415c31d6127bb5bf Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Mon, 14 Jan 2019 01:40:56 -0500 Subject: New upstream version 2.8.0 --- spec/lib/roo/excelx_spec.rb | 156 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 31 deletions(-) (limited to 'spec/lib/roo/excelx_spec.rb') diff --git a/spec/lib/roo/excelx_spec.rb b/spec/lib/roo/excelx_spec.rb index 0ef0f19..6c2289f 100755 --- a/spec/lib/roo/excelx_spec.rb +++ b/spec/lib/roo/excelx_spec.rb @@ -151,6 +151,22 @@ describe Roo::Excelx do it 'returns the expected result' do expect(subject.sheet_for("Tabelle1").instance_variable_get("@name")).to eq "Tabelle1" end + + it 'returns the expected result when passed a number' do + expect(subject.sheet_for(0).instance_variable_get("@name")).to eq "Tabelle1" + end + + it 'returns the expected result when passed a number that is not the first sheet' do + expect(subject.sheet_for(1).instance_variable_get("@name")).to eq "Name of Sheet 2" + end + + it "should raise an error if passed a sheet that does not exist as an integer" do + expect { subject.sheet_for(10) }.to raise_error RangeError + end + + it "should raise an error if passed a sheet that does not exist as a string" do + expect { subject.sheet_for("does_not_exist") }.to raise_error RangeError + end end describe '#row' do @@ -304,6 +320,18 @@ describe Roo::Excelx do end end + describe '#row' do + context 'integers with leading zero' + let(:path) { 'test/files/number_with_zero_prefix.xlsx' } + + it 'returns base 10 integer' do + (1..50).each do |row_index| + range_start = (row_index - 1) * 20 + 1 + expect(subject.row(row_index)).to eq (range_start..(range_start+19)).to_a + end + end + end + describe '#excelx_format' do let(:path) { 'test/files/style.xlsx' } @@ -354,11 +382,22 @@ describe Roo::Excelx do end describe '#hyperlink' do - let(:path) { 'test/files/link.xlsx' } + context 'without location' do + let(:path) { 'test/files/link.xlsx' } - it 'returns the expected result' do - expect(subject.hyperlink(1, 1)).to eq "http://www.google.com" - expect(subject.hyperlink(1, 2)).to eq nil + it 'returns the expected result' do + expect(subject.hyperlink(1, 1)).to eq "http://www.google.com" + expect(subject.hyperlink(1, 2)).to eq nil + end + end + + context 'with location' do + let(:path) { 'test/files/link_with_location.xlsx' } + + it 'returns the expected result' do + expect(subject.hyperlink(1, 1)).to eq "http://www.google.com/#hey" + expect(subject.hyperlink(1, 2)).to eq nil + end end end @@ -480,34 +519,36 @@ describe Roo::Excelx do end describe '#html_strings' do - let(:path) { 'test/files/html_strings_formatting.xlsx' } + describe "HTML Parsing Enabling" do + let(:path) { 'test/files/html_strings_formatting.xlsx' } - it 'returns the expected result' do - expect(subject.excelx_value(1, 1, "Sheet1")).to eq "This has no formatting." - expect(subject.excelx_value(2, 1, "Sheet1")).to eq "This has bold formatting." - expect(subject.excelx_value(2, 2, "Sheet1")).to eq "This has italics formatting." - expect(subject.excelx_value(2, 3, "Sheet1")).to eq "This has underline format." - expect(subject.excelx_value(2, 4, "Sheet1")).to eq "Superscript. x123" - expect(subject.excelx_value(2, 5, "Sheet1")).to eq "SubScript. Tj" - - expect(subject.excelx_value(3, 1, "Sheet1")).to eq "Bold, italics together." - expect(subject.excelx_value(3, 2, "Sheet1")).to eq "Bold, Underline together." - expect(subject.excelx_value(3, 3, "Sheet1")).to eq "Bold, Superscript. xN" - expect(subject.excelx_value(3, 4, "Sheet1")).to eq "Bold, Subscript. Tabc" - expect(subject.excelx_value(3, 5, "Sheet1")).to eq "Italics, Underline together." - expect(subject.excelx_value(3, 6, "Sheet1")).to eq "Italics, Superscript. Xabc" - expect(subject.excelx_value(3, 7, "Sheet1")).to eq "Italics, Subscript. Befg" - expect(subject.excelx_value(4, 1, "Sheet1")).to eq "Bold, italics underline, together." - expect(subject.excelx_value(4, 2, "Sheet1")).to eq "Bold, italics, superscript. Xabc123" - expect(subject.excelx_value(4, 3, "Sheet1")).to eq "Bold, Italics, subscript. Mgha2" - expect(subject.excelx_value(4, 4, "Sheet1")).to eq "Bold, Underline, superscript. ABC123" - expect(subject.excelx_value(4, 5, "Sheet1")).to eq "Bold, Underline, subscript. GoodXYZ" - expect(subject.excelx_value(4, 6, "Sheet1")).to eq "Italics, Underline, superscript. Upswing" - expect(subject.excelx_value(4, 7, "Sheet1")).to eq "Italics, Underline, subscript. Tswing" - expect(subject.excelx_value(5, 1, "Sheet1")).to eq "Bold, italics, underline, superscript. GHJK1904" - expect(subject.excelx_value(5, 2, "Sheet1")).to eq "Bold, italics, underline, subscript. Mikedrop" - expect(subject.excelx_value(6, 1, "Sheet1")).to eq "See that regular html tags do not create html tags.\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
" - expect(subject.excelx_value(7, 1, "Sheet1")).to eq "Does create html tags when formatting is used..\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
" + it 'returns the expected result' do + expect(subject.excelx_value(1, 1, "Sheet1")).to eq("This has no formatting.") + expect(subject.excelx_value(2, 1, "Sheet1")).to eq("This has bold formatting.") + expect(subject.excelx_value(2, 2, "Sheet1")).to eq("This has italics formatting.") + expect(subject.excelx_value(2, 3, "Sheet1")).to eq("This has underline format.") + expect(subject.excelx_value(2, 4, "Sheet1")).to eq("Superscript. x123") + expect(subject.excelx_value(2, 5, "Sheet1")).to eq("SubScript. Tj") + + expect(subject.excelx_value(3, 1, "Sheet1")).to eq("Bold, italics together.") + expect(subject.excelx_value(3, 2, "Sheet1")).to eq("Bold, Underline together.") + expect(subject.excelx_value(3, 3, "Sheet1")).to eq("Bold, Superscript. xN") + expect(subject.excelx_value(3, 4, "Sheet1")).to eq("Bold, Subscript. Tabc") + expect(subject.excelx_value(3, 5, "Sheet1")).to eq("Italics, Underline together.") + expect(subject.excelx_value(3, 6, "Sheet1")).to eq("Italics, Superscript. Xabc") + expect(subject.excelx_value(3, 7, "Sheet1")).to eq("Italics, Subscript. Befg") + expect(subject.excelx_value(4, 1, "Sheet1")).to eq("Bold, italics underline, together.") + expect(subject.excelx_value(4, 2, "Sheet1")).to eq("Bold, italics, superscript. Xabc123") + expect(subject.excelx_value(4, 3, "Sheet1")).to eq("Bold, Italics, subscript. Mgha2") + expect(subject.excelx_value(4, 4, "Sheet1")).to eq("Bold, Underline, superscript. ABC123") + expect(subject.excelx_value(4, 5, "Sheet1")).to eq("Bold, Underline, subscript. GoodXYZ") + expect(subject.excelx_value(4, 6, "Sheet1")).to eq("Italics, Underline, superscript. Upswing") + expect(subject.excelx_value(4, 7, "Sheet1")).to eq("Italics, Underline, subscript. Tswing") + expect(subject.excelx_value(5, 1, "Sheet1")).to eq("Bold, italics, underline, superscript. GHJK1904") + expect(subject.excelx_value(5, 2, "Sheet1")).to eq("Bold, italics, underline, subscript. Mikedrop") + expect(subject.excelx_value(6, 1, "Sheet1")).to eq("See that regular html tags do not create html tags.\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
") + expect(subject.excelx_value(7, 1, "Sheet1")).to eq("Does create html tags when formatting is used..\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
") + end end end @@ -534,4 +575,57 @@ describe Roo::Excelx do expect(subject.sheet(0).excelx_format(2,1)).to eq 'm/d/yyyy" "h:mm:ss" "AM/PM' end end + + describe 'images' do + let(:path) { 'test/files/images.xlsx' } + + it 'returns array of images from default sheet' do + expect(subject.images).to be_kind_of(Array) + expect(subject.images.size).to eql(19) + end + + it 'returns empty array if there is no images on the sheet' do + expect(subject.images("Sheet2")).to eql([]) + end + end end + +describe 'Roo::Excelx with options set' do + subject(:xlsx) do + Roo::Excelx.new(path, disable_html_wrapper: true) + end + + describe '#html_strings' do + describe "HTML Parsing Disabled" do + let(:path) { 'test/files/html_strings_formatting.xlsx' } + + it 'returns the expected result' do + expect(subject.excelx_value(1, 1, "Sheet1")).to eq("This has no formatting.") + expect(subject.excelx_value(2, 1, "Sheet1")).to eq("This has bold formatting.") + expect(subject.excelx_value(2, 2, "Sheet1")).to eq("This has italics formatting.") + expect(subject.excelx_value(2, 3, "Sheet1")).to eq("This has underline format.") + expect(subject.excelx_value(2, 4, "Sheet1")).to eq("Superscript. x123") + expect(subject.excelx_value(2, 5, "Sheet1")).to eq("SubScript. Tj") + + expect(subject.excelx_value(3, 1, "Sheet1")).to eq("Bold, italics together.") + expect(subject.excelx_value(3, 2, "Sheet1")).to eq("Bold, Underline together.") + expect(subject.excelx_value(3, 3, "Sheet1")).to eq("Bold, Superscript. xN") + expect(subject.excelx_value(3, 4, "Sheet1")).to eq("Bold, Subscript. Tabc") + expect(subject.excelx_value(3, 5, "Sheet1")).to eq("Italics, Underline together.") + expect(subject.excelx_value(3, 6, "Sheet1")).to eq("Italics, Superscript. Xabc") + expect(subject.excelx_value(3, 7, "Sheet1")).to eq("Italics, Subscript. Befg") + expect(subject.excelx_value(4, 1, "Sheet1")).to eq("Bold, italics underline, together.") + expect(subject.excelx_value(4, 2, "Sheet1")).to eq("Bold, italics, superscript. Xabc123") + expect(subject.excelx_value(4, 3, "Sheet1")).to eq("Bold, Italics, subscript. Mgha2") + expect(subject.excelx_value(4, 4, "Sheet1")).to eq("Bold, Underline, superscript. ABC123") + expect(subject.excelx_value(4, 5, "Sheet1")).to eq("Bold, Underline, subscript. GoodXYZ") + expect(subject.excelx_value(4, 6, "Sheet1")).to eq("Italics, Underline, superscript. Upswing") + expect(subject.excelx_value(4, 7, "Sheet1")).to eq("Italics, Underline, subscript. Tswing") + expect(subject.excelx_value(5, 1, "Sheet1")).to eq("Bold, italics, underline, superscript. GHJK1904") + expect(subject.excelx_value(5, 2, "Sheet1")).to eq("Bold, italics, underline, subscript. Mikedrop") + expect(subject.excelx_value(6, 1, "Sheet1")).to eq("See that regular html tags do not create html tags.\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
") + expect(subject.excelx_value(7, 1, "Sheet1")).to eq("Does create html tags when formatting is used..\n
    \n
  1. Denver Broncos
  2. \n
  3. Carolina Panthers
  4. \n
  5. New England Patriots
  6. \n
  7. Arizona Panthers
  8. \n
") + end + end + end +end \ No newline at end of file -- cgit v1.2.3