Sha256: 220f8141f7f3997a3540e0141b88f1be7b1245bccc49aec44f4f5390e917b0a5

Contents?: true

Size: 1.7 KB

Versions: 16

Compression:

Stored size: 1.7 KB

Contents

require 'tc_helper'

class TestDefinedNames < Test::Unit::TestCase
  def setup
    @dn = Axlsx::DefinedName.new('Sheet1!A1:A1')
  end

  def test_initialize
    assert_equal('Sheet1!A1:A1', @dn.formula)
  end

  def test_string_attributes
    %w(short_cut_key status_bar help description custom_menu comment).each do |attr|
      assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) }
      assert_nothing_raised { @dn.send("#{attr}=", '_xlnm.Sheet_Title') }
    end
  end

  def test_boolean_attributes
   %w(workbook_parameter publish_to_server xlm vb_proceedure function hidden).each do |attr|
      assert_raise(ArgumentError, 'only booleanish allowed in string attributes') { @dn.send("#{attr}=", 'foo') }
      assert_nothing_raised { @dn.send("#{attr}=", 1) }
    end

  end

  def test_local_sheet_id
    assert_raise(ArgumentError, 'local_sheet_id must be an unsigned int') { @dn.local_sheet_id = -1 }
    assert_nothing_raised { @dn.local_sheet_id = 1 }
  end

  def test_do_not_camelcase_value_for_name
    @dn.name = '_xlnm._FilterDatabase'
    doc = Nokogiri::XML(@dn.to_xml_string)
    assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1)
    assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
  end

  def test_to_xml_string
    assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string }
    @dn.name = '_xlnm.Print_Titles'
    @dn.hidden = true
    doc = Nokogiri::XML(@dn.to_xml_string)
    assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1)
    assert_equal(doc.xpath("//definedName[@hidden='1']").size, 1)
    assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
  end

end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
caxlsx-3.1.1 test/workbook/tc_defined_name.rb
caxlsx-3.1.0 test/workbook/tc_defined_name.rb
bonio-axlsx-2.2.3 test/workbook/tc_defined_name.rb
caxlsx-3.0.4 test/workbook/tc_defined_name.rb
caxlsx-3.0.3 test/workbook/tc_defined_name.rb
caxlsx-3.0.2 test/workbook/tc_defined_name.rb
caxlsx-3.0.1 test/workbook/tc_defined_name.rb
caxlsx-3.0.0 test/workbook/tc_defined_name.rb
axlsx-alt-3.0.1 test/workbook/tc_defined_name.rb
axlsx-alt-3.0.0 test/workbook/tc_defined_name.rb
axlsx-3.0.0.pre test/workbook/tc_defined_name.rb
bonio-axlsx-2.2.2 test/workbook/tc_defined_name.rb
bonio-axlsx-2.2.1 test/workbook/tc_defined_name.rb
dg-axlsx-2.1.0 test/workbook/tc_defined_name.rb
axlsx-2.1.0.pre test/workbook/tc_defined_name.rb
l_axlsx-2.0.1 test/workbook/tc_defined_name.rb