comparison 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
comparison
equal deleted inserted replaced
16771:1490c5a1fccc 16772:18093a6accb5
67 call assert_equal(2, len(prop_type_list({'bufnr': bufnr}))) 67 call assert_equal(2, len(prop_type_list({'bufnr': bufnr})))
68 call prop_type_delete('one', {'bufnr': bufnr}) 68 call prop_type_delete('one', {'bufnr': bufnr})
69 call assert_equal(1, len(prop_type_list({'bufnr': bufnr}))) 69 call assert_equal(1, len(prop_type_list({'bufnr': bufnr})))
70 call prop_type_delete('two', {'bufnr': bufnr}) 70 call prop_type_delete('two', {'bufnr': bufnr})
71 call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) 71 call assert_equal(0, len(prop_type_list({'bufnr': bufnr})))
72
73 call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
72 endfunc 74 endfunc
73 75
74 func AddPropTypes() 76 func AddPropTypes()
75 call prop_type_add('one', {}) 77 call prop_type_add('one', {})
76 call prop_type_add('two', {}) 78 call prop_type_add('two', {})
122 call prop_clear(1) 124 call prop_clear(1)
123 call prop_add(1, 5, {'type': 'two'}) 125 call prop_add(1, 5, {'type': 'two'})
124 let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] 126 let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}]
125 call assert_equal(expected, prop_list(1)) 127 call assert_equal(expected, prop_list(1))
126 128
129 call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
130
127 call DeletePropTypes() 131 call DeletePropTypes()
128 bwipe! 132 bwipe!
129 endfunc 133 endfunc
130 134
131 func Test_prop_remove() 135 func Test_prop_remove()
134 call SetupPropsInFirstLine() 138 call SetupPropsInFirstLine()
135 let props = Get_expected_props() 139 let props = Get_expected_props()
136 call assert_equal(props, prop_list(1)) 140 call assert_equal(props, prop_list(1))
137 141
138 " remove by id 142 " remove by id
139 call prop_remove({'id': 12}, 1) 143 call assert_equal(1, prop_remove({'id': 12}, 1))
140 unlet props[2] 144 unlet props[2]
141 call assert_equal(props, prop_list(1)) 145 call assert_equal(props, prop_list(1))
142 146
143 " remove by type 147 " remove by type
144 call prop_remove({'type': 'one'}, 1) 148 call assert_equal(1, prop_remove({'type': 'one'}, 1))
145 unlet props[1] 149 unlet props[1]
146 call assert_equal(props, prop_list(1)) 150 call assert_equal(props, prop_list(1))
151
152 " remove from unknown buffer
153 call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:')
147 154
148 call DeletePropTypes() 155 call DeletePropTypes()
149 bwipe! 156 bwipe!
150 endfunc 157 endfunc
151 158
758 call prop_type_add('comment', {'highlight': 'Search'}) 765 call prop_type_add('comment', {'highlight': 'Search'})
759 new 766 new
760 call prop_add(1, 1, {'type': 'comment'}) 767 call prop_add(1, 1, {'type': 'comment'})
761 close 768 close
762 endfunc 769 endfunc
770
771 func Test_textprop_remove_from_buf()
772 new
773 let buf = bufnr('')
774 call prop_type_add('one', {'bufnr': buf})
775 call prop_add(1, 1, {'type': 'one', 'id': 234})
776 file x
777 edit y
778 call prop_remove({'id': 234, 'bufnr': buf}, 1)
779 call prop_type_delete('one', {'bufnr': buf})
780 bwipe! x
781 close
782 endfunc