Sha256: fb540e924cf996322dc6306fbcc73cbefe90879e407e020daa9c09993cd187c2

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 KB

Contents

# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx'
require 'stringio'

class TestWriteHyperlink < Test::Unit::TestCase
  def setup
    @workbook = WriteXLSX.new(StringIO.new)
    @worksheet = @workbook.add_worksheet('')
  end

  def test_write_hyperlink_external
    hyperlink = Writexlsx::Worksheet::Hyperlink.new('')
    @worksheet.__send__('write_hyperlink_external', hyperlink, 0, 0, 1)
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<hyperlink ref="A1" r:id="rId1"/>'
    assert_equal(expected, result)
  end

  def test_write_hyperlink_internal_sheet2
    hyperlink = Writexlsx::Worksheet::Hyperlink.new('internal:Sheet2!A1', 'Sheet2!A1')
    @worksheet.__send__('write_hyperlink_internal', hyperlink, 0, 0)
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<hyperlink ref="A1" location="Sheet2!A1" display="Sheet2!A1"/>'
    assert_equal(expected, result)
  end

  def test_write_hyperlink_internal_quoted_sheet
    hyperlink = Writexlsx::Worksheet::Hyperlink.new("internal:'Data Sheet'!D5", "'Data Sheet'!D5")
    @worksheet.__send__('write_hyperlink_internal', hyperlink, 4, 0)
    result = @worksheet.instance_variable_get(:@writer).string
    expected = %q{<hyperlink ref="A5" location="'Data Sheet'!D5" display="'Data Sheet'!D5"/>}
    assert_equal(expected, result)
  end

  def test_write_hyperlink_internal_tooltip
    hyperlink = Writexlsx::Worksheet::Hyperlink.new('internal:Sheet2!A1', 'Sheet2!A1')
    hyperlink.tip = 'Screen Tip 1'
    @worksheet.__send__('write_hyperlink_internal', hyperlink, 17, 0)
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<hyperlink ref="A18" location="Sheet2!A1" tooltip="Screen Tip 1" display="Sheet2!A1"/>'
    assert_equal(expected, result)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
write_xlsx-0.72.2 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.72.1 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.72.0 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.71.0 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.70.0 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.69.0 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.65.1 test/worksheet/test_write_hyperlink.rb
write_xlsx-0.65.0 test/worksheet/test_write_hyperlink.rb