diff src/testdir/test_textprop.vim @ 16772:18093a6accb5 v8.1.1388

patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer commit https://github.com/vim/vim/commit/f0884c5f3f5a25481d1e16f0979aa978a6690bb1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 24 21:22:29 2019 +0200 patch 8.1.1388: errors when calling prop_remove() for an unloaded buffer Problem: Errors when calling prop_remove() for an unloaded buffer. Solution: Bail out when the buffer is not loaded. Add a few more tests for failing when the buffer number is invalid.
author Bram Moolenaar <Bram@vim.org>
date Fri, 24 May 2019 21:30:05 +0200
parents 09c81f17f83c
children 98ca522e6453
line wrap: on
line diff
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -69,6 +69,8 @@ func Test_proptype_buf()
   call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
   call prop_type_delete('two', {'bufnr': bufnr})
   call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
+
+  call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
 endfunc
 
 func AddPropTypes()
@@ -124,6 +126,8 @@ func Test_prop_add()
   let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}]
   call assert_equal(expected, prop_list(1))
 
+  call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
+
   call DeletePropTypes()
   bwipe!
 endfunc
@@ -136,15 +140,18 @@ func Test_prop_remove()
   call assert_equal(props, prop_list(1))
 
   " remove by id
-  call prop_remove({'id': 12}, 1)
+  call assert_equal(1, prop_remove({'id': 12}, 1))
   unlet props[2]
   call assert_equal(props, prop_list(1))
 
   " remove by type
-  call prop_remove({'type': 'one'}, 1)
+  call assert_equal(1, prop_remove({'type': 'one'}, 1))
   unlet props[1]
   call assert_equal(props, prop_list(1))
 
+  " remove from unknown buffer
+  call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
+
   call DeletePropTypes()
   bwipe!
 endfunc
@@ -760,3 +767,16 @@ func Test_textprop_empty_buffer()
   call prop_add(1, 1, {'type': 'comment'})
   close
 endfunc
+
+func Test_textprop_remove_from_buf()
+  new
+  let buf = bufnr('')
+  call prop_type_add('one', {'bufnr': buf})
+  call prop_add(1, 1, {'type': 'one', 'id': 234})
+  file x
+  edit y
+  call prop_remove({'id': 234, 'bufnr': buf}, 1)
+  call prop_type_delete('one', {'bufnr': buf})
+  bwipe! x
+  close
+endfunc