summaryrefslogtreecommitdiff
path: root/test/json/test_json_generic_object.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-11 11:14:36 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-11 11:14:36 +0000
commitcfaddc2a3248dd0ce4a370fdbab44ca88adf5722 (patch)
tree6c004c0c73ea77dc6c77033632241f6ba4f77a58 /test/json/test_json_generic_object.rb
parent8e7b572d97f0a19a8467f3a299d72c49ba51a293 (diff)
* ext/json/*, test/json/*, defs/default_gems: Gemify JSON library.
[fix GH-867][Feature #11057] * test/ruby/test_extlibs.rb: removed json gem from existence extentions. * gems/bundled_gems: added json gem into bundled gem. * lib/rdoc/rubygems_hook.rb: ignored no json environment. * lib/rubygems/test_case.rb, test/rubygems/*: ditto. * lib/rdoc/test_case.rb, test/rdoc/*: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json_generic_object.rb')
-rw-r--r--test/json/test_json_generic_object.rb75
1 files changed, 0 insertions, 75 deletions
diff --git a/test/json/test_json_generic_object.rb b/test/json/test_json_generic_object.rb
deleted file mode 100644
index c43c7762be..0000000000
--- a/test/json/test_json_generic_object.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env ruby
-# encoding: 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
- switch_json_creatable do
- assert_equal @go, JSON(JSON(@go), :create_additions => true)
- end
- end
-
- def test_parse_json
- assert_kind_of Hash, JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }', :create_additions => true)
- switch_json_creatable do
- assert_equal @go, l = JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }', :create_additions => true)
- 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
-
- def test_from_hash
- result = GenericObject.from_hash(
- :foo => { :bar => { :baz => true }, :quux => [ { :foobar => true } ] })
- assert_kind_of GenericObject, result.foo
- assert_kind_of GenericObject, result.foo.bar
- assert_equal true, result.foo.bar.baz
- assert_kind_of GenericObject, result.foo.quux.first
- assert_equal true, result.foo.quux.first.foobar
- assert_equal true, GenericObject.from_hash(true)
- end
-
- def test_json_generic_object_load
- empty = JSON::GenericObject.load(nil)
- assert_kind_of JSON::GenericObject, empty
- simple_json = '{"json_class":"JSON::GenericObject","hello":"world"}'
- simple = JSON::GenericObject.load(simple_json)
- assert_kind_of JSON::GenericObject, simple
- assert_equal "world", simple.hello
- converting = JSON::GenericObject.load('{ "hello": "world" }')
- assert_kind_of JSON::GenericObject, converting
- assert_equal "world", converting.hello
-
- json = JSON::GenericObject.dump(JSON::GenericObject[:hello => 'world'])
- assert_equal JSON(json), JSON('{"json_class":"JSON::GenericObject","hello":"world"}')
- end
-
- private
-
- def switch_json_creatable
- JSON::GenericObject.json_creatable = true
- yield
- ensure
- JSON::GenericObject.json_creatable = false
- end
-end