summaryrefslogtreecommitdiff
path: root/test/reline/test_key_actor_vi.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/reline/test_key_actor_vi.rb')
-rw-r--r--test/reline/test_key_actor_vi.rb149
1 files changed, 147 insertions, 2 deletions
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index 1ea160b6b5..c6337baea7 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -9,8 +9,8 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
set editing-mode vi
LINES
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
- @line_editor = Reline::LineEditor.new(@config)
- @line_editor.reset(@prompt, @encoding)
+ @line_editor = Reline::LineEditor.new(@config, @encoding)
+ @line_editor.reset(@prompt, encoding: @encoding)
end
def test_vi_command_mode
@@ -24,6 +24,74 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
assert_line('abc')
end
+ def test_vi_insert
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys('i')
+ assert_line('i')
+ assert_cursor(1)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys("\C-[")
+ assert_line('i')
+ assert_cursor(0)
+ assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
+ input_keys('i')
+ assert_line('i')
+ assert_cursor(0)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ end
+
+ def test_vi_add
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys('a')
+ assert_line('a')
+ assert_cursor(1)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys("\C-[")
+ assert_line('a')
+ assert_cursor(0)
+ assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
+ input_keys('a')
+ assert_line('a')
+ assert_cursor(1)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ end
+
+ def test_vi_insert_at_bol
+ input_keys('I')
+ assert_line('I')
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys("12345\C-[hh")
+ assert_line('I12345')
+ assert_byte_pointer_size('I12')
+ assert_cursor(3)
+ assert_cursor_max(6)
+ assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
+ input_keys('I')
+ assert_line('I12345')
+ assert_byte_pointer_size('')
+ assert_cursor(0)
+ assert_cursor_max(6)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ end
+
+ def test_vi_add_at_eol
+ input_keys('A')
+ assert_line('A')
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ input_keys("12345\C-[hh")
+ assert_line('A12345')
+ assert_byte_pointer_size('A12')
+ assert_cursor(3)
+ assert_cursor_max(6)
+ assert_instance_of(Reline::KeyActor::ViCommand, @config.editing_mode)
+ input_keys('A')
+ assert_line('A12345')
+ assert_byte_pointer_size('A12345')
+ assert_cursor(6)
+ assert_cursor_max(6)
+ assert_instance_of(Reline::KeyActor::ViInsert, @config.editing_mode)
+ end
+
def test_ed_insert_one
input_keys('a')
assert_line('a')
@@ -565,6 +633,60 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
assert_cursor_max(6)
end
+ def test_vi_to_next_char
+ input_keys("abcdef\C-[0")
+ assert_line('abcdef')
+ assert_byte_pointer_size('')
+ assert_cursor(0)
+ assert_cursor_max(6)
+ input_keys('tz')
+ assert_line('abcdef')
+ assert_byte_pointer_size('')
+ assert_cursor(0)
+ assert_cursor_max(6)
+ input_keys('te')
+ assert_line('abcdef')
+ assert_byte_pointer_size('abc')
+ assert_cursor(3)
+ assert_cursor_max(6)
+ end
+
+ def test_vi_prev_char
+ input_keys("abcdef\C-[")
+ assert_line('abcdef')
+ assert_byte_pointer_size('abcde')
+ assert_cursor(5)
+ assert_cursor_max(6)
+ input_keys('Fz')
+ assert_line('abcdef')
+ assert_byte_pointer_size('abcde')
+ assert_cursor(5)
+ assert_cursor_max(6)
+ input_keys('Fa')
+ assert_line('abcdef')
+ assert_byte_pointer_size('')
+ assert_cursor(0)
+ assert_cursor_max(6)
+ end
+
+ def test_vi_to_prev_char
+ input_keys("abcdef\C-[")
+ assert_line('abcdef')
+ assert_byte_pointer_size('abcde')
+ assert_cursor(5)
+ assert_cursor_max(6)
+ input_keys('Tz')
+ assert_line('abcdef')
+ assert_byte_pointer_size('abcde')
+ assert_cursor(5)
+ assert_cursor_max(6)
+ input_keys('Ta')
+ assert_line('abcdef')
+ assert_byte_pointer_size('a')
+ assert_cursor(1)
+ assert_cursor_max(6)
+ end
+
def test_vi_delete_next_char
input_keys("abc\C-[h")
assert_byte_pointer_size('a')
@@ -1092,4 +1214,27 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
assert_cursor_max(11)
assert_line('aaa ddd eee')
end
+
+ def test_vi_change_meta
+ input_keys("aaa bbb ccc ddd eee\C-[02w")
+ assert_byte_pointer_size('aaa bbb ')
+ assert_cursor(8)
+ assert_cursor_max(19)
+ assert_line('aaa bbb ccc ddd eee')
+ input_keys('cwaiueo ')
+ assert_byte_pointer_size('aaa bbb aiueo ')
+ assert_cursor(14)
+ assert_cursor_max(21)
+ assert_line('aaa bbb aiueo ddd eee')
+ input_keys("\C-[")
+ assert_byte_pointer_size('aaa bbb aiueo')
+ assert_cursor(13)
+ assert_cursor_max(21)
+ assert_line('aaa bbb aiueo ddd eee')
+ input_keys('cb')
+ assert_byte_pointer_size('aaa bbb ')
+ assert_cursor(8)
+ assert_cursor_max(16)
+ assert_line('aaa bbb ddd eee')
+ end
end