summaryrefslogtreecommitdiff
path: root/test/json
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-21 15:57:42 +0900
committerKenta Murata <mrkn@mrkn.jp>2020-12-21 22:10:43 +0900
commit14d7d1df25bbefadfc385042d541b4afc31e4c1b (patch)
tree4177058f76232748572fd6cf246044f79ae5f35d /test/json
parent4c2e7f26bda8df087a66e546744de0d0d467ea7c (diff)
[json] Make json Ractor safe
Diffstat (limited to 'test/json')
-rw-r--r--test/json/ractor_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/json/ractor_test.rb b/test/json/ractor_test.rb
new file mode 100644
index 0000000..96d1528
--- /dev/null
+++ b/test/json/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