diff options
author | Florian Frank <flori@ping.de> | 2010-08-07 11:09:56 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2010-08-07 12:08:06 +0200 |
commit | 1edf726ff3029e877350bc8db3217a64a74de581 (patch) | |
tree | 9d06ca2d650a514f5f42e2d46342a5fac45da0fd /tests/test_json_generate.rb | |
parent | bec5586cd5318e722fd599263105fa56b0bbe3e1 (diff) | |
download | json-1edf726ff3029e877350bc8db3217a64a74de581.tar.gz |
do not forget to dup the state
use state for depth checking in pure as well
Diffstat (limited to 'tests/test_json_generate.rb')
-rwxr-xr-x | tests/test_json_generate.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index 8dc804b..d67a4b2 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -164,4 +164,21 @@ EOT assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) } assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true) end + + def test_depth + ary = []; ary << ary + assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth + assert_raises(JSON::NestingError) { JSON.generate(ary) } + assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth + assert_equal 0, JSON::FAST_STATE_PROTOTYPE.depth + assert_raises(JSON::NestingError) { JSON.fast_generate(ary) } + assert_equal 0, JSON::FAST_STATE_PROTOTYPE.depth + assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth + assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) } + assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth + s = JSON.state.new + assert_equal 0, s.depth + assert_raises(JSON::NestingError) { ary.to_json(s) } + assert_equal 19, s.depth + end end |