summaryrefslogtreecommitdiff
path: root/test/json/json_coder_test.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2025-09-18 20:33:41 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-09-19 15:48:55 +0900
commitdf81f0b02e5c496e6cd12224319f8dee9f0718d4 (patch)
tree639b576068969a2f4a67b0b9819ded8a2be826ff /test/json/json_coder_test.rb
parenta9e538e0b60577363e16b6411444e80169b9bc80 (diff)
`JSON::Coder` callback now recieve a second argument to mark object keyssync-gems
e.g. ```ruby { 1 => 2 } ``` The callback will be invoked for `1` as while it has a native JSON equivalent, it's not legal as an object name.
Diffstat (limited to 'test/json/json_coder_test.rb')
-rwxr-xr-xtest/json/json_coder_test.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/json/json_coder_test.rb b/test/json/json_coder_test.rb
index fc4aba2968..c724835376 100755
--- a/test/json/json_coder_test.rb
+++ b/test/json/json_coder_test.rb
@@ -12,7 +12,8 @@ class JSONCoderTest < Test::Unit::TestCase
end
def test_json_coder_with_proc_with_unsupported_value
- coder = JSON::Coder.new do |object|
+ coder = JSON::Coder.new do |object, is_key|
+ assert_equal false, is_key
Object.new
end
assert_raise(JSON::GeneratorError) { coder.dump([Object.new]) }
@@ -20,7 +21,10 @@ class JSONCoderTest < Test::Unit::TestCase
def test_json_coder_hash_key
obj = Object.new
- coder = JSON::Coder.new(&:to_s)
+ coder = JSON::Coder.new do |obj, is_key|
+ assert_equal true, is_key
+ obj.to_s
+ end
assert_equal %({#{obj.to_s.inspect}:1}), coder.dump({ obj => 1 })
coder = JSON::Coder.new { 42 }
@@ -49,14 +53,14 @@ class JSONCoderTest < Test::Unit::TestCase
end
def test_json_coder_dump_NaN_or_Infinity
- coder = JSON::Coder.new(&:inspect)
+ coder = JSON::Coder.new { |o| o.inspect }
assert_equal "NaN", coder.load(coder.dump(Float::NAN))
assert_equal "Infinity", coder.load(coder.dump(Float::INFINITY))
assert_equal "-Infinity", coder.load(coder.dump(-Float::INFINITY))
end
def test_json_coder_dump_NaN_or_Infinity_loop
- coder = JSON::Coder.new(&:itself)
+ coder = JSON::Coder.new { |o| o.itself }
error = assert_raise JSON::GeneratorError do
coder.dump(Float::NAN)
end