Skip to content

Commit

Permalink
Add assertion to auto_indent_proc's parameter, add Ctrl-d exit test (#…
Browse files Browse the repository at this point in the history
…574)

* Add auto_indent_proc's parameter assertion in multiline_repl

* Add rendering test for Ctrl-d exit
  • Loading branch information
tompng authored Jul 19, 2023
1 parent f363a43 commit 46db711
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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

0 comments on commit 46db711

Please sign in to comment.