aboutsummaryrefslogtreecommitdiffstats
path: root/test/json
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 16:00:49 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 16:00:49 +0000
commit5a00be2bf75939fd3bb05dabbdf46244eaa6bb43 (patch)
tree7a4e8c43342493d270ea16116506295751621c85 /test/json
parent5f7be3150f0bffb6a958770c61270302123774c3 (diff)
downloadruby-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')
-rwxr-xr-xtest/json/test_json.rb14
-rwxr-xr-xtest/json/test_json_addition.rb8
-rw-r--r--test/json/test_json_encoding.rb2
-rwxr-xr-xtest/json/test_json_fixtures.rb2
-rwxr-xr-xtest/json/test_json_generate.rb2
-rw-r--r--test/json/test_json_string_matching.rb2
-rwxr-xr-xtest/json/test_json_unicode.rb2
7 files changed, 22 insertions, 10 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)
diff --git a/test/json/test_json_addition.rb b/test/json/test_json_addition.rb
index e262e25953..cf808668b8 100755
--- a/test/json/test_json_addition.rb
+++ b/test/json/test_json_addition.rb
@@ -10,7 +10,7 @@ require 'json/add/bigdecimal'
require 'json/add/ostruct'
require 'date'
-class TC_JSONAddition < Test::Unit::TestCase
+class TestJSONAddition < Test::Unit::TestCase
include JSON
class A
@@ -64,7 +64,7 @@ class TC_JSONAddition < Test::Unit::TestCase
def to_json(*args)
{
- 'json_class' => 'TC_JSONAddition::Nix',
+ 'json_class' => 'TestJSONAddition::Nix',
}.to_json(*args)
end
end
@@ -88,7 +88,7 @@ class TC_JSONAddition < Test::Unit::TestCase
a_hash = JSON.parse(json, :create_additions => false)
assert_kind_of Hash, a_hash
assert_equal(
- {"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
+ {"args"=>[666], "json_class"=>"TestJSONAddition::A"}.sort_by { |k,| k },
a_hash.sort_by { |k,| k }
)
end
@@ -97,7 +97,7 @@ class TC_JSONAddition < Test::Unit::TestCase
b = B.new
assert !B.json_creatable?
json = generate(b)
- assert_equal({ "json_class"=>"TC_JSONAddition::B" }, JSON.parse(json))
+ assert_equal({ "json_class"=>"TestJSONAddition::B" }, JSON.parse(json))
end
def test_extended_json_fail2
diff --git a/test/json/test_json_encoding.rb b/test/json/test_json_encoding.rb
index 7af5e63a73..caa0c6c50e 100644
--- a/test/json/test_json_encoding.rb
+++ b/test/json/test_json_encoding.rb
@@ -4,7 +4,7 @@
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
-class TC_JSONEncoding < Test::Unit::TestCase
+class TestJSONEncoding < Test::Unit::TestCase
include JSON
def setup
diff --git a/test/json/test_json_fixtures.rb b/test/json/test_json_fixtures.rb
index e9df8f5b1c..37e51457d4 100755
--- a/test/json/test_json_fixtures.rb
+++ b/test/json/test_json_fixtures.rb
@@ -4,7 +4,7 @@
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
-class TC_JSONFixtures < Test::Unit::TestCase
+class TestJSONFixtures < Test::Unit::TestCase
def setup
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 8d06cec10e..04368a4c8b 100755
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -4,7 +4,7 @@
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
-class TC_JSONGenerate < Test::Unit::TestCase
+class TestJSONGenerate < Test::Unit::TestCase
include JSON
def setup
diff --git a/test/json/test_json_string_matching.rb b/test/json/test_json_string_matching.rb
index df26a68a4d..b8a7169490 100644
--- a/test/json/test_json_string_matching.rb
+++ b/test/json/test_json_string_matching.rb
@@ -6,7 +6,7 @@ require File.join(File.dirname(__FILE__), 'setup_variant')
require 'stringio'
require 'time'
-class TestJsonStringMatching < Test::Unit::TestCase
+class TestJSONStringMatching < Test::Unit::TestCase
include JSON
class TestTime < ::Time
diff --git a/test/json/test_json_unicode.rb b/test/json/test_json_unicode.rb
index ace56cae36..c328811106 100755
--- a/test/json/test_json_unicode.rb
+++ b/test/json/test_json_unicode.rb
@@ -4,7 +4,7 @@
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
-class TC_JSONUnicode < Test::Unit::TestCase
+class TestJSONUnicode < Test::Unit::TestCase
include JSON
def test_unicode