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

Fix ArgumentError in aliased macro

Closes: https://github.com/ruby/ruby/pull/2221
This commit is contained in:
Nobuyoshi Nakada 2019-06-02 13:10:03 +09:00 committed by aycabta
parent f4b060d8d7
commit 3457ce4486
2 changed files with 46 additions and 2 deletions

View file

@ -641,6 +641,10 @@ class Reline::LineEditor
end end
end end
private def argumentable?(method_obj)
method_obj and method_obj.parameters.length != 1
end
private def process_key(key, method_symbol) private def process_key(key, method_symbol)
if method_symbol and respond_to?(method_symbol, true) if method_symbol and respond_to?(method_symbol, true)
method_obj = method(method_symbol) method_obj = method(method_symbol)
@ -648,14 +652,20 @@ class Reline::LineEditor
method_obj = nil method_obj = nil
end end
if method_symbol and key.is_a?(Symbol) 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 @kill_ring.process
@vi_arg = nil @vi_arg = nil
elsif @vi_arg elsif @vi_arg
if key.chr =~ /[0-9]/ if key.chr =~ /[0-9]/
ed_argument_digit(key) ed_argument_digit(key)
else else
if ARGUMENTABLE.include?(method_symbol) and method_obj if argumentable?(method_obj)
run_for_operators(key, method_symbol) do run_for_operators(key, method_symbol) do
method_obj.(key, arg: @vi_arg) method_obj.(key, arg: @vi_arg)
end end

34
test/reline/test_macro.rb Normal file
View file

@ -0,0 +1,34 @@
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