* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / json / ractor_test.rb
blob71105e55ecd22d1a1a33a5f9f1d26bba9822f5cd
1 # encoding: utf-8
2 # frozen_string_literal: false
4 require 'test_helper'
6 class JSONInRactorTest < Test::Unit::TestCase
7   def test_generate
8     assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
9     begin;
10       $VERBOSE = nil
11       require "json"
12       r = Ractor.new do
13         json = JSON.generate({
14           'a' => 2,
15           'b' => 3.141,
16           'c' => 'c',
17           'd' => [ 1, "b", 3.14 ],
18           'e' => { 'foo' => 'bar' },
19           'g' => "\"\0\037",
20           'h' => 1000.0,
21           'i' => 0.001
22         })
23         JSON.parse(json)
24       end
25       expected_json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
26                       '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
27       assert_equal(JSON.parse(expected_json), r.take)
28     end;
29   end
30 end if defined?(Ractor)