Skip to content

Commit d02e403

Browse files
etiennebarriebyroot
authored andcommitted
Test depth
1 parent 9d32cf4 commit d02e403

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/json/json_generator_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ def test_allow_nan
282282
end
283283

284284
def test_depth
285+
pretty = { object_nl: "\n", array_nl: "\n", space: " ", indent: " " }
286+
state = JSON.state.new(**pretty)
287+
assert_equal %({\n "foo": 42\n}), JSON.generate({ foo: 42 }, pretty)
288+
assert_equal %({\n "foo": 42\n}), state.generate(foo: 42)
289+
state.depth = 1
290+
assert_equal %({\n "foo": 42\n }), JSON.generate({ foo: 42 }, pretty.merge(depth: 1))
291+
assert_equal %({\n "foo": 42\n }), state.generate(foo: 42)
292+
end
293+
294+
def test_depth_nesting_error
285295
ary = []; ary << ary
286296
assert_raise(JSON::NestingError) { generate(ary) }
287297
assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) }

0 commit comments

Comments
 (0)