diff options
author | Famiu Haque <famiuhaque@protonmail.com> | 2022-04-18 09:02:32 +0600 |
---|---|---|
committer | Famiu Haque <famiuhaque@protonmail.com> | 2022-04-20 00:10:02 +0600 |
commit | 1e3d9c7dbc3ea186227ae27a93e683f750a32ce1 (patch) | |
tree | 90f69449f47ae0a3078dcb0c8742879793005a8c /test | |
parent | 0124a7bfa9e27796e561cb0b3a045b9327bf7077 (diff) | |
download | rneovim-1e3d9c7dbc3ea186227ae27a93e683f750a32ce1.tar.gz rneovim-1e3d9c7dbc3ea186227ae27a93e683f750a32ce1.tar.bz2 rneovim-1e3d9c7dbc3ea186227ae27a93e683f750a32ce1.zip |
feat: add `undo!`
Allows using `undo!` to undo changes and remove them from the undo-tree. Can only be used for moving backwards in the same undo branch.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/editor/undo_spec.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index a023ca3d90..a041428cdc 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -2,9 +2,18 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command +local eval = helpers.eval local expect = helpers.expect +local eq = helpers.eq local feed = helpers.feed +local feed_command = helpers.feed_command local insert = helpers.insert +local funcs = helpers.funcs + +local function lastmessage() + local messages = funcs.split(funcs.execute('messages'), '\n') + return messages[#messages] +end describe('u CTRL-R g- g+', function() before_each(clear) @@ -59,3 +68,61 @@ describe('u CTRL-R g- g+', function() undo_and_redo(4, 'g-', 'g+', '1') end) end) + +describe(':undo! command', function() + before_each(function() + clear() + feed('i1 little bug in the code<Esc>') + feed('o1 little bug in the code<Esc>') + feed('oTake 1 down, patch it around<Esc>') + feed('o99 little bugs in the code<Esc>') + end) + it('works', function() + feed_command('undo!') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around]]) + feed('<C-r>') + eq('Already at newest change', lastmessage()) + end) + it('works with arguments', function() + feed_command('undo! 2') + expect([[ + 1 little bug in the code + 1 little bug in the code]]) + feed('<C-r>') + eq('Already at newest change', lastmessage()) + end) + it('correctly sets alternative redo', function() + feed('uo101 little bugs in the code<Esc>') + feed_command('undo!') + feed('<C-r>') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around + 99 little bugs in the code]]) + + feed('uuoTake 2 down, patch them around<Esc>') + feed('o101 little bugs in the code<Esc>') + feed_command('undo! 2') + feed('<C-r><C-r>') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around + 99 little bugs in the code]]) + end) + it('fails when attempting to redo or move to different undo branch', function() + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + feed('u') + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + feed('o101 little bugs in the code<Esc>') + feed('o101 little bugs in the code<Esc>') + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + end) +end) |