[ruby/json] Add test coverage for JSON.load with a Proc

Fix: https://github.com/ruby/json/issues/438

https://github.com/ruby/json/commit/9dd89eaac8
This commit is contained in:
Jean Boussier 2024-10-18 15:48:00 +02:00 committed by Hiroshi SHIBATA
parent 9045258c88
commit 18cc663aef

View File

@ -107,6 +107,25 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
tempfile.close!
end
def test_load_with_proc
visited = []
JSON.load('{"foo": [1, 2, 3], "bar": {"baz": "plop"}}', proc { |o| visited << JSON.dump(o) })
expected = [
'"foo"',
'1',
'2',
'3',
'[1,2,3]',
'"bar"',
'"baz"',
'"plop"',
'{"baz":"plop"}',
'{"foo":[1,2,3],"bar":{"baz":"plop"}}',
]
assert_equal expected, visited
end
def test_load_with_options
json = '{ "foo": NaN }'
assert JSON.load(json, nil, :allow_nan => true)['foo'].nan?