mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
tests: Fix an further simplify migrated test 61.
:undojoin can only be used inside scripts and command chains. So it has to be tested inside an explicit `source()` call. Also add a new test case for the different behavior when sourceing normal mode commands from a script or inserting them interactively.
This commit is contained in:
parent
981dd23f8d
commit
2ce3656754
@ -5,84 +5,89 @@ local feed, insert, source, eq, eval, clear, execute, expect, wait =
|
||||
helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval,
|
||||
helpers.clear, helpers.execute, helpers.expect, helpers.wait
|
||||
|
||||
local expect_empty_buffer = function()
|
||||
local function expect_empty_buffer()
|
||||
-- The space will be removed by helpers.dedent but is needed as dedent will
|
||||
-- throw an error if it can not find the common indent of the given lines.
|
||||
expect(' ')
|
||||
return expect(' ')
|
||||
end
|
||||
local function expect_line(line)
|
||||
return eq(line, eval('getline(".")'))
|
||||
end
|
||||
local function write_file(name, text)
|
||||
local file = io.open(name, 'w')
|
||||
file:write(text)
|
||||
file:flush()
|
||||
file:close()
|
||||
end
|
||||
|
||||
|
||||
describe('the undo tree', function()
|
||||
setup(clear)
|
||||
setup(function()
|
||||
clear()
|
||||
write_file('Xtest.source', 'o1\x1ba2\x12=string(123)\n\x1b')
|
||||
write_file('Xtest0', '\n123456789\n')
|
||||
end)
|
||||
teardown(function()
|
||||
os.remove('Xtest0')
|
||||
os.remove('Xtest')
|
||||
os.remove('Xtest.source')
|
||||
end)
|
||||
|
||||
it('is working', function()
|
||||
execute('e Xtest0')
|
||||
-- Assert that no undo history is present.
|
||||
eq({}, eval('undotree().entries'))
|
||||
insert([[
|
||||
|
||||
123456789]])
|
||||
|
||||
-- Clear the undo history after the insertion (see :h clear-undo)
|
||||
execute('let old_undolevels = &undolevels')
|
||||
execute('set undolevels=-1')
|
||||
feed('a <BS><Esc>')
|
||||
execute('let &undolevels = old_undolevels')
|
||||
execute('unlet old_undolevels')
|
||||
eq({}, eval('undotree().entries'))
|
||||
|
||||
-- Delete three characters and undo.
|
||||
feed('Gxxx')
|
||||
eq('456789', eval('getline(".")'))
|
||||
expect_line('456789')
|
||||
feed('g-')
|
||||
eq('3456789', eval('getline(".")'))
|
||||
expect_line('3456789')
|
||||
feed('g-')
|
||||
eq('23456789', eval('getline(".")'))
|
||||
expect_line('23456789')
|
||||
feed('g-')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456789')
|
||||
feed('g-')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456789')
|
||||
|
||||
-- Delete three other characters and go back in time step by step.
|
||||
feed('$xxx')
|
||||
eq('123456', eval('getline(".")'))
|
||||
expect_line('123456')
|
||||
execute('sleep 1')
|
||||
wait()
|
||||
feed('g-')
|
||||
eq('1234567', eval('getline(".")'))
|
||||
expect_line('1234567')
|
||||
feed('g-')
|
||||
eq('12345678', eval('getline(".")'))
|
||||
expect_line('12345678')
|
||||
feed('g-')
|
||||
eq('456789', eval('getline(".")'))
|
||||
expect_line('456789')
|
||||
feed('g-')
|
||||
eq('3456789', eval('getline(".")'))
|
||||
expect_line('3456789')
|
||||
feed('g-')
|
||||
eq('23456789', eval('getline(".")'))
|
||||
expect_line('23456789')
|
||||
feed('g-')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456789')
|
||||
feed('g-')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456789')
|
||||
feed('g-')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456789')
|
||||
feed('10g+')
|
||||
eq('123456', eval('getline(".")'))
|
||||
expect_line('123456')
|
||||
|
||||
-- Delay for three seconds and go some seconds forward and backward.
|
||||
-- Delay for two seconds and go some seconds forward and backward.
|
||||
execute('sleep 2')
|
||||
wait()
|
||||
feed('Aa<esc>')
|
||||
feed('Ab<esc>')
|
||||
feed('Ac<esc>')
|
||||
eq('123456abc', eval('getline(".")'))
|
||||
execute('ear 1s')
|
||||
eq('123456', eval('getline(".")'))
|
||||
execute('ear 3s')
|
||||
eq('123456789', eval('getline(".")'))
|
||||
expect_line('123456abc')
|
||||
execute('earlier 1s')
|
||||
expect_line('123456')
|
||||
execute('earlier 3s')
|
||||
expect_line('123456789')
|
||||
execute('later 1s')
|
||||
eq('123456', eval('getline(".")'))
|
||||
expect_line('123456')
|
||||
execute('later 1h')
|
||||
eq('123456abc', eval('getline(".")'))
|
||||
expect_line('123456abc')
|
||||
|
||||
-- Test that setting 'ul' breaks change blocks, we need to use source() in
|
||||
-- order to test this, as interactive changes are not grouped.
|
||||
@ -123,13 +128,15 @@ describe('the undo tree', function()
|
||||
-- Test undojoin.
|
||||
feed('Goaaaa<esc>')
|
||||
feed('obbbb<esc>u')
|
||||
eq('aaaa', eval('getline(".")'))
|
||||
feed('obbbb<esc>')
|
||||
execute('undojoin')
|
||||
feed('occcc<esc>u')
|
||||
-- TODO At this point the original test will write "aaaa" to test.out.
|
||||
-- Why is the line "bbbb" here?
|
||||
eq('bbbb', eval('getline(".")'))
|
||||
expect_line('aaaa')
|
||||
source([[
|
||||
normal obbbb
|
||||
set ul=100
|
||||
undojoin
|
||||
normal occcc
|
||||
]])
|
||||
feed('u')
|
||||
expect_line('aaaa')
|
||||
|
||||
execute('e! Xtest')
|
||||
feed('ione one one<esc>')
|
||||
@ -195,7 +202,32 @@ describe('the undo tree', function()
|
||||
c
|
||||
12]])
|
||||
feed('od<esc>')
|
||||
feed('o1<esc>a2<C-R>=string(123)<cr><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')
|
||||
expect([[
|
||||
|
||||
a
|
||||
b
|
||||
1
|
||||
c
|
||||
12
|
||||
d
|
||||
12123]])
|
||||
feed('u')
|
||||
expect([[
|
||||
|
||||
a
|
||||
b
|
||||
1
|
||||
c
|
||||
12
|
||||
d]])
|
||||
-- The above behaviour was tested in the legacy vim test because the
|
||||
-- legacy tests were executed with ':so!'. The behavior differs for
|
||||
-- interactive use (even in vim, where the result was the same):
|
||||
feed(io.open('Xtest.source'):read('*all'))
|
||||
expect([[
|
||||
|
||||
a
|
||||
@ -205,13 +237,6 @@ describe('the undo tree', function()
|
||||
12
|
||||
d
|
||||
12123]])
|
||||
|
||||
-- TODO there is a difference between the original test and this test at
|
||||
-- this point. The original tests expects the last line to go away after
|
||||
-- the undo. I do not know why this should be the case as the "o" and "a"
|
||||
-- above are seperate changes. I was able to confirm this manually with
|
||||
-- vim and nvim. Both end up in this state (treat "o" and "a" as two
|
||||
-- edits).
|
||||
feed('u')
|
||||
expect([[
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user