Skip to content

Commit b8d2294

Browse files
authored
Merge pull request ruby#627 from casperisfine/json-load-proc
Add test coverage for JSON.load with a Proc
2 parents 259d3c1 + 9dd89ea commit b8d2294

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/json/json_common_interface_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ def test_load
107107
tempfile.close!
108108
end
109109

110+
def test_load_with_proc
111+
visited = []
112+
JSON.load('{"foo": [1, 2, 3], "bar": {"baz": "plop"}}', proc { |o| visited << JSON.dump(o) })
113+
114+
expected = [
115+
'"foo"',
116+
'1',
117+
'2',
118+
'3',
119+
'[1,2,3]',
120+
'"bar"',
121+
'"baz"',
122+
'"plop"',
123+
'{"baz":"plop"}',
124+
'{"foo":[1,2,3],"bar":{"baz":"plop"}}',
125+
]
126+
assert_equal expected, visited
127+
end
128+
110129
def test_load_with_options
111130
json = '{ "foo": NaN }'
112131
assert JSON.load(json, nil, :allow_nan => true)['foo'].nan?

0 commit comments

Comments
 (0)