mirror of
https://github.com/neovim/neovim.git
synced 2025-11-09 20:15:24 +00:00
tests: Split test 61 into several it() blocks.
This commit is contained in:
@@ -20,79 +20,113 @@ local function write_file(name, text)
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe('undo:', function()
|
||||||
describe('the undo tree', function()
|
before_each(clear)
|
||||||
setup(function()
|
|
||||||
clear()
|
|
||||||
write_file('Xtest.source', 'o1\x1ba2\x12=string(123)\n\x1b')
|
|
||||||
write_file('Xtest0', '\n123456789\n')
|
|
||||||
end)
|
|
||||||
teardown(function()
|
teardown(function()
|
||||||
os.remove('Xtest0')
|
|
||||||
os.remove('Xtest')
|
|
||||||
os.remove('Xtest.source')
|
os.remove('Xtest.source')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('is working', function()
|
describe(':earlier and :later', function()
|
||||||
execute('e Xtest0')
|
before_each(function()
|
||||||
-- Assert that no undo history is present.
|
os.remove('Xtest')
|
||||||
eq({}, eval('undotree().entries'))
|
end)
|
||||||
-- Delete three characters and undo.
|
teardown(function()
|
||||||
feed('Gxxx')
|
os.remove('Xtest')
|
||||||
expect_line('456789')
|
end)
|
||||||
feed('g-')
|
|
||||||
expect_line('3456789')
|
|
||||||
feed('g-')
|
|
||||||
expect_line('23456789')
|
|
||||||
feed('g-')
|
|
||||||
expect_line('123456789')
|
|
||||||
feed('g-')
|
|
||||||
expect_line('123456789')
|
|
||||||
|
|
||||||
-- Delete three other characters and go back in time step by step.
|
it('work with time specifications and g- and g+', function()
|
||||||
feed('$xxx')
|
-- We write the test text to a file in order to prevent nvim to record
|
||||||
expect_line('123456')
|
-- the inserting of the text into the undo history.
|
||||||
execute('sleep 1')
|
write_file('Xtest', '\n123456789\n')
|
||||||
wait()
|
execute('e Xtest')
|
||||||
feed('g-')
|
-- Assert that no undo history is present.
|
||||||
expect_line('1234567')
|
eq({}, eval('undotree().entries'))
|
||||||
feed('g-')
|
-- Delete three characters and undo.
|
||||||
expect_line('12345678')
|
feed('Gxxx')
|
||||||
feed('g-')
|
expect_line('456789')
|
||||||
expect_line('456789')
|
feed('g-')
|
||||||
feed('g-')
|
expect_line('3456789')
|
||||||
expect_line('3456789')
|
feed('g-')
|
||||||
feed('g-')
|
expect_line('23456789')
|
||||||
expect_line('23456789')
|
feed('g-')
|
||||||
feed('g-')
|
expect_line('123456789')
|
||||||
expect_line('123456789')
|
feed('g-')
|
||||||
feed('g-')
|
expect_line('123456789')
|
||||||
expect_line('123456789')
|
|
||||||
feed('g-')
|
|
||||||
expect_line('123456789')
|
|
||||||
feed('10g+')
|
|
||||||
expect_line('123456')
|
|
||||||
|
|
||||||
-- Delay for two seconds and go some seconds forward and backward.
|
-- Delete three other characters and go back in time step by step.
|
||||||
execute('sleep 2')
|
feed('$xxx')
|
||||||
wait()
|
expect_line('123456')
|
||||||
feed('Aa<esc>')
|
execute('sleep 1')
|
||||||
feed('Ab<esc>')
|
wait()
|
||||||
feed('Ac<esc>')
|
feed('g-')
|
||||||
expect_line('123456abc')
|
expect_line('1234567')
|
||||||
execute('earlier 1s')
|
feed('g-')
|
||||||
expect_line('123456')
|
expect_line('12345678')
|
||||||
execute('earlier 3s')
|
feed('g-')
|
||||||
expect_line('123456789')
|
expect_line('456789')
|
||||||
execute('later 1s')
|
feed('g-')
|
||||||
expect_line('123456')
|
expect_line('3456789')
|
||||||
execute('later 1h')
|
feed('g-')
|
||||||
expect_line('123456abc')
|
expect_line('23456789')
|
||||||
|
feed('g-')
|
||||||
|
expect_line('123456789')
|
||||||
|
feed('g-')
|
||||||
|
expect_line('123456789')
|
||||||
|
feed('g-')
|
||||||
|
expect_line('123456789')
|
||||||
|
feed('10g+')
|
||||||
|
expect_line('123456')
|
||||||
|
|
||||||
-- Test that setting 'ul' breaks change blocks, we need to use source() in
|
-- Delay for two seconds and go some seconds forward and backward.
|
||||||
-- order to test this, as interactive changes are not grouped.
|
execute('sleep 2')
|
||||||
execute('new')
|
wait()
|
||||||
-- First verify that scripts produce single big undo blocks.
|
feed('Aa<esc>')
|
||||||
|
feed('Ab<esc>')
|
||||||
|
feed('Ac<esc>')
|
||||||
|
expect_line('123456abc')
|
||||||
|
execute('earlier 1s')
|
||||||
|
expect_line('123456')
|
||||||
|
execute('earlier 3s')
|
||||||
|
expect_line('123456789')
|
||||||
|
execute('later 1s')
|
||||||
|
expect_line('123456')
|
||||||
|
execute('later 1h')
|
||||||
|
expect_line('123456abc')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('work with file write specifications', function()
|
||||||
|
feed('ione one one<esc>')
|
||||||
|
execute('w Xtest')
|
||||||
|
feed('otwo<esc>')
|
||||||
|
feed('otwo<esc>')
|
||||||
|
execute('w')
|
||||||
|
feed('othree<esc>')
|
||||||
|
execute('earlier 1f')
|
||||||
|
expect([[
|
||||||
|
one one one
|
||||||
|
two
|
||||||
|
two]])
|
||||||
|
execute('earlier 1f')
|
||||||
|
expect('one one one')
|
||||||
|
execute('earlier 1f')
|
||||||
|
expect_empty_buffer()
|
||||||
|
execute('later 1f')
|
||||||
|
expect('one one one')
|
||||||
|
execute('later 1f')
|
||||||
|
expect([[
|
||||||
|
one one one
|
||||||
|
two
|
||||||
|
two]])
|
||||||
|
execute('later 1f')
|
||||||
|
expect([[
|
||||||
|
one one one
|
||||||
|
two
|
||||||
|
two
|
||||||
|
three]])
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('scripts produce one undo block for all changes by default', function()
|
||||||
source([[
|
source([[
|
||||||
normal Aaaaa
|
normal Aaaaa
|
||||||
normal obbbb
|
normal obbbb
|
||||||
@@ -104,7 +138,11 @@ describe('the undo tree', function()
|
|||||||
cccc]])
|
cccc]])
|
||||||
feed('u')
|
feed('u')
|
||||||
expect_empty_buffer()
|
expect_empty_buffer()
|
||||||
-- Verify that undo blocks can be broken inside scripts by setting 'ul'.
|
end)
|
||||||
|
|
||||||
|
it('setting undolevel can break change blocks (inside scripts)', function()
|
||||||
|
-- We need to use source() in order to test this, as interactive changes
|
||||||
|
-- are not grouped.
|
||||||
source([[
|
source([[
|
||||||
normal Aaaaa
|
normal Aaaaa
|
||||||
set ul=100
|
set ul=100
|
||||||
@@ -124,8 +162,9 @@ describe('the undo tree', function()
|
|||||||
expect('aaaa')
|
expect('aaaa')
|
||||||
feed('u')
|
feed('u')
|
||||||
expect_empty_buffer()
|
expect_empty_buffer()
|
||||||
|
end)
|
||||||
-- Test undojoin.
|
|
||||||
|
it(':undojoin can join change blocks inside scripts', function()
|
||||||
feed('Goaaaa<esc>')
|
feed('Goaaaa<esc>')
|
||||||
feed('obbbb<esc>u')
|
feed('obbbb<esc>u')
|
||||||
expect_line('aaaa')
|
expect_line('aaaa')
|
||||||
@@ -137,38 +176,12 @@ describe('the undo tree', function()
|
|||||||
]])
|
]])
|
||||||
feed('u')
|
feed('u')
|
||||||
expect_line('aaaa')
|
expect_line('aaaa')
|
||||||
|
end)
|
||||||
|
|
||||||
execute('e! Xtest')
|
it('undoing pastes from the expression register is working', function()
|
||||||
feed('ione one one<esc>')
|
local normal_commands = 'o1\x1ba2\x12=string(123)\n\x1b'
|
||||||
execute('w!')
|
write_file('Xtest.source', normal_commands)
|
||||||
feed('otwo<esc>')
|
|
||||||
feed('otwo<esc>')
|
|
||||||
execute('w')
|
|
||||||
feed('othree<esc>')
|
|
||||||
execute('earlier 1f')
|
|
||||||
expect([[
|
|
||||||
one one one
|
|
||||||
two
|
|
||||||
two]])
|
|
||||||
execute('earlier 1f')
|
|
||||||
expect('one one one')
|
|
||||||
execute('earlier 1f')
|
|
||||||
expect_empty_buffer()
|
|
||||||
execute('later 1f')
|
|
||||||
expect('one one one')
|
|
||||||
execute('later 1f')
|
|
||||||
expect([[
|
|
||||||
one one one
|
|
||||||
two
|
|
||||||
two]])
|
|
||||||
execute('later 1f')
|
|
||||||
expect([[
|
|
||||||
one one one
|
|
||||||
two
|
|
||||||
two
|
|
||||||
three]])
|
|
||||||
|
|
||||||
execute('enew!')
|
|
||||||
feed('oa<esc>')
|
feed('oa<esc>')
|
||||||
feed('ob<esc>')
|
feed('ob<esc>')
|
||||||
feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
|
feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
|
||||||
@@ -177,7 +190,6 @@ describe('the undo tree', function()
|
|||||||
a
|
a
|
||||||
b
|
b
|
||||||
12034]])
|
12034]])
|
||||||
|
|
||||||
feed('uu')
|
feed('uu')
|
||||||
expect([[
|
expect([[
|
||||||
|
|
||||||
@@ -202,9 +214,6 @@ describe('the undo tree', function()
|
|||||||
c
|
c
|
||||||
12]])
|
12]])
|
||||||
feed('od<esc>')
|
feed('od<esc>')
|
||||||
-- The file Xtest.source is written during setup. It contains this text
|
|
||||||
-- (nvim like escape sequences interpreted):
|
|
||||||
-- o1<esc>a2<C-R>=string(123)<cr><esc>
|
|
||||||
execute('so! Xtest.source')
|
execute('so! Xtest.source')
|
||||||
expect([[
|
expect([[
|
||||||
|
|
||||||
@@ -227,7 +236,7 @@ describe('the undo tree', function()
|
|||||||
-- The above behaviour was tested in the legacy vim test because the
|
-- The above behaviour was tested in the legacy vim test because the
|
||||||
-- legacy tests were executed with ':so!'. The behavior differs for
|
-- legacy tests were executed with ':so!'. The behavior differs for
|
||||||
-- interactive use (even in vim, where the result was the same):
|
-- interactive use (even in vim, where the result was the same):
|
||||||
feed(io.open('Xtest.source'):read('*all'))
|
feed(normal_commands)
|
||||||
expect([[
|
expect([[
|
||||||
|
|
||||||
a
|
a
|
||||||
|
|||||||
Reference in New Issue
Block a user