mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@14044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6272cf8ecd
commit
0cf0b82418
15 changed files with 346 additions and 152 deletions
|
@ -8,6 +8,7 @@ require 'test_json'
|
|||
require 'test_json_generate'
|
||||
require 'test_json_unicode'
|
||||
require 'test_json_addition'
|
||||
require 'test_json_rails'
|
||||
require 'test_json_fixtures'
|
||||
|
||||
class TS_AllTests
|
||||
|
@ -17,6 +18,7 @@ class TS_AllTests
|
|||
suite << TC_JSON.suite
|
||||
suite << TC_JSONUnicode.suite
|
||||
suite << TC_JSONAddition.suite
|
||||
suite << TC_JSONRails.suite
|
||||
suite << TC_JSONFixtures.suite
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,6 @@ class TC_JSON < Test::Unit::TestCase
|
|||
include JSON
|
||||
|
||||
def setup
|
||||
$KCODE = 'UTF8'
|
||||
@ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true].map do
|
||||
|x| [x]
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,7 +5,6 @@ require 'json'
|
|||
|
||||
class TC_JSONFixtures < Test::Unit::TestCase
|
||||
def setup
|
||||
$KCODE = 'UTF8'
|
||||
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
|
||||
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
||||
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
||||
|
|
|
@ -5,7 +5,6 @@ class TC_JSONGenerate < Test::Unit::TestCase
|
|||
include JSON
|
||||
|
||||
def setup
|
||||
$KCODE = 'UTF8'
|
||||
@hash = {
|
||||
'a' => 2,
|
||||
'b' => 3.141,
|
||||
|
|
|
@ -7,7 +7,6 @@ class TC_JSONUnicode < Test::Unit::TestCase
|
|||
include JSON
|
||||
|
||||
def setup
|
||||
$KCODE = 'UTF8'
|
||||
end
|
||||
|
||||
def test_unicode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue