From 4e74fcf70f32406d2f8a661abbe3ee69e1d1ef52 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 19 Jul 2023 05:56:39 +0900 Subject: [PATCH 1/2] Add auto_indent_proc's parameter assertion in multiline_repl --- test/reline/yamatanooroti/multiline_repl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl index 73f5159ee2..bdefc48faa 100755 --- a/test/reline/yamatanooroti/multiline_repl +++ b/test/reline/yamatanooroti/multiline_repl @@ -59,8 +59,24 @@ opt.on('--dynamic-prompt-show-line') { } } } + +def assert_auto_indent_params(lines, line_index, byte_pointer, is_newline) + raise 'Wrong lines type' unless lines.all?(String) + + line = lines[line_index] + raise 'Wrong line_index value' unless line + + # The condition `byte_pointer <= line.bytesize` is not satisfied. Maybe bug. + # Instead, loose constraint `byte_pointer <= line.bytesize + 1` seems to be satisfied when is_newline is false. + return if is_newline + + raise 'byte_pointer out of bounds' unless byte_pointer <= line.bytesize + 1 + raise 'Invalid byte_pointer' unless line.byteslice(0, byte_pointer).valid_encoding? +end + opt.on('--auto-indent') { Reline.auto_indent_proc = lambda do |lines, line_index, byte_pointer, is_newline| + assert_auto_indent_params(lines, line_index, byte_pointer, is_newline) AutoIndent.calculate_indent(lines, line_index, byte_pointer, is_newline) end } From fe276df84d269e6d40d2bca857c8ec8935ab107f Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 19 Jul 2023 06:06:21 +0900 Subject: [PATCH 2/2] Add rendering test for Ctrl-d exit --- test/reline/yamatanooroti/test_rendering.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 985884393a..c72e47fd38 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -1591,6 +1591,20 @@ def test_repeated_input_delete EOC end + def test_exit_with_ctrl_d + start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.') + begin + write("\C-d") + close + rescue EOFError + # EOFError is raised when process terminated. + end + assert_screen(<<~EOC) + Multiline REPL. + prompt> + EOC + end + def write_inputrc(content) File.open(@inputrc_file, 'w') do |f| f.write content