aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/testdir/Makefile11
-rw-r--r--src/nvim/testdir/test61.in112
-rw-r--r--src/nvim/testdir/test61.ok49
-rw-r--r--test/functional/legacy/061_undo_tree_spec.lua279
4 files changed, 280 insertions, 171 deletions
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile
index b982dbcbb3..da99c6d1c4 100644
--- a/src/nvim/testdir/Makefile
+++ b/src/nvim/testdir/Makefile
@@ -19,7 +19,7 @@ SCRIPTS := test_eval.out \
test46.out test47.out test48.out test49.out \
test52.out test53.out test55.out \
test57.out test58.out test59.out \
- test61.out test62.out test63.out test64.out \
+ test62.out test63.out test64.out \
test68.out test69.out \
test71.out test73.out \
test79.out test80.out \
@@ -126,15 +126,6 @@ test1.out: .gdbinit test1.in
@-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1"
$(RUN_VIM) $*.in
- # For flaky tests retry one time.
- @/bin/sh -c "if test -f test.out -a $* = test61; then \
- if diff test.out $*.ok; then \
- echo flaky test ok first time; \
- else rm -rf $*.failed $(RM_ON_RUN); \
- $(RUN_VIM) $*.in; \
- fi; \
- fi"
-
# Check if the test.out file matches test.ok.
@/bin/sh -c "if test -f test.out; then \
if diff test.out $*.ok; then \
diff --git a/src/nvim/testdir/test61.in b/src/nvim/testdir/test61.in
deleted file mode 100644
index 87bb07a209..0000000000
--- a/src/nvim/testdir/test61.in
+++ /dev/null
@@ -1,112 +0,0 @@
-Tests for undo tree.
-Since this script is sourced we need to explicitly break changes up in
-undo-able pieces. Do that by setting 'undolevels'.
-Also tests :earlier and :later.
-
-STARTTEST
-:echo undotree().entries
-ENDTEST
-
-STARTTEST
-:" Delete three characters and undo
-Gx:set ul=100
-x:set ul=100
-x:.w! test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-:"
-:/^111/w >>test.out
-:" Delete three other characters and go back in time step by step
-$x:set ul=100
-x:set ul=100
-x:.w >>test.out
-:sleep 1
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-g-:.w >>test.out
-10g+:.w >>test.out
-:"
-:/^222/w >>test.out
-:" Delay for three seconds and go some seconds forward and backward
-:sleep 2
-Aa:set ul=100
-Ab:set ul=100
-Ac:set ul=100
-:.w >>test.out
-:ear 1s
-:.w >>test.out
-:ear 3s
-:.w >>test.out
-:later 1s
-:.w >>test.out
-:later 1h
-:.w >>test.out
-:"
-:" test undojoin
-Goaaaa:set ul=100
-obbbbu:.w >>test.out
-obbbb:set ul=100
-:undojoin
-occccu:.w >>test.out
-:e! Xtest
-ione one one:set ul=100
-:w!
-otwo:set ul=100
-otwo:set ul=100
-:w
-othree:earlier 1f
-:" expect "one one one\ntwo\ntwo"
-:%yank a
-:earlier 1f
-:" expect "one one one"
-:%yank b
-:earlier 1f
-:" expect empty line
-:%yank c
-:later 1f
-:" expect "one one one"
-:%yank d
-:later 1f
-:" expect "one one one\ntwo\ntwo"
-:%yank e
-:later 1f
-:" expect "one one one\ntwo\ntwo\nthree"
-ggO---:0put e
-ggO---:0put d
-ggO---:0put c
-ggO---:0put b
-ggO---:0put a
-ggO---:w >>test.out
-:so small.vim
-:enew!
-oa
-:set ul=100
-ob
-:set ul=100
-o1a2=setline('.','1234')
-
-uu:"
-oc
-:set ul=100
-o1a2=setline('.','1234')
-
-u:"
-od
-:set ul=100
-o1a2=string(123)
-u:"
-:%w >>test.out
-:qa!
-ENDTEST
-
-1111 -----
-2222 -----
-
-123456789
diff --git a/src/nvim/testdir/test61.ok b/src/nvim/testdir/test61.ok
deleted file mode 100644
index ea4b473ad7..0000000000
--- a/src/nvim/testdir/test61.ok
+++ /dev/null
@@ -1,49 +0,0 @@
-456789
-3456789
-23456789
-123456789
-123456789
-1111 -----
-123456
-1234567
-12345678
-456789
-3456789
-23456789
-123456789
-123456789
-123456789
-123456
-2222 -----
-123456abc
-123456
-123456789
-123456
-123456abc
-aaaa
-aaaa
----
-one one one
-two
-two
----
-one one one
----
-
----
-one one one
----
-one one one
-two
-two
----
-one one one
-two
-two
-three
-
-a
-b
-c
-12
-d
diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua
new file mode 100644
index 0000000000..651c928e17
--- /dev/null
+++ b/test/functional/legacy/061_undo_tree_spec.lua
@@ -0,0 +1,279 @@
+-- Tests for undo tree and :earlier and :later.
+
+local helpers = require('test.functional.helpers')
+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 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.
+ 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('undo:', function()
+ before_each(clear)
+ teardown(function()
+ os.remove('Xtest.source')
+ end)
+
+ describe(':earlier and :later', function()
+ before_each(function()
+ os.remove('Xtest')
+ end)
+ teardown(function()
+ os.remove('Xtest')
+ end)
+
+ it('work with time specifications and g- and g+', function()
+ -- We write the test text to a file in order to prevent nvim to record
+ -- the inserting of the text into the undo history.
+ write_file('Xtest', '\n123456789\n')
+
+
+ -- `:earlier` and `:later` are (obviously) time-sensitive, so this test
+ -- sometimes fails if the system is under load. It is wrapped in a local
+ -- function to allow multiple attempts.
+ local function test_earlier_later()
+ clear()
+ execute('e Xtest')
+ -- 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')
+ execute('sleep 1')
+ wait()
+ 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.
+ execute('sleep 2')
+ wait()
+ 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
+ local success, result = false, ''
+ for i = 1, 2 do
+ success, result = pcall(test_earlier_later)
+ if success then
+ return
+ end
+ end
+ -- We did not return in the loop so there was an error or failure.
+ -- We now try to run the test again but will not catch further errors,
+ -- so the user will see them.
+ test_earlier_later()
+ 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([[
+ normal Aaaaa
+ normal obbbb
+ normal occcc
+ ]])
+ expect([[
+ aaaa
+ bbbb
+ cccc]])
+ feed('u')
+ expect_empty_buffer()
+ 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([[
+ 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()
+ end)
+
+ it(':undojoin can join change blocks inside scripts', function()
+ feed('Goaaaa<esc>')
+ feed('obbbb<esc>u')
+ expect_line('aaaa')
+ source([[
+ normal obbbb
+ set ul=100
+ undojoin
+ normal occcc
+ ]])
+ feed('u')
+ expect_line('aaaa')
+ end)
+
+ it('undoing pastes from the expression register is working', function()
+ local normal_commands = 'o1\x1ba2\x12=string(123)\n\x1b'
+ write_file('Xtest.source', normal_commands)
+
+ feed('oa<esc>')
+ feed('ob<esc>')
+ feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
+ expect([[
+
+ a
+ b
+ 12034]])
+ feed('uu')
+ expect([[
+
+ a
+ b
+ 1]])
+ feed('oc<esc>')
+ feed([[o1<esc>a2<C-R>=setline('.','1234')<cr><esc>]])
+ expect([[
+
+ a
+ b
+ 1
+ c
+ 12034]])
+ feed('u')
+ expect([[
+
+ a
+ b
+ 1
+ c
+ 12]])
+ feed('od<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(normal_commands)
+ expect([[
+
+ a
+ b
+ 1
+ c
+ 12
+ d
+ 12123]])
+ feed('u')
+ expect([[
+
+ a
+ b
+ 1
+ c
+ 12
+ d
+ 1]])
+ end)
+end)