diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_json.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/test_json.rb b/tests/test_json.rb index f5a432f..19b742f 100755 --- a/tests/test_json.rb +++ b/tests/test_json.rb @@ -173,7 +173,18 @@ class TC_JSON < Test::Unit::TestCase assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } ')) end - class SubHash < Hash; end + class SubHash < 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 + new.merge(o) + end + end def test_parse_object_custom_class res = parse('{}', :object_class => SubHash) @@ -181,6 +192,16 @@ class TC_JSON < Test::Unit::TestCase assert_equal(SubHash, res.class) end + def test_generation_of_core_subclasses + obj = SubHash.new.merge( "foo" => SubHash.new.merge("bar" => true)) + obj_json = JSON(obj) + obj_again = JSON(obj_json) + assert_kind_of SubHash, obj_again + assert_kind_of SubHash, obj_again['foo'] + assert obj_again['foo']['bar'] + assert_equal obj, obj_again + end + def test_parser_reset parser = Parser.new(@json) assert_equal(@hash, parser.parse) |