2020-03-21 05:40:15 -04:00
|
|
|
require 'reline'
|
|
|
|
|
2020-03-21 05:31:20 -04:00
|
|
|
begin
|
|
|
|
require 'yamatanooroti'
|
|
|
|
|
2020-03-21 05:40:15 -04:00
|
|
|
class Reline::TestRendering < Yamatanooroti::TestCase
|
2020-03-21 05:31:20 -04:00
|
|
|
def setup
|
2020-07-05 01:02:34 -04:00
|
|
|
@pwd = Dir.pwd
|
2020-07-12 10:29:45 -04:00
|
|
|
@tmpdir = File.join(File.expand_path(Dir.tmpdir), "test_reline_config_#{$$}")
|
2020-07-05 01:02:34 -04:00
|
|
|
begin
|
|
|
|
Dir.mkdir(@tmpdir)
|
|
|
|
rescue Errno::EEXIST
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
|
|
|
Dir.mkdir(@tmpdir)
|
|
|
|
end
|
|
|
|
Dir.chdir(@tmpdir)
|
2020-07-12 10:29:45 -04:00
|
|
|
@inputrc_backup = ENV['INPUTRC']
|
|
|
|
@inputrc_file = ENV['INPUTRC'] = File.join(@tmpdir, 'temporaty_inputrc')
|
2020-07-05 01:02:34 -04:00
|
|
|
File.unlink(@inputrc_file) if File.exist?(@inputrc_file)
|
2020-03-21 05:31:20 -04:00
|
|
|
end
|
|
|
|
|
2020-07-05 01:02:34 -04:00
|
|
|
def teardown
|
|
|
|
Dir.chdir(@pwd)
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
2020-07-12 10:29:45 -04:00
|
|
|
ENV['INPUTRC'] = @inputrc_backup
|
2020-07-05 01:02:34 -04:00
|
|
|
end
|
|
|
|
|
2020-03-21 05:31:20 -04:00
|
|
|
def test_history_back
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-03-21 05:31:20 -04:00
|
|
|
write(":a\n")
|
|
|
|
write("\C-p")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> :a
|
|
|
|
=> :a
|
|
|
|
prompt> :a
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_backspace
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-03-21 05:31:20 -04:00
|
|
|
write(":abc\C-h\n")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> :ab
|
|
|
|
=> :ab
|
|
|
|
prompt>
|
|
|
|
EOC
|
|
|
|
end
|
2020-05-16 05:25:56 -04:00
|
|
|
|
|
|
|
def test_autowrap
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-05-16 05:25:56 -04:00
|
|
|
write('01234567890123456789012')
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> 0123456789012345678901
|
|
|
|
2
|
|
|
|
EOC
|
|
|
|
end
|
2020-07-12 10:29:45 -04:00
|
|
|
|
2020-09-10 16:48:59 -04:00
|
|
|
def test_finish_autowrapped_line
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-09-10 16:48:59 -04:00
|
|
|
write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> [{'user'=>{'email'=>'a@a', 'id'=
|
|
|
|
>'ABC'}, 'version'=>4, 'status'=>'succee
|
|
|
|
ded'}]
|
|
|
|
=> [{"user"=>{"email"=>"a@a", "id"=>"ABC
|
|
|
|
"}, "version"=>4, "status"=>"succeeded"}
|
|
|
|
]
|
|
|
|
prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_finish_autowrapped_line_in_the_middle_of_lines
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-09-10 16:48:59 -04:00
|
|
|
write("[{'user'=>{'email'=>'abcdef@abcdef', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]#{"\C-b"*7}\n")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> [{'user'=>{'email'=>'a
|
|
|
|
bcdef@abcdef', 'id'=>'ABC'}, '
|
|
|
|
version'=>4, 'status'=>'succee
|
|
|
|
ded'}]
|
|
|
|
=> [{"user"=>{"email"=>"abcdef
|
|
|
|
@abcdef", "id"=>"ABC"}, "versi
|
|
|
|
on"=>4, "status"=>"succeeded"}
|
|
|
|
]
|
|
|
|
prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
2020-09-11 12:51:26 -04:00
|
|
|
def test_finish_autowrapped_line_in_the_middle_of_multilines
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(30, 16, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-09-11 12:51:26 -04:00
|
|
|
write("<<~EOM\n ABCDEFG\nEOM\n")
|
|
|
|
close
|
|
|
|
assert_screen(<<~'EOC')
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> <<~EOM
|
|
|
|
prompt> ABCDEF
|
|
|
|
G
|
|
|
|
prompt> EOM
|
|
|
|
=> "ABCDEFG\n"
|
|
|
|
prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
2020-07-12 10:29:45 -04:00
|
|
|
def test_prompt
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~'LINES'
|
|
|
|
"abc": "123"
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-12 10:29:45 -04:00
|
|
|
write("abc\n")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
prompt> 123
|
|
|
|
=> 123
|
|
|
|
prompt>
|
|
|
|
EOC
|
|
|
|
end
|
2020-07-12 17:47:43 -04:00
|
|
|
|
|
|
|
def test_mode_icon_emacs
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~LINES
|
|
|
|
set show-mode-in-prompt on
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-12 17:47:43 -04:00
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
@prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mode_icon_vi
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~LINES
|
|
|
|
set editing-mode vi
|
|
|
|
set show-mode-in-prompt on
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-12 17:47:43 -04:00
|
|
|
write(":a\n\C-[k")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
(ins)prompt> :a
|
|
|
|
=> :a
|
|
|
|
(cmd)prompt> :a
|
|
|
|
EOC
|
|
|
|
end
|
2020-07-20 07:52:07 -04:00
|
|
|
|
|
|
|
def test_original_mode_icon_emacs
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~LINES
|
|
|
|
set show-mode-in-prompt on
|
|
|
|
set emacs-mode-string [emacs]
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-20 07:52:07 -04:00
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
[emacs]prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_original_mode_icon_with_quote
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~LINES
|
|
|
|
set show-mode-in-prompt on
|
|
|
|
set emacs-mode-string "[emacs]"
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-20 07:52:07 -04:00
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
[emacs]prompt>
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_original_mode_icon_vi
|
2020-10-06 10:55:33 -04:00
|
|
|
write_inputrc <<~LINES
|
|
|
|
set editing-mode vi
|
|
|
|
set show-mode-in-prompt on
|
|
|
|
set vi-ins-mode-string "{InS}"
|
|
|
|
set vi-cmd-mode-string "{CmD}"
|
|
|
|
LINES
|
2020-10-09 08:30:57 -04:00
|
|
|
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
2020-07-20 07:52:07 -04:00
|
|
|
write(":a\n\C-[k")
|
|
|
|
close
|
|
|
|
assert_screen(<<~EOC)
|
|
|
|
Multiline REPL.
|
|
|
|
{InS}prompt> :a
|
|
|
|
=> :a
|
|
|
|
{CmD}prompt> :a
|
|
|
|
EOC
|
|
|
|
end
|
2020-10-06 10:55:33 -04:00
|
|
|
|
|
|
|
private def write_inputrc(content)
|
|
|
|
File.open(@inputrc_file, 'w') do |f|
|
|
|
|
f.write content
|
|
|
|
end
|
|
|
|
end
|
2020-03-21 05:31:20 -04:00
|
|
|
end
|
2020-03-21 05:41:14 -04:00
|
|
|
rescue LoadError, NameError
|
|
|
|
# On Ruby repository, this test suit doesn't run because Ruby repo doesn't
|
|
|
|
# have the yamatanooroti gem.
|
2020-03-21 05:31:20 -04:00
|
|
|
end
|