diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-12 10:51:49 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-12 10:51:49 +0000 |
commit | 43f6fdfb42d3f4c9025c290bdf5aeffe5959f1bf (patch) | |
tree | bc2260bf09b94eef5c9ce2b08f366a822a9a2fed /test/json/test_json_generic_object.rb | |
parent | 395d7bb34624d69bf54e121a4f385ef84537e996 (diff) |
* ext/json: merge JSON 1.7.5.
fix tests and other fixes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json_generic_object.rb')
-rw-r--r-- | test/json/test_json_generic_object.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/json/test_json_generic_object.rb b/test/json/test_json_generic_object.rb new file mode 100644 index 0000000000..e13a492170 --- /dev/null +++ b/test/json/test_json_generic_object.rb @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +require 'test/unit' +require File.join(File.dirname(__FILE__), 'setup_variant') +class TestJSONGenericObject < Test::Unit::TestCase + include JSON + + def setup + @go = GenericObject[ :a => 1, :b => 2 ] + end + + def test_attributes + assert_equal 1, @go.a + assert_equal 1, @go[:a] + assert_equal 2, @go.b + assert_equal 2, @go[:b] + assert_nil @go.c + assert_nil @go[:c] + end + + def test_generate_json + assert_equal @go, JSON(JSON(@go)) + end + + def test_parse_json + assert_equal @go, l = JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }') + assert_equal 1, l.a + assert_equal @go, l = JSON('{ "a": 1, "b": 2 }', :object_class => GenericObject) + assert_equal 1, l.a + assert_equal GenericObject[:a => GenericObject[:b => 2]], + l = JSON('{ "a": { "b": 2 } }', :object_class => GenericObject) + assert_equal 2, l.a.b + end +end |