Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertion to auto_indent_proc's parameter, add Ctrl-d exit test #574

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/reline/yamatanooroti/multiline_repl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down