Skip to content

Commit

Permalink
Add test coverage for JSON.load with a Proc
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Oct 18, 2024
1 parent 259d3c1 commit 9dd89ea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/json/json_common_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ def test_load
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?
Expand Down

0 comments on commit 9dd89ea

Please sign in to comment.