mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 02:23:59 +02:00
* ext/json: Import JSON 1.5.5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e52527a4f9
commit
e9e9ec43f5
10 changed files with 103 additions and 59 deletions
|
@ -4,6 +4,7 @@
|
|||
require 'test/unit'
|
||||
require File.join(File.dirname(__FILE__), 'setup_variant')
|
||||
require 'stringio'
|
||||
require 'tempfile'
|
||||
|
||||
unless Array.method_defined?(:permutation)
|
||||
begin
|
||||
|
@ -263,12 +264,12 @@ class TC_JSON < Test::Unit::TestCase
|
|||
def test_generation_of_core_subclasses_with_new_to_json
|
||||
obj = SubHash2["foo" => SubHash2["bar" => true]]
|
||||
obj_json = JSON(obj)
|
||||
obj_again = JSON(obj_json)
|
||||
obj_again = JSON.parse(obj_json, :create_additions => true)
|
||||
assert_kind_of SubHash2, obj_again
|
||||
assert_kind_of SubHash2, obj_again['foo']
|
||||
assert obj_again['foo']['bar']
|
||||
assert_equal obj, obj_again
|
||||
assert_equal ["foo"], JSON(JSON(SubArray2["foo"]))
|
||||
assert_equal ["foo"], JSON(JSON(SubArray2["foo"]), :create_additions => true)
|
||||
end
|
||||
|
||||
def test_generation_of_core_subclasses_with_default_to_json
|
||||
|
@ -414,6 +415,25 @@ EOT
|
|||
JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
|
||||
end
|
||||
|
||||
def test_load
|
||||
assert_equal @hash, JSON.load(@json)
|
||||
tempfile = Tempfile.open('json')
|
||||
tempfile.write @json
|
||||
tempfile.rewind
|
||||
assert_equal @hash, JSON.load(tempfile)
|
||||
stringio = StringIO.new(@json)
|
||||
stringio.rewind
|
||||
assert_equal @hash, JSON.load(stringio)
|
||||
assert_raise(NoMethodError) { JSON.load(nil) }
|
||||
assert_raise(JSON::ParserError) {JSON.load('') }
|
||||
end
|
||||
|
||||
def test_load_with_options
|
||||
small_hash = JSON("foo" => 'bar')
|
||||
symbol_hash = { :foo => 'bar' }
|
||||
assert_equal symbol_hash, JSON.load(small_hash, nil, :symbolize_names => true)
|
||||
end
|
||||
|
||||
def test_load_dump
|
||||
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
||||
assert_equal too_deep, JSON.dump(eval(too_deep))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue