File: typecast_hash_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 (29 lines) | stat: -rw-r--r-- 702 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
require "test_helper"

# Tests typecast_hash type attribute handling
class TypecastHashTest < Minitest::Test
  cover "MultiXml*"
  include MultiXml::Helpers

  def test_raises_disallowed_type_error_with_type
    error = assert_raises(MultiXml::DisallowedTypeError) do
      typecast_hash({"type" => "yaml"}, ["yaml"])
    end

    assert_equal "yaml", error.type
  end

  def test_passes_type_to_convert_hash
    hash = {"type" => "array", "item" => %w[a b c]}
    result = typecast_hash(hash, [])

    assert_equal %w[a b c], result
  end

  def test_type_affects_conversion
    hash = {"type" => "string", "nil" => "false"}
    result = typecast_hash(hash, [])

    assert_equal "", result
  end
end