summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-21 15:57:42 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-22 13:58:03 +0900
commitf1d5fb030ce758b96e13817290964d92e3516d82 (patch)
treea3f4efbdbd25f2927aa72756f969f8d5a0e083cc /tests
parentae5ef25af52b2b92d7ecf40feeca09c324c0d777 (diff)
downloadjson-f1d5fb030ce758b96e13817290964d92e3516d82.tar.gz
[json] Make json Ractor safe
Diffstat (limited to 'tests')
-rw-r--r--tests/ractor_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ractor_test.rb b/tests/ractor_test.rb
new file mode 100644
index 0000000..96d1528
--- /dev/null
+++ b/tests/ractor_test.rb
@@ -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