[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / psych / test_ractor.rb
blob1b0d8106098b556e227b66fe4e1ebe3630d10f09
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')
7       obj = {foo: [42]}
8       obj2 = Ractor.new(obj) do |obj|
9         Psych.unsafe_load(Psych.dump(obj))
10       end.take
11       assert_equal obj, obj2
12     RUBY
13   end
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) }
23     RUBY
24   end
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')
31       r = Ractor.new do
32         Psych.add_builtin_type 'omap' do |type, val|
33           val * 2
34         end
35         Psych.load('--- !!omap hello')
36       end.take
37       assert_equal 'hellohello', r
38       assert_equal 'hello', Psych.load('--- !!omap hello')
39     RUBY
40   end
42   def test_ractor_constants
43     assert_ractor(<<~RUBY, require_relative: 'helper')
44       r = Ractor.new do
45         Psych.libyaml_version.join('.') == Psych::LIBYAML_VERSION
46       end.take
47       assert_equal true, r
48     RUBY
49   end
50 end if defined?(Ractor)