From 398da71175ef9154be505155c0b1c0b2efb20445 Mon Sep 17 00:00:00 2001 From: Quang-Minh Nguyen Date: Fri, 18 Sep 2020 13:02:14 +0700 Subject: Validate name during initialization --- bootstraptest/test_ractor.rb | 50 +++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'bootstraptest/test_ractor.rb') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 4b6afc2c53..9cfd42c5f4 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -8,6 +8,37 @@ assert_equal 'Ractor', %q{ Ractor.new{}.class } +# A Ractor can have a name +assert_equal 'test-name', %q{ + r = Ractor.new name: 'test-name' do + end + r.name +} + +# If Ractor doesn't have a name, Ractor#name returns nil. +assert_equal 'nil', %q{ + r = Ractor.new do + end + r.name.inspect +} + +# Raises exceptions if initialize with invalid name +assert_equal 'no implicit conversion of Array into String', %q{ + begin + r = Ractor.new(name: [{}]) {} + rescue TypeError => e + e.message + end +} + +assert_equal 'ASCII incompatible encoding (UTF-16BE)', %q{ + begin + r = Ractor.new(name: String.new('Invalid encoding', encoding: 'UTF-16BE')) {} + rescue ArgumentError => e + e.message + end +} + # Ractor.new must call with a block assert_equal "must be called with a block", %q{ begin @@ -263,7 +294,7 @@ assert_equal 'false', %q{ r = Ractor.new obj do |msg| msg.object_id end - + obj.object_id == r.take } @@ -360,7 +391,7 @@ assert_equal 'hello', %q{ str = r.take begin - r.take + r.take rescue Ractor::RemoteError str #=> "hello" end @@ -528,20 +559,6 @@ assert_equal '[1000, 3]', %q{ Ractor.new{ [A.size, H.size] }.take } -# A Ractor can have a name -assert_equal 'test-name', %q{ - r = Ractor.new name: 'test-name' do - end - r.name -} - -# If Ractor doesn't have a name, Ractor#name returns nil. -assert_equal 'nil', %q{ - r = Ractor.new do - end - r.name.inspect -} - ### ### Synchronization tests ### @@ -559,4 +576,3 @@ assert_equal "#{N}#{N}", %Q{ } end # if !ENV['GITHUB_WORKFLOW'] - -- cgit v1.2.3