summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_str_val.rb
blob: 783d4122388a3d57ac797cb5f78e384dd6733057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require 'tc_helper'

class TestStrVal < Test::Unit::TestCase
  def setup
    @str_val = Axlsx::StrVal.new v: "1"
    @str_val_with_special_characters = Axlsx::StrVal.new v: "a & b <c>"
  end

  def test_initialize
    assert_equal("1", @str_val.v)
  end

  def test_to_xml_string
    str = +'<?xml version="1.0" encoding="UTF-8"?>'
    str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
    str << @str_val.to_xml_string(0)
    doc = Nokogiri::XML(str)

    assert_equal(1, doc.xpath("//c:pt/c:v[text()='1']").size)
  end

  def test_to_xml_string_special_characters
    str = +'<?xml version="1.0" encoding="UTF-8"?>'
    str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
    str << @str_val_with_special_characters.to_xml_string(0)
    doc = Nokogiri::XML(str)

    assert_equal(1, doc.xpath("//c:pt/c:v[text()='a & b <c>']").size)
  end
end