mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 17:43:59 +02:00
merge revision(s) 33122:
* ext/json: Merge json gem 1.5.4+ (2149f4185c598fb97db1). [Bug #5173] [ruby-core:38866] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f363d4d8c1
commit
510f6dc7d0
13 changed files with 728 additions and 288 deletions
|
@ -50,6 +50,7 @@ EOT
|
|||
parsed_json = parse(json)
|
||||
assert_equal({"1"=>2}, parsed_json)
|
||||
assert_raise(GeneratorError) { generate(666) }
|
||||
assert_equal '666', generate(666, :quirks_mode => true)
|
||||
end
|
||||
|
||||
def test_generate_pretty
|
||||
|
@ -67,6 +68,7 @@ EOT
|
|||
parsed_json = parse(json)
|
||||
assert_equal({"1"=>2}, parsed_json)
|
||||
assert_raise(GeneratorError) { pretty_generate(666) }
|
||||
assert_equal '666', pretty_generate(666, :quirks_mode => true)
|
||||
end
|
||||
|
||||
def test_fast_generate
|
||||
|
@ -79,9 +81,24 @@ EOT
|
|||
parsed_json = parse(json)
|
||||
assert_equal({"1"=>2}, parsed_json)
|
||||
assert_raise(GeneratorError) { fast_generate(666) }
|
||||
assert_equal '666', fast_generate(666, :quirks_mode => true)
|
||||
end
|
||||
|
||||
|
||||
def test_own_state
|
||||
state = State.new
|
||||
json = generate(@hash, state)
|
||||
assert_equal(JSON.parse(@json2), JSON.parse(json))
|
||||
parsed_json = parse(json)
|
||||
assert_equal(@hash, parsed_json)
|
||||
json = generate({1=>2}, state)
|
||||
assert_equal('{"1":2}', json)
|
||||
parsed_json = parse(json)
|
||||
assert_equal({"1"=>2}, parsed_json)
|
||||
assert_raise(GeneratorError) { generate(666, state) }
|
||||
state.quirks_mode = true
|
||||
assert state.quirks_mode?
|
||||
assert_equal '666', generate(666, state)
|
||||
end
|
||||
|
||||
def test_states
|
||||
json = generate({1=>2}, nil)
|
||||
|
@ -107,6 +124,7 @@ EOT
|
|||
:allow_nan => false,
|
||||
:array_nl => "\n",
|
||||
:ascii_only => false,
|
||||
:quirks_mode => false,
|
||||
:depth => 0,
|
||||
:indent => " ",
|
||||
:max_nesting => 19,
|
||||
|
@ -122,6 +140,7 @@ EOT
|
|||
:allow_nan => false,
|
||||
:array_nl => "",
|
||||
:ascii_only => false,
|
||||
:quirks_mode => false,
|
||||
:depth => 0,
|
||||
:indent => "",
|
||||
:max_nesting => 19,
|
||||
|
@ -137,6 +156,7 @@ EOT
|
|||
:allow_nan => false,
|
||||
:array_nl => "",
|
||||
:ascii_only => false,
|
||||
:quirks_mode => false,
|
||||
:depth => 0,
|
||||
:indent => "",
|
||||
:max_nesting => 0,
|
||||
|
@ -177,4 +197,17 @@ EOT
|
|||
assert_raises(JSON::NestingError) { ary.to_json(s) }
|
||||
assert_equal 19, s.depth
|
||||
end
|
||||
|
||||
def test_gc
|
||||
bignum_too_long_to_embed_as_string = 1234567890123456789012345
|
||||
expect = bignum_too_long_to_embed_as_string.to_s
|
||||
stress, GC.stress = GC.stress, true
|
||||
|
||||
10.times do |i|
|
||||
tmp = bignum_too_long_to_embed_as_string.to_json
|
||||
assert_equal expect, tmp
|
||||
end
|
||||
ensure
|
||||
GC.stress = stress
|
||||
end if GC.respond_to?(:stress=)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue