зеркало из https://github.com/github/ruby.git
Rewrite with assert_ractor for multiple ractor environment
This commit is contained in:
Родитель
a080651f46
Коммит
4146fd284b
|
@ -3,100 +3,115 @@ 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
|
||||||
error = Ractor.new {
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
begin
|
class ::Book; end
|
||||||
Boook
|
include DidYouMean::TestHelper
|
||||||
rescue NameError => e
|
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
|
||||||
e
|
|
||||||
end
|
|
||||||
}.take
|
|
||||||
|
|
||||||
assert_correction "Book", error.corrections
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_key_name_suggestion_works_in_ractor
|
|
||||||
error = Ractor.new {
|
|
||||||
begin
|
|
||||||
hash = { "foo" => 1, bar: 2 }
|
|
||||||
|
|
||||||
hash.fetch(:bax)
|
|
||||||
rescue KeyError => e
|
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
|
||||||
e
|
|
||||||
end
|
|
||||||
}.take
|
|
||||||
|
|
||||||
assert_correction ":bar", error.corrections
|
|
||||||
assert_match "Did you mean? :bar", error.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_method_name_suggestion_works_in_ractor
|
|
||||||
error = Ractor.new {
|
|
||||||
begin
|
|
||||||
self.to__s
|
|
||||||
rescue NoMethodError => e
|
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
|
||||||
e
|
|
||||||
end
|
|
||||||
}.take
|
|
||||||
|
|
||||||
assert_correction :to_s, error.corrections
|
|
||||||
assert_match "Did you mean? to_s", error.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
if defined?(::NoMatchingPatternKeyError)
|
|
||||||
def test_pattern_key_name_suggestion_works_in_ractor
|
|
||||||
error = Ractor.new {
|
error = Ractor.new {
|
||||||
begin
|
begin
|
||||||
eval(<<~RUBY, binding, __FILE__, __LINE__)
|
Boook
|
||||||
hash = {foo: 1, bar: 2, baz: 3}
|
rescue NameError => e
|
||||||
hash => {fooo:}
|
|
||||||
fooo = 1 # suppress "unused variable: fooo" warning
|
|
||||||
RUBY
|
|
||||||
rescue NoMatchingPatternKeyError => e
|
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
e
|
e
|
||||||
end
|
end
|
||||||
}.take
|
}.take
|
||||||
|
|
||||||
assert_correction ":foo", error.corrections
|
assert_correction "Book", error.corrections
|
||||||
assert_match "Did you mean? :foo", error.to_s
|
CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_key_name_suggestion_works_in_ractor
|
||||||
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
|
include DidYouMean::TestHelper
|
||||||
|
error = Ractor.new {
|
||||||
|
begin
|
||||||
|
hash = { "foo" => 1, bar: 2 }
|
||||||
|
|
||||||
|
hash.fetch(:bax)
|
||||||
|
rescue KeyError => e
|
||||||
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
|
e
|
||||||
|
end
|
||||||
|
}.take
|
||||||
|
|
||||||
|
assert_correction ":bar", error.corrections
|
||||||
|
assert_match "Did you mean? :bar", error.to_s
|
||||||
|
CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_method_name_suggestion_works_in_ractor
|
||||||
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
|
include DidYouMean::TestHelper
|
||||||
|
error = Ractor.new {
|
||||||
|
begin
|
||||||
|
self.to__s
|
||||||
|
rescue NoMethodError => e
|
||||||
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
|
e
|
||||||
|
end
|
||||||
|
}.take
|
||||||
|
|
||||||
|
assert_correction :to_s, error.corrections
|
||||||
|
assert_match "Did you mean? to_s", error.to_s
|
||||||
|
CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
if defined?(::NoMatchingPatternKeyError)
|
||||||
|
def test_pattern_key_name_suggestion_works_in_ractor
|
||||||
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
|
include DidYouMean::TestHelper
|
||||||
|
error = Ractor.new {
|
||||||
|
begin
|
||||||
|
eval(<<~RUBY, binding, __FILE__, __LINE__)
|
||||||
|
hash = {foo: 1, bar: 2, baz: 3}
|
||||||
|
hash => {fooo:}
|
||||||
|
fooo = 1 # suppress "unused variable: fooo" warning
|
||||||
|
RUBY
|
||||||
|
rescue NoMatchingPatternKeyError => e
|
||||||
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
|
e
|
||||||
|
end
|
||||||
|
}.take
|
||||||
|
|
||||||
|
assert_correction ":foo", error.corrections
|
||||||
|
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
|
||||||
error = Ractor.new {
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
begin
|
class FirstNameError < NameError; end
|
||||||
raise FirstNameError, "Other name error"
|
include DidYouMean::TestHelper
|
||||||
rescue FirstNameError => e
|
error = Ractor.new {
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
begin
|
||||||
e
|
raise FirstNameError, "Other name error"
|
||||||
end
|
rescue FirstNameError => e
|
||||||
}.take
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
|
e
|
||||||
|
end
|
||||||
|
}.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
|
||||||
error = Ractor.new {
|
assert_ractor(<<~CODE, require_relative: "helper")
|
||||||
in_ractor = in_ractor = 1
|
include DidYouMean::TestHelper
|
||||||
|
error = Ractor.new {
|
||||||
|
in_ractor = in_ractor = 1
|
||||||
|
|
||||||
begin
|
begin
|
||||||
in_reactor
|
in_reactor
|
||||||
rescue NameError => e
|
rescue NameError => e
|
||||||
e.corrections # It is important to call the #corrections method within Ractor.
|
e.corrections # It is important to call the #corrections method within Ractor.
|
||||||
e
|
e
|
||||||
end
|
end
|
||||||
}.take
|
}.take
|
||||||
|
|
||||||
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
|
||||||
|
|
Загрузка…
Ссылка в новой задаче