diff options
author | Florian Frank <flori@ping.de> | 2011-12-21 11:05:46 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2011-12-21 11:05:46 +0100 |
commit | 60ef7adb347b473cbcce9aacacb2943ae5fb4d4c (patch) | |
tree | ba73bea0660d74b2a9a787c5e0acd1a06739e1b6 /tests/test_json_generate.rb | |
parent | 0dacb54bcdf3c40cc38dae26f04b780024460b45 (diff) | |
parent | 59ecfad89281873fe72234b62545294b5fa7ba95 (diff) | |
download | json-MagLev-master.tar.gz |
Merge branch 'master' of https://github.com/MagLev/json into MagLev-masterMagLev-master
Diffstat (limited to 'tests/test_json_generate.rb')
-rwxr-xr-x | tests/test_json_generate.rb | 96 |
1 files changed, 66 insertions, 30 deletions
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index da96603..b363de1 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -43,6 +43,8 @@ EOT def test_generate json = generate(@hash) assert_equal(JSON.parse(@json2), JSON.parse(json)) + json = JSON[@hash] + assert_equal(JSON.parse(@json2), JSON.parse(json)) parsed_json = parse(json) assert_equal(@hash, parsed_json) json = generate({1=>2}) @@ -121,48 +123,51 @@ EOT def test_pretty_state 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 => " ", - :space_before => "", + :allow_nan => false, + :array_nl => "\n", + :ascii_only => false, + :buffer_initial_length => 1024, + :quirks_mode => false, + :depth => 0, + :indent => " ", + :max_nesting => 19, + :object_nl => "\n", + :space => " ", + :space_before => "", }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) end def test_safe_state 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 => "", - :space_before => "", + :allow_nan => false, + :array_nl => "", + :ascii_only => false, + :buffer_initial_length => 1024, + :quirks_mode => false, + :depth => 0, + :indent => "", + :max_nesting => 19, + :object_nl => "", + :space => "", + :space_before => "", }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) end def test_fast_state 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 => "", - :space_before => "", + :allow_nan => false, + :array_nl => "", + :ascii_only => false, + :buffer_initial_length => 1024, + :quirks_mode => false, + :depth => 0, + :indent => "", + :max_nesting => 0, + :object_nl => "", + :space => "", + :space_before => "", }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s }) end @@ -198,6 +203,17 @@ EOT assert_equal 19, s.depth end + def test_buffer_initial_length + s = JSON.state.new + assert_equal 1024, s.buffer_initial_length + s.buffer_initial_length = 0 + assert_equal 1024, s.buffer_initial_length + s.buffer_initial_length = -1 + assert_equal 1024, s.buffer_initial_length + s.buffer_initial_length = 128 + assert_equal 128, s.buffer_initial_length + end + def test_gc bignum_too_long_to_embed_as_string = 1234567890123456789012345 expect = bignum_too_long_to_embed_as_string.to_s @@ -210,4 +226,24 @@ EOT ensure GC.stress = stress end if GC.respond_to?(:stress=) + + def test_broken_bignum # [ruby-core:38867] + pid = fork do + Bignum.class_eval do + def to_s + end + end + begin + JSON::Ext::Generator::State.new.generate(1<<64) + exit 1 + rescue TypeError + exit 0 + end + end + _, status = Process.waitpid2(pid) + assert status.success? + rescue NotImplementedError + # forking to avoid modifying core class of a parent process and + # introducing race conditions of tests are run in parallel + end if defined?(JSON::Ext) end |