[前][次][番号順一覧][スレッド一覧]

ruby-changes:71901

From: Hiroshi <ko1@a...>
Date: Fri, 20 May 2022 18:53:39 +0900 (JST)
Subject: [ruby-changes:71901] b6649797ee (master): Picked the missing test file from https://github.com/ruby/did_you_mean/commit/8faba54b2d3ec9aa570691775f143801308c5b2f

https://git.ruby-lang.org/ruby.git/commit/?id=b6649797ee

From b6649797ee8cc15330c2c050ba33d09859048996 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 20 May 2022 18:52:28 +0900
Subject: Picked the missing test file from
 https://github.com/ruby/did_you_mean/commit/8faba54b2d3ec9aa570691775f143801308c5b2f

---
 test/did_you_mean/test_ractor_compatibility.rb | 102 +++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 test/did_you_mean/test_ractor_compatibility.rb

diff --git a/test/did_you_mean/test_ractor_compatibility.rb b/test/did_you_mean/test_ractor_compatibility.rb
new file mode 100644
index 0000000000..1a9e63997f
--- /dev/null
+++ b/test/did_you_mean/test_ractor_compatibility.rb
@@ -0,0 +1,102 @@ https://github.com/ruby/ruby/blob/trunk/test/did_you_mean/test_ractor_compatibility.rb#L1
+require_relative './helper'
+
+return if not DidYouMean::TestHelper.ractor_compatible?
+
+class RactorCompatibilityTest < Test::Unit::TestCase
+  include DidYouMean::TestHelper
+
+  class ::Book; end
+  class FirstNameError < NameError; end
+
+  def test_class_name_suggestion_works_in_ractor
+    error = Ractor.new {
+              begin
+                Boook
+              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 {
+                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
+    end
+  end
+
+  def test_can_raise_other_name_error_in_ractor
+    error = Ractor.new {
+      begin
+        raise FirstNameError, "Other name error"
+      rescue FirstNameError => e
+        e.corrections # It is important to call the #corrections method within Ractor.
+        e
+      end
+    }.take
+
+    assert_not_match(/Did you mean\?/, error.message)
+  end
+
+  def test_variable_name_suggestion_works_in_ractor
+    error = Ractor.new {
+      in_ractor = in_ractor = 1
+
+      begin
+        in_reactor
+      rescue NameError => e
+        e.corrections # It is important to call the #corrections method within Ractor.
+        e
+      end
+    }.take
+
+    assert_correction :in_ractor, error.corrections
+    assert_match "Did you mean?  in_ractor", error.to_s
+  end
+end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]