summaryrefslogtreecommitdiff
path: root/test/json/test_json_generate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/json/test_json_generate.rb')
-rwxr-xr-xtest/json/test_json_generate.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 9b0cff4b07e..da96603d61f 100755
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -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