diff src/testdir/test_listener.vim @ 19044:af795b6a2624

patch 8.2.0082: when reusing a buffer listeners are not cleared Commit: https://github.com/vim/vim/commit/f10997a1543eb0724d882da3678bacd44e647141 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 3 21:00:02 2020 +0100 patch 8.2.0082: when reusing a buffer listeners are not cleared Problem: When reusing a buffer listeners are not cleared. (Axel Forsman) Solution: Clear listeners when reusing a buffer. (closes https://github.com/vim/vim/issues/5431)
author Bram Moolenaar <Bram@vim.org>
date Fri, 03 Jan 2020 21:00:16 +0100
parents 5da355d15b88
children 36ec10251b2b
line wrap: on
line diff
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -295,3 +295,34 @@ func Test_listener_undo_line_number()
   delfunc EchoChanges
   call listener_remove(lid)
 endfunc
+
+func Test_listener_cleared_newbuf()
+  func Listener(bufnr, start, end, added, changes)
+    let g:gotCalled += 1
+  endfunc
+  new
+  " check that listening works
+  let g:gotCalled = 0
+  let lid = listener_add("Listener")
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(1, g:gotCalled)
+  %bwipe!
+  let bufnr = bufnr()
+  let b:testing = 123
+  let lid = listener_add("Listener")
+  enew!
+  " check buffer is reused
+  call assert_equal(bufnr, bufnr())
+  call assert_false(exists('b:testing'))
+
+  " check that listening stops when reusing the buffer
+  let g:gotCalled = 0
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(0, g:gotCalled)
+  unlet g:gotCalled
+
+  bwipe!
+  delfunc Listener
+endfunc