Skip to content

Commit 46db711

Browse files
authored
Add assertion to auto_indent_proc's parameter, add Ctrl-d exit test (#574)
* Add auto_indent_proc's parameter assertion in multiline_repl * Add rendering test for Ctrl-d exit
1 parent f363a43 commit 46db711

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/reline/yamatanooroti/multiline_repl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,24 @@ opt.on('--dynamic-prompt-show-line') {
5959
}
6060
}
6161
}
62+
63+
def assert_auto_indent_params(lines, line_index, byte_pointer, is_newline)
64+
raise 'Wrong lines type' unless lines.all?(String)
65+
66+
line = lines[line_index]
67+
raise 'Wrong line_index value' unless line
68+
69+
# The condition `byte_pointer <= line.bytesize` is not satisfied. Maybe bug.
70+
# Instead, loose constraint `byte_pointer <= line.bytesize + 1` seems to be satisfied when is_newline is false.
71+
return if is_newline
72+
73+
raise 'byte_pointer out of bounds' unless byte_pointer <= line.bytesize + 1
74+
raise 'Invalid byte_pointer' unless line.byteslice(0, byte_pointer).valid_encoding?
75+
end
76+
6277
opt.on('--auto-indent') {
6378
Reline.auto_indent_proc = lambda do |lines, line_index, byte_pointer, is_newline|
79+
assert_auto_indent_params(lines, line_index, byte_pointer, is_newline)
6480
AutoIndent.calculate_indent(lines, line_index, byte_pointer, is_newline)
6581
end
6682
}

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,20 @@ def test_repeated_input_delete
15911591
EOC
15921592
end
15931593

1594+
def test_exit_with_ctrl_d
1595+
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
1596+
begin
1597+
write("\C-d")
1598+
close
1599+
rescue EOFError
1600+
# EOFError is raised when process terminated.
1601+
end
1602+
assert_screen(<<~EOC)
1603+
Multiline REPL.
1604+
prompt>
1605+
EOC
1606+
end
1607+
15941608
def write_inputrc(content)
15951609
File.open(@inputrc_file, 'w') do |f|
15961610
f.write content

0 commit comments

Comments
 (0)