File: unwrap_if_simple_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 994 bytes parent folder | download
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
33
require "test_helper"

# Tests unwrap_if_simple value merging behavior
class UnwrapIfSimpleTest < Minitest::Test
  cover "MultiXml*"
  include MultiXml::Helpers

  def test_merges_value_when_multiple_keys
    hash = {"attr1" => "val1", "attr2" => "val2"}
    value = "converted"
    result = unwrap_if_simple(hash, value)

    assert_equal({"attr1" => "val1", "attr2" => "val2", MultiXml::TEXT_CONTENT_KEY => "converted"}, result)
    assert_equal "converted", result[MultiXml::TEXT_CONTENT_KEY]
  end

  def test_returns_value_when_single_key
    hash = {"only_key" => "val"}
    value = "the_value"
    result = unwrap_if_simple(hash, value)

    assert_equal "the_value", result
  end

  def test_value_must_be_in_result
    hash = {"type" => "string", "other" => "data"}
    value = "important_content"
    result = unwrap_if_simple(hash, value)

    assert_includes result.keys, MultiXml::TEXT_CONTENT_KEY
    assert_equal "important_content", result[MultiXml::TEXT_CONTENT_KEY]
  end
end