2020-12-21 09:57:42 +03:00
|
|
|
# frozen_string_literal: false
|
|
|
|
|
2023-08-26 01:32:13 +03:00
|
|
|
require_relative 'test_helper'
|
2020-12-21 09:57:42 +03:00
|
|
|
|
2023-12-01 10:46:42 +03:00
|
|
|
begin
|
|
|
|
require_relative './lib/helper'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2022-11-10 23:21:36 +03:00
|
|
|
|
2020-12-21 09:57:42 +03:00
|
|
|
class JSONInRactorTest < Test::Unit::TestCase
|
|
|
|
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
|
2020-12-22 12:18:32 +03:00
|
|
|
end if defined?(Ractor)
|