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

ruby-changes:55961

From: Nobuyoshi <ko1@a...>
Date: Mon, 3 Jun 2019 01:36:50 +0900 (JST)
Subject: [ruby-changes:55961] Nobuyoshi Nakada: 3457ce4486 (trunk): Fix ArgumentError in aliased macro

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

From 3457ce448655a3c2e52793186f62298903ddc26b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 2 Jun 2019 13:10:03 +0900
Subject: Fix ArgumentError in aliased macro

Closes: https://github.com/ruby/ruby/pull/2221

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 3fb4480..e4acdb9 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -641,6 +641,10 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L641
     end
   end
 
+  private def argumentable?(method_obj)
+    method_obj and method_obj.parameters.length != 1
+  end
+
   private def process_key(key, method_symbol)
     if method_symbol and respond_to?(method_symbol, true)
       method_obj = method(method_symbol)
@@ -648,14 +652,20 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L652
       method_obj = nil
     end
     if method_symbol and key.is_a?(Symbol)
-      method_obj&.(key, arg: @vi_arg)
+      if @vi_arg and argumentable?(method_obj)
+        run_for_operators(key, method_symbol) do
+          method_obj.(key, arg: @vi_arg)
+        end
+      else
+        method_obj&.(key)
+      end
       @kill_ring.process
       @vi_arg = nil
     elsif @vi_arg
       if key.chr =~ /[0-9]/
         ed_argument_digit(key)
       else
-        if ARGUMENTABLE.include?(method_symbol) and method_obj
+        if argumentable?(method_obj)
           run_for_operators(key, method_symbol) do
             method_obj.(key, arg: @vi_arg)
           end
diff --git a/test/reline/test_macro.rb b/test/reline/test_macro.rb
new file mode 100644
index 0000000..7d92b32
--- /dev/null
+++ b/test/reline/test_macro.rb
@@ -0,0 +1,34 @@ https://github.com/ruby/ruby/blob/trunk/test/reline/test_macro.rb#L1
+require_relative 'helper'
+
+class Reline::MacroTest < Reline::TestCase
+  def setup
+    @config = Reline::Config.new
+    @line_editor = Reline::LineEditor.new(@config)
+    @line_editor.instance_variable_set(:@screen_size, [24, 80])
+    @line_editor.output = File.open(IO::NULL, "w")
+  end
+
+  def input_key(char, combined_char = char, with_meta = false)
+    @line_editor.input_key(Reline::Key.new(char, combined_char, with_meta))
+  end
+
+  def input(str)
+    str.each_byte {|c| input_key(c)}
+  end
+
+  def test_simple_input
+    input('abc')
+    assert_equal 'abc', @line_editor.line
+  end
+
+  def test_alias
+    class << @line_editor
+      alias delete_char ed_delete_prev_char
+    end
+    input('abc')
+    assert_nothing_raised(ArgumentError) {
+      input_key(:delete_char)
+    }
+    assert_equal 'ab', @line_editor.line
+  end
+end
-- 
cgit v0.10.2


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

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