diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-28 09:22:57 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-28 09:22:57 +0000 |
commit | ad03de84222bb2773d25b53e5fc862e44dd6f47c (patch) | |
tree | f8eb0bb1ca3effb41119a9e505395f6ba8003752 /test/json/test_json_addition.rb | |
parent | 387c80ab833b36d1b804869f1053af29f7920be9 (diff) | |
download | ruby-ad03de84222bb2773d25b53e5fc862e44dd6f47c.tar.gz ruby-ad03de84222bb2773d25b53e5fc862e44dd6f47c.tar.xz ruby-ad03de84222bb2773d25b53e5fc862e44dd6f47c.zip |
* ext/json, lib/json, test/json: Update to JSON 1.1.2.
(RubyForge#15447)
* math.c: fix typo.
--
M ChangeLog
M math.c
M ext/json/ext/generator/generator.c
M ext/json/ext/parser/parser.rl
M ext/json/ext/parser/parser.c
M lib/json/version.rb
M lib/json/editor.rb
M lib/json/common.rb
M lib/json/pure/parser.rb
M test/json/test_json_unicode.rb
M test/json/test_json_fixtures.rb
M test/json/test_json_generate.rb
M test/json/test_json_addition.rb
M test/json/test_json.rb
M test/json/runner.rb
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json_addition.rb')
-rwxr-xr-x | test/json/test_json_addition.rb | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/test/json/test_json_addition.rb b/test/json/test_json_addition.rb index e527f70a1..2ae0ce47c 100755 --- a/test/json/test_json_addition.rb +++ b/test/json/test_json_addition.rb @@ -1,7 +1,8 @@ #!/usr/bin/env ruby require 'test/unit' -require 'json' +require 'json/add/core' +require 'date' class TC_JSONAddition < Test::Unit::TestCase include JSON @@ -23,7 +24,7 @@ class TC_JSONAddition < Test::Unit::TestCase def to_json(*args) { - 'json_class' => self.class, + 'json_class' => self.class.name, 'args' => [ @a ], }.to_json(*args) end @@ -32,12 +33,16 @@ class TC_JSONAddition < Test::Unit::TestCase class B def to_json(*args) { - 'json_class' => self.class, + 'json_class' => self.class.name, }.to_json(*args) end end class C + def self.json_creatable? + false + end + def to_json(*args) { 'json_class' => 'TC_JSONAddition::Nix', @@ -46,7 +51,6 @@ class TC_JSONAddition < Test::Unit::TestCase end def setup - $KCODE = 'UTF8' end def test_extended_json @@ -58,6 +62,21 @@ class TC_JSONAddition < Test::Unit::TestCase assert_equal a, a_again end + def test_extended_json_disabled + a = A.new(666) + assert A.json_creatable? + json = generate(a) + a_again = JSON.parse(json, :create_additions => true) + assert_kind_of a.class, a_again + assert_equal a, a_again + 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 }, + a_hash.sort_by { |k,| k } + ) + end + def test_extended_json_fail b = B.new assert !B.json_creatable? @@ -91,4 +110,34 @@ EOT raw_again = JSON.parse(json) assert_equal raw, raw_again end + + def test_core + t = Time.now + assert_equal t, JSON(JSON(t)) + d = Date.today + assert_equal d, JSON(JSON(d)) + d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161) + assert_equal d, JSON(JSON(d)) + assert_equal 1..10, JSON(JSON(1..10)) + assert_equal 1...10, JSON(JSON(1...10)) + assert_equal "a".."c", JSON(JSON("a".."c")) + assert_equal "a"..."c", JSON(JSON("a"..."c")) + struct = Struct.new 'MyStruct', :foo, :bar + s = struct.new 4711, 'foot' + assert_equal s, JSON(JSON(s)) + struct = Struct.new :foo, :bar + s = struct.new 4711, 'foot' + assert_raises(JSONError) { JSON(s) } + begin + raise TypeError, "test me" + rescue TypeError => e + e_json = JSON.generate e + e_again = JSON e_json + assert_kind_of TypeError, e_again + assert_equal e.message, e_again.message + assert_equal e.backtrace, e_again.backtrace + end + assert_equal /foo/, JSON(JSON(/foo/)) + assert_equal /foo/i, JSON(JSON(/foo/i)) + end end |