summaryrefslogtreecommitdiff
path: root/test/reline/yamatanooroti
diff options
context:
space:
mode:
authorima1zumi <mariimaizumi5@gmail.com>2021-11-17 00:58:43 +0900
committergit <svn-admin@ruby-lang.org>2021-11-21 13:56:26 +0900
commitf5829e293583aa6ba6a1f1314ee22881d58a5f96 (patch)
treef8ec61d0bb33bc7eed7a58afc133df139e14e560 /test/reline/yamatanooroti
parentfeda058531c0bdd5b673180accb4407dcc798c79 (diff)
[ruby/reline] Correct padding space calculation
fix https://github.com/ruby/irb/issues/308 This bug occurred when `dialog.width - calculate_width(s, true)` was negative. When `dialog.width` is shorter than `old_dialog.width`, it calculates how much padding it has to do. However, there are cases where `s` is longer than `dialog.width`, as in the issue. In that case, `padding_space_with_escape_sequences` will crash. Here, `old_dialog.width` is longer than `dialog.width`, so I changed the padding width to `old_dialog.width - dialog.width`. https://github.com/ruby/reline/commit/c581c31e0f
Diffstat (limited to 'test/reline/yamatanooroti')
-rwxr-xr-xtest/reline/yamatanooroti/multiline_repl22
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb15
2 files changed, 37 insertions, 0 deletions
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index da886b8f06..1f2a023724 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -137,6 +137,28 @@ opt.on('--autocomplete-super-long') {
2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) }
}
}
+
+opt.on('--autocomplete-width-long') {
+ Reline.autocompletion = true
+ Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
+ %w{
+ remove_instance_variable
+ respond_to?
+ ruby2_keywords
+ rand
+ readline
+ readlines
+ require
+ require_relative
+ raise
+ respond_to_missing?
+ redo
+ rescue
+ retry
+ return
+ }.select{ |c| c.start_with?(target) }
+ }
+}
opt.parse!(ARGV)
begin
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index e1dde83589..f68b614327 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -1172,6 +1172,21 @@ begin
EOC
end
+ def test_autocomplete_old_dialog_width_greater_than_dialog_width
+ start_terminal(40, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-width-long}, startup_message: 'Multiline REPL.')
+ write("0+ \n12345678901234")
+ write("\C-p")
+ write("r")
+ write("a")
+ close
+ assert_screen(<<~'EOC')
+ Multiline REPL.
+ prompt> 0+ ra
+ prompt> 123rand 901234
+ raise
+ EOC
+ end
+
def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content