1 # frozen_string_literal: true
2 require_relative 'helper'
4 class TestPsychRactor < Test::Unit::TestCase
5 def test_ractor_round_trip
6 assert_ractor(<<~RUBY, require_relative: 'helper')
8 obj2 = Ractor.new(obj) do |obj|
9 Psych.unsafe_load(Psych.dump(obj))
11 assert_equal obj, obj2
15 def test_not_shareable
16 # There's no point in making these frozen / shareable
17 # and the C-ext disregards begin frozen
18 assert_ractor(<<~RUBY, require_relative: 'helper')
19 parser = Psych::Parser.new
20 emitter = Psych::Emitter.new(nil)
21 assert_raise(Ractor::Error) { Ractor.make_shareable(parser) }
22 assert_raise(Ractor::Error) { Ractor.make_shareable(emitter) }
26 def test_ractor_config
27 # Config is ractor-local
28 # Test is to make sure it works, even though usage is probably very low.
29 # The methods are not documented and might be deprecated one day
30 assert_ractor(<<~RUBY, require_relative: 'helper')
32 Psych.add_builtin_type 'omap' do |type, val|
35 Psych.load('--- !!omap hello')
37 assert_equal 'hellohello', r
38 assert_equal 'hello', Psych.load('--- !!omap hello')
42 def test_ractor_constants
43 assert_ractor(<<~RUBY, require_relative: 'helper')
45 Psych.libyaml_version.join('.') == Psych::LIBYAML_VERSION
50 end if defined?(Ractor)