[ruby/reline] Add assertion to auto_indent_proc's parameter, add

Ctrl-d exit test
(https://github.com/ruby/reline/pull/574)

* Add auto_indent_proc's parameter assertion in multiline_repl

* Add rendering test for Ctrl-d exit

https://github.com/ruby/reline/commit/46db71132a
This commit is contained in:
tomoya ishida 2023-07-19 22:31:13 +09:00 committed by git
parent ca561480ea
commit 7380c73af4
2 changed files with 30 additions and 0 deletions

View File

@ -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
}

View File

@ -1591,6 +1591,20 @@ begin
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