2015-06-18 04:11:32 -07:00
|
|
|
-- Tests for undo tree and :earlier and :later.
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-05-15 10:03:48 -07:00
|
|
|
|
2017-04-08 14:12:26 -07:00
|
|
|
local feed_command = helpers.feed_command
|
2016-04-23 16:53:11 -07:00
|
|
|
local write_file = helpers.write_file
|
|
|
|
local command = helpers.command
|
|
|
|
local source = helpers.source
|
|
|
|
local expect = helpers.expect
|
|
|
|
local clear = helpers.clear
|
|
|
|
local feed = helpers.feed
|
|
|
|
local eval = helpers.eval
|
|
|
|
local eq = helpers.eq
|
2015-05-15 10:03:48 -07:00
|
|
|
|
2015-06-18 09:01:19 -07:00
|
|
|
local function expect_empty_buffer()
|
2015-06-22 19:52:25 -07:00
|
|
|
-- The space will be removed by helpers.dedent but is needed because dedent
|
|
|
|
-- will fail if it can not find the common indent of the given lines.
|
2015-06-18 09:01:19 -07:00
|
|
|
return expect(' ')
|
|
|
|
end
|
|
|
|
local function expect_line(line)
|
|
|
|
return eq(line, eval('getline(".")'))
|
|
|
|
end
|
2015-06-18 04:11:32 -07:00
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
describe('undo tree:', function()
|
2015-06-22 02:15:50 -07:00
|
|
|
before_each(clear)
|
2023-04-11 02:18:54 -07:00
|
|
|
local fname = 'Xtest_functional_legacy_undotree'
|
2015-05-15 10:03:48 -07:00
|
|
|
teardown(function()
|
2023-04-11 02:18:54 -07:00
|
|
|
os.remove(fname .. '.source')
|
2015-05-15 10:03:48 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-22 02:15:50 -07:00
|
|
|
describe(':earlier and :later', function()
|
|
|
|
before_each(function()
|
2023-04-11 02:18:54 -07:00
|
|
|
os.remove(fname)
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
|
|
|
teardown(function()
|
2023-04-11 02:18:54 -07:00
|
|
|
os.remove(fname)
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it('time specifications, g- g+', function()
|
2015-06-22 02:15:50 -07:00
|
|
|
-- We write the test text to a file in order to prevent nvim to record
|
|
|
|
-- the inserting of the text into the undo history.
|
2023-04-11 02:18:54 -07:00
|
|
|
write_file(fname, '\n123456789\n')
|
2015-06-22 02:15:50 -07:00
|
|
|
|
2015-06-22 07:01:39 -07:00
|
|
|
-- `:earlier` and `:later` are (obviously) time-sensitive, so this test
|
2015-06-30 05:16:22 -07:00
|
|
|
-- sometimes fails if the system is under load. It is wrapped in a local
|
2015-06-22 07:01:39 -07:00
|
|
|
-- function to allow multiple attempts.
|
|
|
|
local function test_earlier_later()
|
2015-06-22 19:52:25 -07:00
|
|
|
clear()
|
2023-04-11 02:18:54 -07:00
|
|
|
feed_command('e ' .. fname)
|
2015-06-22 07:01:39 -07:00
|
|
|
-- Assert that no undo history is present.
|
|
|
|
eq({}, eval('undotree().entries'))
|
|
|
|
-- Delete three characters and undo.
|
|
|
|
feed('Gxxx')
|
|
|
|
expect_line('456789')
|
|
|
|
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.
|
|
|
|
feed('$xxx')
|
|
|
|
expect_line('123456')
|
2016-04-21 08:06:03 -07:00
|
|
|
command('sleep 1')
|
2015-06-22 07:01:39 -07:00
|
|
|
feed('g-')
|
|
|
|
expect_line('1234567')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('12345678')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('456789')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('3456789')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('23456789')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('123456789')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('123456789')
|
|
|
|
feed('g-')
|
|
|
|
expect_line('123456789')
|
|
|
|
feed('10g+')
|
|
|
|
expect_line('123456')
|
|
|
|
|
|
|
|
-- Delay for two seconds and go some seconds forward and backward.
|
2016-04-21 08:06:03 -07:00
|
|
|
command('sleep 2')
|
2015-06-22 07:01:39 -07:00
|
|
|
feed('Aa<esc>')
|
|
|
|
feed('Ab<esc>')
|
|
|
|
feed('Ac<esc>')
|
|
|
|
expect_line('123456abc')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('earlier 1s')
|
2015-06-22 07:01:39 -07:00
|
|
|
expect_line('123456')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('earlier 3s')
|
2015-06-22 07:01:39 -07:00
|
|
|
expect_line('123456789')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('later 1s')
|
2015-06-22 07:01:39 -07:00
|
|
|
expect_line('123456')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('later 1h')
|
2015-06-22 07:01:39 -07:00
|
|
|
expect_line('123456abc')
|
|
|
|
end
|
2015-06-22 19:52:25 -07:00
|
|
|
|
2016-12-14 08:56:00 -07:00
|
|
|
helpers.retry(2, nil, test_earlier_later)
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
2015-05-15 10:03:48 -07:00
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it('file-write specifications', function()
|
2015-06-22 02:15:50 -07:00
|
|
|
feed('ione one one<esc>')
|
2023-04-11 02:18:54 -07:00
|
|
|
feed_command('w ' .. fname)
|
2015-06-22 02:15:50 -07:00
|
|
|
feed('otwo<esc>')
|
|
|
|
feed('otwo<esc>')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('w')
|
2015-06-22 02:15:50 -07:00
|
|
|
feed('othree<esc>')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('earlier 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect([[
|
2015-06-22 07:01:39 -07:00
|
|
|
one one one
|
|
|
|
two
|
|
|
|
two]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('earlier 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect('one one one')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('earlier 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect_empty_buffer()
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('later 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect('one one one')
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('later 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect([[
|
2015-06-22 07:01:39 -07:00
|
|
|
one one one
|
|
|
|
two
|
|
|
|
two]])
|
2017-04-08 14:12:26 -07:00
|
|
|
feed_command('later 1f')
|
2015-06-22 02:15:50 -07:00
|
|
|
expect([[
|
2015-06-22 07:01:39 -07:00
|
|
|
one one one
|
|
|
|
two
|
|
|
|
two
|
|
|
|
three]])
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
|
|
|
end)
|
2015-05-15 10:03:48 -07:00
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it('scripts produce one undo-block for all changes by default', function()
|
2015-06-18 04:11:32 -07:00
|
|
|
source([[
|
|
|
|
normal Aaaaa
|
|
|
|
normal obbbb
|
|
|
|
normal occcc
|
|
|
|
]])
|
|
|
|
expect([[
|
|
|
|
aaaa
|
|
|
|
bbbb
|
|
|
|
cccc]])
|
|
|
|
feed('u')
|
|
|
|
expect_empty_buffer()
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it("setting 'undolevel' can break undo-blocks (inside scripts)", function()
|
|
|
|
-- :source is required (because interactive changes are _not_ grouped,
|
|
|
|
-- even with :undojoin).
|
2015-06-18 04:11:32 -07:00
|
|
|
source([[
|
|
|
|
normal Aaaaa
|
|
|
|
set ul=100
|
|
|
|
normal obbbb
|
|
|
|
set ul=100
|
|
|
|
normal occcc
|
|
|
|
]])
|
|
|
|
expect([[
|
|
|
|
aaaa
|
|
|
|
bbbb
|
|
|
|
cccc]])
|
|
|
|
feed('u')
|
|
|
|
expect([[
|
|
|
|
aaaa
|
|
|
|
bbbb]])
|
|
|
|
feed('u')
|
|
|
|
expect('aaaa')
|
|
|
|
feed('u')
|
|
|
|
expect_empty_buffer()
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it(':undojoin can join undo-blocks inside scripts', function()
|
2015-05-15 10:03:48 -07:00
|
|
|
feed('Goaaaa<esc>')
|
|
|
|
feed('obbbb<esc>u')
|
2015-06-18 09:01:19 -07:00
|
|
|
expect_line('aaaa')
|
|
|
|
source([[
|
|
|
|
normal obbbb
|
|
|
|
set ul=100
|
|
|
|
undojoin
|
|
|
|
normal occcc
|
|
|
|
]])
|
|
|
|
feed('u')
|
|
|
|
expect_line('aaaa')
|
2015-06-22 02:15:50 -07:00
|
|
|
end)
|
2015-05-15 10:03:48 -07:00
|
|
|
|
2015-06-22 19:52:25 -07:00
|
|
|
it('undo an expression-register', function()
|
2016-03-06 15:48:36 -07:00
|
|
|
local normal_commands = 'o1\027a2\018=string(123)\n\027'
|
2023-04-11 02:18:54 -07:00
|
|
|
write_file(fname .. '.source', normal_commands)
|
2015-05-15 10:03:48 -07:00
|
|
|
|
|
|
|
feed('oa<esc>')
|
|
|
|
feed('ob<esc>')
|
|
|
|
feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
12034]])
|
|
|
|
feed('uu')
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1]])
|
|
|
|
feed('oc<esc>')
|
|
|
|
feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12034]])
|
|
|
|
feed('u')
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12]])
|
|
|
|
feed('od<esc>')
|
2023-04-11 02:18:54 -07:00
|
|
|
feed_command('so! ' .. fname .. '.source')
|
2015-06-18 09:01:19 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-06-18 09:01:19 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12
|
|
|
|
d
|
|
|
|
12123]])
|
|
|
|
feed('u')
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-06-18 09:01:19 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12
|
|
|
|
d]])
|
2015-06-22 19:52:25 -07:00
|
|
|
|
|
|
|
-- The above behaviour was tested in the legacy Vim test because the
|
2015-06-18 09:01:19 -07:00
|
|
|
-- legacy tests were executed with ':so!'. The behavior differs for
|
2015-06-22 19:52:25 -07:00
|
|
|
-- interactive use (even in Vim; see ":help :undojoin"):
|
2015-06-22 02:15:50 -07:00
|
|
|
feed(normal_commands)
|
2015-05-15 10:03:48 -07:00
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12
|
|
|
|
d
|
|
|
|
12123]])
|
|
|
|
feed('u')
|
|
|
|
expect([[
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2015-05-15 10:03:48 -07:00
|
|
|
a
|
|
|
|
b
|
|
|
|
1
|
|
|
|
c
|
|
|
|
12
|
|
|
|
d
|
|
|
|
1]])
|
|
|
|
end)
|
|
|
|
end)
|