./tests/test_json_generate.rb in json-maglev--1.5.4 vs ./tests/test_json_generate.rb in json-maglev--1.6.1

- old
+ new

@@ -48,10 +48,11 @@ json = generate({1=>2}) assert_equal('{"1":2}', json) 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 json = pretty_generate(@hash) # hashes aren't (insertion) ordered on every ruby implementation assert_equal(@json3, json) @@ -65,10 +66,11 @@ } 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 json = fast_generate(@hash) assert_equal(JSON.parse(@json2), JSON.parse(json)) @@ -77,14 +79,29 @@ json = fast_generate({1=>2}) assert_equal('{"1":2}', json) 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) assert_equal('{"1":2}', json) s = JSON.state.new assert s.check_circular? @@ -105,10 +122,11 @@ state = PRETTY_STATE_PROTOTYPE.dup assert_equal({ :allow_nan => false, :array_nl => "\n", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => " ", :max_nesting => 19, :object_nl => "\n", :space => " ", @@ -120,10 +138,11 @@ state = SAFE_STATE_PROTOTYPE.dup assert_equal({ :allow_nan => false, :array_nl => "", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 19, :object_nl => "", :space => "", @@ -135,10 +154,11 @@ state = FAST_STATE_PROTOTYPE.dup assert_equal({ :allow_nan => false, :array_nl => "", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 0, :object_nl => "", :space => "", @@ -175,6 +195,19 @@ s = JSON.state.new assert_equal 0, s.depth 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