test(paste): add tests with virtualedit=onemore

This commit is contained in:
zeertzjq 2022-03-06 06:56:24 +08:00
parent e4ec8d7d50
commit 3470a9c3de

View File

@ -636,363 +636,374 @@ describe('API', function()
eq('Invalid phase: 4',
pcall_err(request, 'nvim_paste', 'foo', true, 4))
end)
it('stream: multiple chunks form one undo-block', function()
nvim('paste', '1/chunk 1 (start)\n', true, 1)
nvim('paste', '1/chunk 2 (end)\n', true, 3)
local expected1 = [[
1/chunk 1 (start)
1/chunk 2 (end)
]]
expect(expected1)
nvim('paste', '2/chunk 1 (start)\n', true, 1)
nvim('paste', '2/chunk 2\n', true, 2)
expect([[
1/chunk 1 (start)
1/chunk 2 (end)
2/chunk 1 (start)
2/chunk 2
]])
nvim('paste', '2/chunk 3\n', true, 2)
nvim('paste', '2/chunk 4 (end)\n', true, 3)
expect([[
1/chunk 1 (start)
1/chunk 2 (end)
2/chunk 1 (start)
2/chunk 2
2/chunk 3
2/chunk 4 (end)
]])
feed('u') -- Undo.
expect(expected1)
end)
it('stream: Insert mode', function()
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('i')
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('aaaaaabbbbbbccccccdddddd')
feed('<Esc>u')
expect('')
end)
describe('stream: Normal mode', function()
describe('on empty line', function()
before_each(function()
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
end)
after_each(function()
feed('u')
expect('')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('aaaaaabbbbbbccccccdddddd')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd]])
end)
local function run_streamed_paste_tests()
it('stream: multiple chunks form one undo-block', function()
nvim('paste', '1/chunk 1 (start)\n', true, 1)
nvim('paste', '1/chunk 2 (end)\n', true, 3)
local expected1 = [[
1/chunk 1 (start)
1/chunk 2 (end)
]]
expect(expected1)
nvim('paste', '2/chunk 1 (start)\n', true, 1)
nvim('paste', '2/chunk 2\n', true, 2)
expect([[
1/chunk 1 (start)
1/chunk 2 (end)
2/chunk 1 (start)
2/chunk 2
]])
nvim('paste', '2/chunk 3\n', true, 2)
nvim('paste', '2/chunk 4 (end)\n', true, 3)
expect([[
1/chunk 1 (start)
1/chunk 2 (end)
2/chunk 1 (start)
2/chunk 2
2/chunk 3
2/chunk 4 (end)
]])
feed('u') -- Undo.
expect(expected1)
end)
describe('not at the end of a line', function()
before_each(function()
feed('i||<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('0')
end)
after_each(function()
feed('u')
expect('||')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|aaaaaabbbbbbccccccdddddd|')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
|aaaaaa
bbbbbb
cccccc
dddddd|]])
end)
end)
describe('at the end of a line', function()
before_each(function()
feed('i||<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('$')
end)
after_each(function()
feed('u')
expect('||')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
||aaaaaa
bbbbbb
cccccc
dddddd]])
end)
end)
end)
describe('stream: Visual mode', function()
describe('neither end at the end of a line', function()
before_each(function()
feed('i|xxx<CR>xxx|<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('hvhk')
end)
after_each(function()
feed('u')
expect([[
|xxx
xxx|]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|aaaaaabbbbbbccccccdddddd|')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|bbbbbbccccccdddddd|')
end)
it('with all chunks empty', function()
nvim('paste', '', false, 1)
nvim('paste', '', false, 2)
nvim('paste', '', false, 2)
nvim('paste', '', false, 3)
expect('||')
end)
end)
describe('cursor at the end of a line', function()
before_each(function()
feed('i||xxx<CR>xxx<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('vko')
end)
after_each(function()
feed('u')
expect([[
||xxx
xxx]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||bbbbbbccccccdddddd')
end)
end)
describe('other end at the end of a line', function()
before_each(function()
feed('i||xxx<CR>xxx<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('vk')
end)
after_each(function()
feed('u')
expect([[
||xxx
xxx]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||bbbbbbccccccdddddd')
end)
end)
end)
describe('stream: linewise Visual mode', function()
before_each(function()
feed('i123456789<CR>987654321<CR>123456789<Esc>')
it('stream: Insert mode', function()
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('i')
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('aaaaaabbbbbbccccccdddddd')
feed('<Esc>u')
expect('')
end)
after_each(function()
feed('u')
expect([[
123456789
987654321
123456789]])
end)
describe('selecting the start of a file', function()
before_each(function()
feed('ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd987654321
123456789]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd
987654321
123456789]])
end)
end)
describe('selecting the middle of a file', function()
before_each(function()
feed('2ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
123456789
aaaaaa
bbbbbb
cccccc
dddddd123456789]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
123456789
aaaaaa
bbbbbb
cccccc
dddddd
123456789]])
end)
end)
describe('selecting the end of a file', function()
before_each(function()
feed('3ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
123456789
987654321
describe('stream: Normal mode', function()
describe('on empty line', function()
before_each(function()
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
end)
after_each(function()
feed('u')
expect('')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('aaaaaabbbbbbccccccdddddd')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd]])
end)
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
describe('not at the end of a line', function()
before_each(function()
feed('i||<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('0')
end)
after_each(function()
feed('u')
expect('||')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|aaaaaabbbbbbccccccdddddd|')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
|aaaaaa
bbbbbb
cccccc
dddddd|]])
end)
end)
describe('at the end of a line', function()
before_each(function()
feed('i||<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('2|')
end)
after_each(function()
feed('u')
expect('||')
end)
it('pasting one line', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('pasting multiple lines', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
||aaaaaa
bbbbbb
cccccc
dddddd]])
end)
end)
end)
describe('stream: Visual mode', function()
describe('neither end at the end of a line', function()
before_each(function()
feed('i|xxx<CR>xxx|<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('3|vhk')
end)
after_each(function()
feed('u')
expect([[
|xxx
xxx|]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|aaaaaabbbbbbccccccdddddd|')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('|bbbbbbccccccdddddd|')
end)
it('with all chunks empty', function()
nvim('paste', '', false, 1)
nvim('paste', '', false, 2)
nvim('paste', '', false, 2)
nvim('paste', '', false, 3)
expect('||')
end)
end)
describe('cursor at the end of a line', function()
before_each(function()
feed('i||xxx<CR>xxx<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('3|vko')
end)
after_each(function()
feed('u')
expect([[
||xxx
xxx]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||bbbbbbccccccdddddd')
end)
end)
describe('other end at the end of a line', function()
before_each(function()
feed('i||xxx<CR>xxx<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
feed('3|vk')
end)
after_each(function()
feed('u')
expect([[
||xxx
xxx]])
end)
it('with non-empty chunks', function()
nvim('paste', 'aaaaaa', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||aaaaaabbbbbbccccccdddddd')
end)
it('with empty first chunk', function()
nvim('paste', '', false, 1)
nvim('paste', 'bbbbbb', false, 2)
nvim('paste', 'cccccc', false, 2)
nvim('paste', 'dddddd', false, 3)
expect('||bbbbbbccccccdddddd')
end)
end)
end)
describe('stream: linewise Visual mode', function()
before_each(function()
feed('i123456789<CR>987654321<CR>123456789<Esc>')
-- If nvim_paste() calls :undojoin without making any changes, this makes it an error.
feed('afoo<Esc>u')
end)
after_each(function()
feed('u')
expect([[
123456789
987654321
aaaaaa
bbbbbb
cccccc
dddddd
]])
123456789]])
end)
describe('selecting the start of a file', function()
before_each(function()
feed('ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd987654321
123456789]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd
987654321
123456789]])
end)
end)
describe('selecting the middle of a file', function()
before_each(function()
feed('2ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
123456789
aaaaaa
bbbbbb
cccccc
dddddd123456789]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
123456789
aaaaaa
bbbbbb
cccccc
dddddd
123456789]])
end)
end)
describe('selecting the end of a file', function()
before_each(function()
feed('3ggV')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
123456789
987654321
aaaaaa
bbbbbb
cccccc
dddddd]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
123456789
987654321
aaaaaa
bbbbbb
cccccc
dddddd
]])
end)
end)
describe('selecting the whole file', function()
before_each(function()
feed('ggVG')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd
]])
end)
end)
end)
describe('selecting the whole file', function()
before_each(function()
feed('ggVG')
end)
it('pasting text without final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd]])
end)
it('pasting text with final new line', function()
nvim('paste', 'aaaaaa\n', false, 1)
nvim('paste', 'bbbbbb\n', false, 2)
nvim('paste', 'cccccc\n', false, 2)
nvim('paste', 'dddddd\n', false, 3)
expect([[
aaaaaa
bbbbbb
cccccc
dddddd
]])
end)
end
describe('without virtualedit,', function()
run_streamed_paste_tests()
end)
describe('with virtualedit=onemore,', function()
before_each(function()
command('set virtualedit=onemore')
end)
run_streamed_paste_tests()
end)
it('non-streaming', function()
-- With final "\n".