Sha256: fed61c0f5c302da1d55f4efe3b36037c181b338e8b45fe94828502732393e4ec

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'test/unit'
require File.dirname(__FILE__) + '/../lib/json-schema'

class StringifyTest < Test::Unit::TestCase
  def test_stringify_on_hash
    hash = {
      :a => 'foo',
      'b' => :bar
    }
    assert_equal({'a' => 'foo', 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbol keys should be converted to strings')
  end

  def test_stringify_on_array
    array = [
      :a,
      'b'
    ]
    assert_equal(['a', 'b'], JSON::Schema.stringify(array), 'symbols in an array should be converted to strings')
  end

  def test_stringify_on_hash_of_arrays
    hash = {
      :a => [:foo],
      'b' => :bar
    }
    assert_equal({'a' => ['foo'], 'b' => 'bar'}, JSON::Schema.stringify(hash), 'symbols in a nested array should be converted to strings')
  end

  def test_stringify_on_array_of_hashes
    array = [
      :a,
      {
        :b => :bar
      }
    ]
    assert_equal(['a', {'b' => 'bar'}], JSON::Schema.stringify(array), 'symbols keys in a nested hash should be converted to strings')
  end

  def test_stringify_on_hash_of_hashes
    hash = {
      :a => {
        :b => {
          :foo => :bar
        }
      }
    }
    assert_equal({'a' => {'b' => {'foo' => 'bar'} } }, JSON::Schema.stringify(hash), 'symbols in a nested hash of hashes should be converted to strings')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json-schema-2.4.1 test/test_stringify.rb