mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[json] Make json Ractor safe
This commit is contained in:
parent
4c2e7f26bd
commit
14d7d1df25
4 changed files with 52 additions and 1 deletions
34
test/json/ractor_test.rb
Normal file
34
test/json/ractor_test.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# encoding: utf-8
|
||||
# frozen_string_literal: false
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class JSONInRactorTest < Test::Unit::TestCase
|
||||
def setup
|
||||
skip unless defined? Ractor
|
||||
end
|
||||
|
||||
def test_generate
|
||||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||
begin;
|
||||
$VERBOSE = nil
|
||||
require "json"
|
||||
r = Ractor.new do
|
||||
json = JSON.generate({
|
||||
'a' => 2,
|
||||
'b' => 3.141,
|
||||
'c' => 'c',
|
||||
'd' => [ 1, "b", 3.14 ],
|
||||
'e' => { 'foo' => 'bar' },
|
||||
'g' => "\"\0\037",
|
||||
'h' => 1000.0,
|
||||
'i' => 0.001
|
||||
})
|
||||
JSON.parse(json)
|
||||
end
|
||||
expected_json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
|
||||
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
||||
assert_equal(JSON.parse(expected_json), r.take)
|
||||
end;
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue