diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-01 16:26:13 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-01 16:26:13 +0000 |
commit | 4a84c27e3ee50c4989591fcde2b7a10c5ccc0395 (patch) | |
tree | 4d741784865b00fcd418be81775eb256abb9d6ac /test/json/test_json.rb | |
parent | b60cc77902972047e6b1dcaf22f90d19448b0510 (diff) | |
download | ruby-4a84c27e3ee50c4989591fcde2b7a10c5ccc0395.tar.gz |
* ext/json: Update github/flori/json from 1.4.2+ to
e22b2f2bdfe6a9b0. this fixes some bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json.rb')
-rwxr-xr-x | test/json/test_json.rb | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/test/json/test_json.rb b/test/json/test_json.rb index f5a432f8bd..00e52f511a 100755 --- a/test/json/test_json.rb +++ b/test/json/test_json.rb @@ -160,6 +160,20 @@ class TC_JSON < Test::Unit::TestCase class SubArray < Array; end + class SubArray2 < Array + def to_json(*a) + { + JSON.create_id => self.class.name, + 'ary' => to_a, + }.to_json(*a) + end + + def self.json_create(o) + o.delete JSON.create_id + o['ary'] + end + end + def test_parse_array_custom_class res = parse('[]', :array_class => SubArray) assert_equal([], res) @@ -173,12 +187,52 @@ class TC_JSON < Test::Unit::TestCase assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } ')) end - class SubHash < Hash; end + class SubHash < Hash + end + + class SubHash2 < Hash + def to_json(*a) + { + JSON.create_id => self.class.name, + }.merge(self).to_json(*a) + end + + def self.json_create(o) + o.delete JSON.create_id + self[o] + end + end def test_parse_object_custom_class - res = parse('{}', :object_class => SubHash) + res = parse('{}', :object_class => SubHash2) assert_equal({}, res) - assert_equal(SubHash, res.class) + assert_equal(SubHash2, res.class) + end + + 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) + 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"])) + end + + def test_generation_of_core_subclasses_with_default_to_json + assert_equal '{"foo":"bar"}', JSON(SubHash["foo" => "bar"]) + assert_equal '["foo"]', JSON(SubArray["foo"]) + end + + def test_generation_of_core_subclasses + obj = SubHash["foo" => SubHash["bar" => true]] + obj_json = JSON(obj) + obj_again = JSON(obj_json) + assert_kind_of Hash, obj_again + assert_kind_of Hash, obj_again['foo'] + assert obj_again['foo']['bar'] + assert_equal obj, obj_again end def test_parser_reset |