Sha256: 45afed1880c7528ef5c45b5a95ca85c5e660816ce0f8f5141542fa730c483e62

Contents?: true

Size: 1.55 KB

Versions: 19

Compression:

Stored size: 1.55 KB

Contents

# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx/package/xml_writer_simple'

class TestXMLWriterSimple < Minitest::Test
  def setup
    @obj = Writexlsx::Package::XMLWriterSimple.new
  end

  def test_xml_decl
    assert_equal(
      %Q!<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n!,
      @obj.xml_decl
    )
  end

  def test_empty_tag
    assert_equal('<foo/>', @obj.empty_tag('foo'))
  end

  def test_empty_tag_with_xml_decl
    expected = <<EOS
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo/>
EOS
    assert_equal(expected, @obj.xml_decl + @obj.empty_tag('foo') + "\n")
  end

  def test_start_end_tag
    assert_equal("<foo></foo>", @obj.start_tag('foo') + @obj.end_tag('foo'))
  end

  def test_attribute
    assert_equal(
      "<foo x=\"1&gt;2\"/>", @obj.empty_tag("foo", [ ['x', '1>2'] ])
    )
  end

  def test_character_data
    assert_equal(
      "<foo>&lt;tag&gt;&amp;amp;&lt;/tag&gt;</foo>",
      @obj.start_tag('foo') + @obj.characters("<tag>&amp;</tag>") + @obj.end_tag('foo')
    )
  end

  def test_data_element_with_empty_attr
    expected = "<foo>data</foo>"
    @obj.data_element('foo', 'data')
    result = @obj.string
    assert_equal(expected, result)
  end

  def test_data_element
    attributes = [
      ['name', '_xlnm.Print_Titles'],
      ['localSheetId', 0]
    ]
    expected =
      "<definedName name=\"_xlnm.Print_Titles\" localSheetId=\"0\">Sheet1!$1:$1</definedName>"
    @obj.data_element('definedName', 'Sheet1!$1:$1', attributes)
    result = @obj.string
    assert_equal(expected, result)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
write_xlsx-1.09.4 test/test_xml_writer_simple.rb
write_xlsx-1.09.3 test/test_xml_writer_simple.rb
write_xlsx-1.09.2 test/test_xml_writer_simple.rb
write_xlsx-1.09.1 test/test_xml_writer_simple.rb
write_xlsx-1.09.0 test/test_xml_writer_simple.rb
write_xlsx-1.08.2 test/test_xml_writer_simple.rb
write_xlsx-1.08.1 test/test_xml_writer_simple.rb
write_xlsx-1.08.0 test/test_xml_writer_simple.rb
write_xlsx-1.07.0 test/test_xml_writer_simple.rb
write_xlsx-1.04.0 test/test_xml_writer_simple.rb
write_xlsx-1.02.0 test/test_xml_writer_simple.rb
write_xlsx-1.01.0 test/test_xml_writer_simple.rb
write_xlsx-1.00.0 test/test_xml_writer_simple.rb
write_xlsx-0.99.0 test/test_xml_writer_simple.rb
write_xlsx-0.97.0 test/test_xml_writer_simple.rb
write_xlsx-0.90.0 test/test_xml_writer_simple.rb
write_xlsx-0.89.0 test/test_xml_writer_simple.rb
write_xlsx-0.88.0 test/test_xml_writer_simple.rb
write_xlsx-0.87.0 test/test_xml_writer_simple.rb