Skip to content

Commit

Permalink
Add a test for dialog with scroll key
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 9, 2021
1 parent 29634cb commit 99640ab
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
51 changes: 40 additions & 11 deletions test/reline/yamatanooroti/multiline_repl
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,47 @@ opt.on('--dynamic-prompt-returns-empty') {
opt.on('--auto-indent') {
AutoIndent.new
}
opt.on('--simple-dialog') {
opt.on('--dialog VAL') { |v|
Reline.add_dialog_proc(:simple_dialog, lambda {
contents = <<~RUBY.split("\n")
Ruby is...
A dynamic, open source programming
language with a focus on simplicity
and productivity. It has an elegant
syntax that is natural to read and
easy to write.
RUBY
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents)
})
if v.include?('simple')
contents = <<~RUBY.split("\n")
Ruby is...
A dynamic, open source programming
language with a focus on simplicity
and productivity. It has an elegant
syntax that is natural to read and
easy to write.
RUBY
elsif v.include?('long')
contents = <<~RUBY.split("\n")
Ruby is...
A dynamic, open
source programming
language with a
focus on simplicity
and productivity.
It has an elegant
syntax that is
natural to read
and easy to write.
RUBY
end
if v.include?('scrollkey')
dialog.trap_key = nil
if key and key.match?(dialog.name)
if context.pointer.nil?
context.pointer = 0
elsif context.first > dialog.contents.size
context.pointer = 0
else
context.pointer += 1
end
end
dialog.trap_key = [?j.ord]
height = 4
end
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, pointer: context.pointer)
}, Struct.new(:pointer).new)
}
opt.on('--complete') {
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
Expand Down
17 changes: 16 additions & 1 deletion test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def test_completion_journey_with_empty_line
end

def test_simple_dialog
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --simple-dialog}, startup_message: 'Multiline REPL.')
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
write('a')
write('b')
write('c')
Expand All @@ -854,6 +854,21 @@ def test_simple_dialog
EOC
end

def test_simple_dialog_with_scroll_key
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog long,scrollkey}, startup_message: 'Multiline REPL.')
write('a')
5.times{ write('j') }
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt> a
A dynamic, open
source programming
language with a
focus on simplicity
EOC
end

def test_autocomplete
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write("Stri")
Expand Down

0 comments on commit 99640ab

Please sign in to comment.