1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Rewrite with assert_ractor for multiple ractor environment

This commit is contained in:
Hiroshi SHIBATA 2022-05-20 19:48:21 +09:00
parent a080651f46
commit 4146fd284b
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2

View file

@ -3,12 +3,10 @@ require_relative './helper'
return if not DidYouMean::TestHelper.ractor_compatible? return if not DidYouMean::TestHelper.ractor_compatible?
class RactorCompatibilityTest < Test::Unit::TestCase class RactorCompatibilityTest < Test::Unit::TestCase
include DidYouMean::TestHelper
class ::Book; end
class FirstNameError < NameError; end
def test_class_name_suggestion_works_in_ractor def test_class_name_suggestion_works_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
class ::Book; end
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
begin begin
Boook Boook
@ -19,9 +17,12 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take }.take
assert_correction "Book", error.corrections assert_correction "Book", error.corrections
CODE
end end
def test_key_name_suggestion_works_in_ractor def test_key_name_suggestion_works_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
begin begin
hash = { "foo" => 1, bar: 2 } hash = { "foo" => 1, bar: 2 }
@ -35,9 +36,12 @@ class RactorCompatibilityTest < Test::Unit::TestCase
assert_correction ":bar", error.corrections assert_correction ":bar", error.corrections
assert_match "Did you mean? :bar", error.to_s assert_match "Did you mean? :bar", error.to_s
CODE
end end
def test_method_name_suggestion_works_in_ractor def test_method_name_suggestion_works_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
begin begin
self.to__s self.to__s
@ -49,10 +53,13 @@ class RactorCompatibilityTest < Test::Unit::TestCase
assert_correction :to_s, error.corrections assert_correction :to_s, error.corrections
assert_match "Did you mean? to_s", error.to_s assert_match "Did you mean? to_s", error.to_s
CODE
end end
if defined?(::NoMatchingPatternKeyError) if defined?(::NoMatchingPatternKeyError)
def test_pattern_key_name_suggestion_works_in_ractor def test_pattern_key_name_suggestion_works_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
begin begin
eval(<<~RUBY, binding, __FILE__, __LINE__) eval(<<~RUBY, binding, __FILE__, __LINE__)
@ -68,10 +75,14 @@ class RactorCompatibilityTest < Test::Unit::TestCase
assert_correction ":foo", error.corrections assert_correction ":foo", error.corrections
assert_match "Did you mean? :foo", error.to_s assert_match "Did you mean? :foo", error.to_s
CODE
end end
end end
def test_can_raise_other_name_error_in_ractor def test_can_raise_other_name_error_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
class FirstNameError < NameError; end
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
begin begin
raise FirstNameError, "Other name error" raise FirstNameError, "Other name error"
@ -82,9 +93,12 @@ class RactorCompatibilityTest < Test::Unit::TestCase
}.take }.take
assert_not_match(/Did you mean\?/, error.message) assert_not_match(/Did you mean\?/, error.message)
CODE
end end
def test_variable_name_suggestion_works_in_ractor def test_variable_name_suggestion_works_in_ractor
assert_ractor(<<~CODE, require_relative: "helper")
include DidYouMean::TestHelper
error = Ractor.new { error = Ractor.new {
in_ractor = in_ractor = 1 in_ractor = in_ractor = 1
@ -98,5 +112,6 @@ class RactorCompatibilityTest < Test::Unit::TestCase
assert_correction :in_ractor, error.corrections assert_correction :in_ractor, error.corrections
assert_match "Did you mean? in_ractor", error.to_s assert_match "Did you mean? in_ractor", error.to_s
CODE
end end
end end