diff src/testdir/test_listener.vim @ 19779:f3162c3ed128 v8.2.0446

patch 8.2.0446: listener with undo of deleting all lines not tested Commit: https://github.com/vim/vim/commit/a07e31af545b91925362854a48c42fee16dd8c28 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 25 21:13:46 2020 +0100 patch 8.2.0446: listener with undo of deleting all lines not tested Problem: Listener with undo of deleting all lines not tested. Solution: Add a test.
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Mar 2020 21:15:04 +0100
parents 36ec10251b2b
children 2fb397573541
line wrap: on
line diff
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -296,6 +296,31 @@ func Test_listener_undo_line_number()
   call listener_remove(lid)
 endfunc
 
+func Test_listener_undo_delete_all()
+  new
+  call setline(1, [1, 2, 3, 4])
+  let s:changes = []
+  func s:ExtendList(bufnr, start, end, added, changes)
+    call extend(s:changes, a:changes)
+  endfunc
+  let id = listener_add('s:ExtendList')
+
+  set undolevels&  " start new undo block
+  normal! ggdG
+  undo
+  call listener_flush()
+  call assert_equal(2, s:changes->len())
+  " delete removes four lines, empty line remains
+  call assert_equal({'lnum': 1, 'end': 5, 'col': 1, 'added': -4}, s:changes[0])
+  " undo replaces empty line and adds 3 lines
+  call assert_equal({'lnum': 1, 'end': 2, 'col': 1, 'added': 3}, s:changes[1])
+
+  call listener_remove(id)
+  delfunc s:ExtendList
+  unlet s:changes
+  bwipe!
+endfunc
+
 func Test_listener_cleared_newbuf()
   func Listener(bufnr, start, end, added, changes)
     let g:gotCalled += 1