diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-07 16:00:49 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-07 16:00:49 +0000 |
commit | 5a00be2bf75939fd3bb05dabbdf46244eaa6bb43 (patch) | |
tree | 7a4e8c43342493d270ea16116506295751621c85 /test/json/test_json.rb | |
parent | 5f7be3150f0bffb6a958770c61270302123774c3 (diff) | |
download | ruby-5a00be2bf75939fd3bb05dabbdf46244eaa6bb43.tar.gz |
* ext/json: Merge JSON 1.7.1.
https://github.com/flori/json/commit/e5b9a9465c1159fae533bca320d950b772bcb4ac
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json.rb')
-rwxr-xr-x | test/json/test_json.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/test/json/test_json.rb b/test/json/test_json.rb index 1b39360b33..22cd5ee5a5 100755 --- a/test/json/test_json.rb +++ b/test/json/test_json.rb @@ -21,7 +21,7 @@ unless Array.method_defined?(:permutation) end end -class TC_JSON < Test::Unit::TestCase +class TestJSON < Test::Unit::TestCase include JSON def setup @@ -109,6 +109,8 @@ class TC_JSON < Test::Unit::TestCase def test_parse_json_primitive_values assert_raise(JSON::ParserError) { JSON.parse('') } assert_raise(JSON::ParserError) { JSON.parse('', :quirks_mode => true) } + assert_raise(TypeError) { JSON::Parser.new(nil).parse } + assert_raise(TypeError) { JSON::Parser.new(nil, :quirks_mode => true).parse } assert_raise(TypeError) { JSON.parse(nil) } assert_raise(TypeError) { JSON.parse(nil, :quirks_mode => true) } assert_raise(JSON::ParserError) { JSON.parse(' /* foo */ ') } @@ -314,6 +316,16 @@ class TC_JSON < Test::Unit::TestCase assert res.item_set? end + def test_parse_generic_object + res = parse('{"foo":"bar", "baz":{}}', :object_class => JSON::GenericObject) + assert_equal(JSON::GenericObject, res.class) + assert_equal "bar", res.foo + assert_equal "bar", res["foo"] + assert_equal "bar", res[:foo] + assert_equal "bar", res.to_hash[:foo] + assert_equal(JSON::GenericObject, res.baz.class) + end + def test_generate_core_subclasses_with_new_to_json obj = SubHash2["foo" => SubHash2["bar" => true]] obj_json = JSON(obj) |