Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 1 | " Tests for defining text property types and adding text properties to the |
| 2 | " buffer. |
| 3 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 4 | source check.vim |
| 5 | CheckFeature textprop |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 7 | source screendump.vim |
| 8 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 9 | func Test_proptype_global() |
| 10 | call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) |
| 11 | let proptypes = prop_type_list() |
| 12 | call assert_equal(1, len(proptypes)) |
| 13 | call assert_equal('comment', proptypes[0]) |
| 14 | |
| 15 | let proptype = prop_type_get('comment') |
| 16 | call assert_equal('Directory', proptype['highlight']) |
| 17 | call assert_equal(123, proptype['priority']) |
| 18 | call assert_equal(1, proptype['start_incl']) |
| 19 | call assert_equal(1, proptype['end_incl']) |
| 20 | |
| 21 | call prop_type_delete('comment') |
| 22 | call assert_equal(0, len(prop_type_list())) |
| 23 | |
| 24 | call prop_type_add('one', {}) |
| 25 | call assert_equal(1, len(prop_type_list())) |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 26 | let proptype = 'one'->prop_type_get() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 27 | call assert_false(has_key(proptype, 'highlight')) |
| 28 | call assert_equal(0, proptype['priority']) |
| 29 | call assert_equal(0, proptype['start_incl']) |
| 30 | call assert_equal(0, proptype['end_incl']) |
| 31 | |
| 32 | call prop_type_add('two', {}) |
| 33 | call assert_equal(2, len(prop_type_list())) |
| 34 | call prop_type_delete('one') |
| 35 | call assert_equal(1, len(prop_type_list())) |
| 36 | call prop_type_delete('two') |
| 37 | call assert_equal(0, len(prop_type_list())) |
| 38 | endfunc |
| 39 | |
| 40 | func Test_proptype_buf() |
| 41 | let bufnr = bufnr('') |
| 42 | call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) |
| 43 | let proptypes = prop_type_list({'bufnr': bufnr}) |
| 44 | call assert_equal(1, len(proptypes)) |
| 45 | call assert_equal('comment', proptypes[0]) |
| 46 | |
| 47 | let proptype = prop_type_get('comment', {'bufnr': bufnr}) |
| 48 | call assert_equal('Directory', proptype['highlight']) |
| 49 | call assert_equal(123, proptype['priority']) |
| 50 | call assert_equal(1, proptype['start_incl']) |
| 51 | call assert_equal(1, proptype['end_incl']) |
| 52 | |
| 53 | call prop_type_delete('comment', {'bufnr': bufnr}) |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 54 | call assert_equal(0, len({'bufnr': bufnr}->prop_type_list())) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 55 | |
| 56 | call prop_type_add('one', {'bufnr': bufnr}) |
| 57 | let proptype = prop_type_get('one', {'bufnr': bufnr}) |
| 58 | call assert_false(has_key(proptype, 'highlight')) |
| 59 | call assert_equal(0, proptype['priority']) |
| 60 | call assert_equal(0, proptype['start_incl']) |
| 61 | call assert_equal(0, proptype['end_incl']) |
| 62 | |
| 63 | call prop_type_add('two', {'bufnr': bufnr}) |
| 64 | call assert_equal(2, len(prop_type_list({'bufnr': bufnr}))) |
| 65 | call prop_type_delete('one', {'bufnr': bufnr}) |
| 66 | call assert_equal(1, len(prop_type_list({'bufnr': bufnr}))) |
| 67 | call prop_type_delete('two', {'bufnr': bufnr}) |
| 68 | call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 69 | |
| 70 | call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:") |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 71 | endfunc |
| 72 | |
| 73 | func AddPropTypes() |
| 74 | call prop_type_add('one', {}) |
| 75 | call prop_type_add('two', {}) |
| 76 | call prop_type_add('three', {}) |
| 77 | call prop_type_add('whole', {}) |
| 78 | endfunc |
| 79 | |
| 80 | func DeletePropTypes() |
| 81 | call prop_type_delete('one') |
| 82 | call prop_type_delete('two') |
| 83 | call prop_type_delete('three') |
| 84 | call prop_type_delete('whole') |
| 85 | endfunc |
| 86 | |
| 87 | func SetupPropsInFirstLine() |
| 88 | call setline(1, 'one two three') |
| 89 | call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 90 | eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'}) |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 91 | call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 92 | call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) |
| 93 | endfunc |
| 94 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 95 | func Get_expected_props() |
| 96 | return [ |
| 97 | \ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 98 | \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 99 | \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 100 | \ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 101 | \ ] |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 102 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 103 | |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 104 | func Test_prop_find() |
| 105 | new |
| 106 | call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) |
| 107 | |
| 108 | " Add two text props on lines 1 and 5, and one spanning lines 2 to 4. |
| 109 | call prop_type_add('prop_name', {'highlight': 'Directory'}) |
| 110 | call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) |
| 111 | call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) |
| 112 | call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) |
| 113 | |
| 114 | let expected = [ |
| 115 | \ {'lnum': 1, 'col': 5, 'length': 3, 'id': 10, 'type': 'prop_name', 'start': 1, 'end': 1}, |
| 116 | \ {'lnum': 2, 'col': 4, 'id': 11, 'type': 'prop_name', 'start': 1, 'end': 0}, |
| 117 | \ {'lnum': 5, 'col': 4, 'length': 1, 'id': 12, 'type': 'prop_name', 'start': 1, 'end': 1} |
| 118 | \ ] |
| 119 | |
| 120 | " Starting at line 5 col 1 this should find the prop at line 5 col 4. |
| 121 | call cursor(5,1) |
| 122 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 123 | call assert_equal(expected[2], result) |
| 124 | |
| 125 | " With skipstart left at false (default), this should find the prop at line |
| 126 | " 5 col 4. |
| 127 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b') |
| 128 | call assert_equal(expected[2], result) |
| 129 | |
| 130 | " With skipstart set to true, this should skip the prop at line 5 col 4. |
| 131 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b') |
| 132 | unlet result.length |
| 133 | call assert_equal(expected[1], result) |
| 134 | |
| 135 | " Search backwards from line 1 col 10 to find the prop on the same line. |
| 136 | let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b') |
| 137 | call assert_equal(expected[0], result) |
| 138 | |
| 139 | " with skipstart set to false, if the start position is anywhere between the |
| 140 | " start and end lines of a text prop (searching forward or backward), the |
| 141 | " result should be the prop on the first line (the line with 'start' set to 1). |
| 142 | call cursor(3,1) |
| 143 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 144 | unlet result.length |
| 145 | call assert_equal(expected[1], result) |
| 146 | let result = prop_find({'type': 'prop_name'}, 'b') |
| 147 | unlet result.length |
| 148 | call assert_equal(expected[1], result) |
| 149 | |
| 150 | " with skipstart set to true, if the start position is anywhere between the |
| 151 | " start and end lines of a text prop (searching forward or backward), all lines |
| 152 | " of the prop will be skipped. |
| 153 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b') |
| 154 | call assert_equal(expected[0], result) |
| 155 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f') |
| 156 | call assert_equal(expected[2], result) |
| 157 | |
| 158 | " Use skipstart to search through all props with type name 'prop_name'. |
| 159 | " First forward... |
| 160 | let lnum = 1 |
| 161 | let col = 1 |
| 162 | let i = 0 |
| 163 | for exp in expected |
| 164 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f') |
| 165 | if !has_key(exp, "length") |
| 166 | unlet result.length |
| 167 | endif |
| 168 | call assert_equal(exp, result) |
| 169 | let lnum = result.lnum |
| 170 | let col = result.col |
| 171 | let i = i + 1 |
| 172 | endfor |
| 173 | |
| 174 | " ...then backwards. |
| 175 | let lnum = 6 |
| 176 | let col = 4 |
| 177 | let i = 2 |
| 178 | while i >= 0 |
| 179 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b') |
| 180 | if !has_key(expected[i], "length") |
| 181 | unlet result.length |
| 182 | endif |
| 183 | call assert_equal(expected[i], result) |
| 184 | let lnum = result.lnum |
| 185 | let col = result.col |
| 186 | let i = i - 1 |
| 187 | endwhile |
| 188 | |
| 189 | " Starting from line 6 col 1 search backwards for prop with id 10. |
| 190 | call cursor(6,1) |
| 191 | let result = prop_find({'id': 10, 'skipstart': 1}, 'b') |
| 192 | call assert_equal(expected[0], result) |
| 193 | |
| 194 | " Starting from line 1 col 1 search forwards for prop with id 12. |
| 195 | call cursor(1,1) |
| 196 | let result = prop_find({'id': 12}, 'f') |
| 197 | call assert_equal(expected[2], result) |
| 198 | |
| 199 | " Search for a prop with an unknown id. |
| 200 | let result = prop_find({'id': 999}, 'f') |
| 201 | call assert_equal({}, result) |
| 202 | |
| 203 | " Search backwards from the proceeding position of the prop with id 11 |
| 204 | " (at line num 2 col 4). This should return an empty dict. |
| 205 | let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b') |
| 206 | call assert_equal({}, result) |
| 207 | |
| 208 | " When lnum is given and col is omitted, use column 1. |
| 209 | let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f') |
| 210 | call assert_equal(expected[0], result) |
| 211 | |
| 212 | call prop_clear(1,6) |
| 213 | call prop_type_delete('prop_name') |
| 214 | endfunc |
| 215 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 216 | func Test_prop_add() |
| 217 | new |
| 218 | call AddPropTypes() |
| 219 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 220 | let expected_props = Get_expected_props() |
| 221 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 222 | call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') |
| 223 | call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') |
| 224 | |
| 225 | " Insert a line above, text props must still be there. |
| 226 | call append(0, 'empty') |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 227 | call assert_equal(expected_props, prop_list(2)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 228 | " Delete a line above, text props must still be there. |
| 229 | 1del |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 230 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 231 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 232 | " Prop without length or end column is zero length |
| 233 | call prop_clear(1) |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 234 | call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) |
| 235 | call prop_add(1, 5, #{type: 'included'}) |
| 236 | let expected = [#{col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}] |
| 237 | call assert_equal(expected, prop_list(1)) |
| 238 | |
| 239 | " Inserting text makes the prop bigger. |
| 240 | exe "normal 5|ixx\<Esc>" |
| 241 | let expected = [#{col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}] |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 242 | call assert_equal(expected, prop_list(1)) |
| 243 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 244 | call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') |
| 245 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 246 | call DeletePropTypes() |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 247 | call prop_type_delete('included') |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 248 | bwipe! |
| 249 | endfunc |
| 250 | |
| 251 | func Test_prop_remove() |
| 252 | new |
| 253 | call AddPropTypes() |
| 254 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 255 | let props = Get_expected_props() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 256 | call assert_equal(props, prop_list(1)) |
| 257 | |
| 258 | " remove by id |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 259 | call assert_equal(1, {'id': 12}->prop_remove(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 260 | unlet props[2] |
| 261 | call assert_equal(props, prop_list(1)) |
| 262 | |
| 263 | " remove by type |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 264 | call assert_equal(1, prop_remove({'type': 'one'}, 1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 265 | unlet props[1] |
| 266 | call assert_equal(props, prop_list(1)) |
| 267 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 268 | " remove from unknown buffer |
| 269 | call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:') |
| 270 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 271 | call DeletePropTypes() |
| 272 | bwipe! |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 273 | |
| 274 | new |
| 275 | call AddPropTypes() |
| 276 | call SetupPropsInFirstLine() |
| 277 | call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) |
| 278 | let props = Get_expected_props() |
| 279 | call insert(props, {'col': 6, 'length': 2, 'id': 11, 'type': 'three', 'start': 1, 'end': 1}, 3) |
| 280 | call assert_equal(props, prop_list(1)) |
| 281 | call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) |
| 282 | unlet props[3] |
| 283 | call assert_equal(props, prop_list(1)) |
| 284 | |
| 285 | call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860') |
| 286 | call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860') |
| 287 | |
| 288 | call DeletePropTypes() |
| 289 | bwipe! |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 290 | endfunc |
| 291 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 292 | func SetupOneLine() |
| 293 | call setline(1, 'xonex xtwoxx') |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 294 | normal gg0 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 295 | call AddPropTypes() |
| 296 | call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) |
| 297 | call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) |
| 298 | let expected = [ |
| 299 | \ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 300 | \ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
| 301 | \] |
| 302 | call assert_equal(expected, prop_list(1)) |
| 303 | return expected |
| 304 | endfunc |
| 305 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 306 | func Test_prop_add_remove_buf() |
| 307 | new |
| 308 | let bufnr = bufnr('') |
| 309 | call AddPropTypes() |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 310 | for lnum in range(1, 4) |
| 311 | call setline(lnum, 'one two three') |
| 312 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 313 | wincmd w |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 314 | for lnum in range(1, 4) |
| 315 | call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) |
| 316 | call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) |
| 317 | call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) |
| 318 | endfor |
| 319 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 320 | let props = [ |
| 321 | \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 322 | \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
| 323 | \ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, |
| 324 | \] |
| 325 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 326 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 327 | " remove by id |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 328 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 329 | unlet props[1] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 330 | |
| 331 | call prop_remove({'id': 12, 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 332 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 333 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 334 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 335 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 336 | |
| 337 | call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4) |
| 338 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 339 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 340 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 341 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 342 | |
| 343 | call prop_remove({'id': 12, 'bufnr': bufnr}) |
| 344 | for lnum in range(1, 4) |
| 345 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 346 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 347 | |
| 348 | " remove by type |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 349 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 350 | unlet props[0] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 351 | |
| 352 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 353 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 354 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 355 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 356 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 357 | |
| 358 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4) |
| 359 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 360 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 361 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 362 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 363 | |
| 364 | call prop_remove({'type': 'one', 'bufnr': bufnr}) |
| 365 | for lnum in range(1, 4) |
| 366 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 367 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 368 | |
| 369 | call DeletePropTypes() |
| 370 | wincmd w |
| 371 | bwipe! |
| 372 | endfunc |
| 373 | |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 374 | func Test_prop_backspace() |
| 375 | new |
| 376 | set bs=2 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 377 | let expected = SetupOneLine() " 'xonex xtwoxx' |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 378 | |
| 379 | exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" |
| 380 | call assert_equal('one xtwoxx', getline(1)) |
| 381 | let expected[0].col = 1 |
| 382 | let expected[1].col = 6 |
| 383 | call assert_equal(expected, prop_list(1)) |
| 384 | |
| 385 | call DeletePropTypes() |
| 386 | bwipe! |
| 387 | set bs& |
| 388 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 389 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 390 | func Test_prop_replace() |
| 391 | new |
| 392 | set bs=2 |
| 393 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 394 | |
| 395 | exe "normal 0Ryyy\<Esc>" |
| 396 | call assert_equal('yyyex xtwoxx', getline(1)) |
| 397 | call assert_equal(expected, prop_list(1)) |
| 398 | |
| 399 | exe "normal ftRyy\<BS>" |
| 400 | call assert_equal('yyyex xywoxx', getline(1)) |
| 401 | call assert_equal(expected, prop_list(1)) |
| 402 | |
| 403 | exe "normal 0fwRyy\<BS>" |
| 404 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 405 | call assert_equal(expected, prop_list(1)) |
| 406 | |
| 407 | exe "normal 0foRyy\<BS>\<BS>" |
| 408 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 409 | call assert_equal(expected, prop_list(1)) |
| 410 | |
| 411 | call DeletePropTypes() |
| 412 | bwipe! |
| 413 | set bs& |
| 414 | endfunc |
| 415 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 416 | func Test_prop_open_line() |
| 417 | new |
| 418 | |
| 419 | " open new line, props stay in top line |
| 420 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 421 | exe "normal o\<Esc>" |
| 422 | call assert_equal('xonex xtwoxx', getline(1)) |
| 423 | call assert_equal('', getline(2)) |
| 424 | call assert_equal(expected, prop_list(1)) |
| 425 | call DeletePropTypes() |
| 426 | |
| 427 | " move all props to next line |
| 428 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 429 | exe "normal 0i\<CR>\<Esc>" |
| 430 | call assert_equal('', getline(1)) |
| 431 | call assert_equal('xonex xtwoxx', getline(2)) |
| 432 | call assert_equal(expected, prop_list(2)) |
| 433 | call DeletePropTypes() |
| 434 | |
| 435 | " split just before prop, move all props to next line |
| 436 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 437 | exe "normal 0li\<CR>\<Esc>" |
| 438 | call assert_equal('x', getline(1)) |
| 439 | call assert_equal('onex xtwoxx', getline(2)) |
| 440 | let expected[0].col -= 1 |
| 441 | let expected[1].col -= 1 |
| 442 | call assert_equal(expected, prop_list(2)) |
| 443 | call DeletePropTypes() |
| 444 | |
| 445 | " split inside prop, split first prop |
| 446 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 447 | exe "normal 0lli\<CR>\<Esc>" |
| 448 | call assert_equal('xo', getline(1)) |
| 449 | call assert_equal('nex xtwoxx', getline(2)) |
| 450 | let exp_first = [deepcopy(expected[0])] |
| 451 | let exp_first[0].length = 1 |
| 452 | call assert_equal(exp_first, prop_list(1)) |
| 453 | let expected[0].col = 1 |
| 454 | let expected[0].length = 2 |
| 455 | let expected[1].col -= 2 |
| 456 | call assert_equal(expected, prop_list(2)) |
| 457 | call DeletePropTypes() |
| 458 | |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 459 | " split just after first prop, second prop move to next line |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 460 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 461 | exe "normal 0fea\<CR>\<Esc>" |
| 462 | call assert_equal('xone', getline(1)) |
| 463 | call assert_equal('x xtwoxx', getline(2)) |
| 464 | let exp_first = expected[0:0] |
| 465 | call assert_equal(exp_first, prop_list(1)) |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 466 | let expected = expected[1:1] |
| 467 | let expected[0].col -= 4 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 468 | call assert_equal(expected, prop_list(2)) |
| 469 | call DeletePropTypes() |
| 470 | |
| 471 | bwipe! |
| 472 | set bs& |
| 473 | endfunc |
| 474 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 475 | func Test_prop_clear() |
| 476 | new |
| 477 | call AddPropTypes() |
| 478 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 479 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 480 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 481 | eval 1->prop_clear() |
| 482 | call assert_equal([], 1->prop_list()) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 483 | |
| 484 | call DeletePropTypes() |
| 485 | bwipe! |
| 486 | endfunc |
| 487 | |
| 488 | func Test_prop_clear_buf() |
| 489 | new |
| 490 | call AddPropTypes() |
| 491 | call SetupPropsInFirstLine() |
| 492 | let bufnr = bufnr('') |
| 493 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 494 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 495 | |
| 496 | call prop_clear(1, 1, {'bufnr': bufnr}) |
| 497 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 498 | |
| 499 | wincmd w |
| 500 | call DeletePropTypes() |
| 501 | bwipe! |
| 502 | endfunc |
| 503 | |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 504 | func Test_prop_setline() |
| 505 | new |
| 506 | call AddPropTypes() |
| 507 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 508 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 509 | |
| 510 | call setline(1, 'foobar') |
| 511 | call assert_equal([], prop_list(1)) |
| 512 | |
| 513 | call DeletePropTypes() |
| 514 | bwipe! |
| 515 | endfunc |
| 516 | |
| 517 | func Test_prop_setbufline() |
| 518 | new |
| 519 | call AddPropTypes() |
| 520 | call SetupPropsInFirstLine() |
| 521 | let bufnr = bufnr('') |
| 522 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 523 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 524 | |
| 525 | call setbufline(bufnr, 1, 'foobar') |
| 526 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 527 | |
| 528 | wincmd w |
| 529 | call DeletePropTypes() |
| 530 | bwipe! |
| 531 | endfunc |
| 532 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 533 | func Test_prop_substitute() |
| 534 | new |
| 535 | " Set first line to 'one two three' |
| 536 | call AddPropTypes() |
| 537 | call SetupPropsInFirstLine() |
| 538 | let expected_props = Get_expected_props() |
| 539 | call assert_equal(expected_props, prop_list(1)) |
| 540 | |
| 541 | " Change "n" in "one" to XX: 'oXXe two three' |
| 542 | s/n/XX/ |
| 543 | let expected_props[0].length += 1 |
| 544 | let expected_props[1].length += 1 |
| 545 | let expected_props[2].col += 1 |
| 546 | let expected_props[3].col += 1 |
| 547 | call assert_equal(expected_props, prop_list(1)) |
| 548 | |
| 549 | " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' |
| 550 | s/t//g |
| 551 | let expected_props[0].length -= 2 |
| 552 | let expected_props[2].length -= 1 |
| 553 | let expected_props[3].length -= 1 |
| 554 | let expected_props[3].col -= 1 |
| 555 | call assert_equal(expected_props, prop_list(1)) |
| 556 | |
| 557 | " Split the line by changing w to line break: 'oXXe ', 'o hree' |
| 558 | " The long prop is split and spans both lines. |
| 559 | " The props on "two" and "three" move to the next line. |
| 560 | s/w/\r/ |
| 561 | let new_props = [ |
| 562 | \ copy(expected_props[0]), |
| 563 | \ copy(expected_props[2]), |
| 564 | \ copy(expected_props[3]), |
| 565 | \ ] |
| 566 | let expected_props[0].length = 5 |
| 567 | unlet expected_props[3] |
| 568 | unlet expected_props[2] |
| 569 | call assert_equal(expected_props, prop_list(1)) |
| 570 | |
| 571 | let new_props[0].length = 6 |
| 572 | let new_props[1].col = 1 |
| 573 | let new_props[1].length = 1 |
| 574 | let new_props[2].col = 3 |
| 575 | call assert_equal(new_props, prop_list(2)) |
| 576 | |
| 577 | call DeletePropTypes() |
| 578 | bwipe! |
| 579 | endfunc |
| 580 | |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 581 | func Test_prop_change_indent() |
| 582 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 583 | new |
| 584 | call setline(1, [' xxx', 'yyyyy']) |
| 585 | call prop_add(2, 2, {'length': 2, 'type': 'comment'}) |
| 586 | let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} |
| 587 | call assert_equal([expect], prop_list(2)) |
| 588 | |
| 589 | set shiftwidth=3 |
| 590 | normal 2G>> |
| 591 | call assert_equal(' yyyyy', getline(2)) |
| 592 | let expect.col += 3 |
| 593 | call assert_equal([expect], prop_list(2)) |
| 594 | |
| 595 | normal 2G== |
| 596 | call assert_equal(' yyyyy', getline(2)) |
| 597 | let expect.col = 6 |
| 598 | call assert_equal([expect], prop_list(2)) |
| 599 | |
| 600 | call prop_clear(2) |
| 601 | call prop_add(2, 2, {'length': 5, 'type': 'comment'}) |
| 602 | let expect.col = 2 |
| 603 | let expect.length = 5 |
| 604 | call assert_equal([expect], prop_list(2)) |
| 605 | |
| 606 | normal 2G<< |
| 607 | call assert_equal(' yyyyy', getline(2)) |
| 608 | let expect.length = 2 |
| 609 | call assert_equal([expect], prop_list(2)) |
| 610 | |
| 611 | set shiftwidth& |
| 612 | call prop_type_delete('comment') |
| 613 | endfunc |
| 614 | |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 615 | " Setup a three line prop in lines 2 - 4. |
| 616 | " Add short props in line 1 and 5. |
| 617 | func Setup_three_line_prop() |
| 618 | new |
| 619 | call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) |
| 620 | call prop_add(1, 2, {'length': 1, 'type': 'comment'}) |
| 621 | call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) |
| 622 | call prop_add(5, 2, {'length': 1, 'type': 'comment'}) |
| 623 | endfunc |
| 624 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 625 | func Test_prop_multiline() |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 626 | eval 'comment'->prop_type_add({'highlight': 'Directory'}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 627 | new |
| 628 | call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) |
| 629 | |
| 630 | " start halfway line 1, end halfway line 3 |
| 631 | call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) |
| 632 | let expect1 = {'col': 3, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 633 | call assert_equal([expect1], prop_list(1)) |
| 634 | let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 635 | call assert_equal([expect2], prop_list(2)) |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 636 | let expect3 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 637 | call assert_equal([expect3], prop_list(3)) |
| 638 | call prop_clear(1, 3) |
| 639 | |
| 640 | " include all three lines |
| 641 | call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) |
| 642 | let expect1.col = 1 |
| 643 | let expect1.length = 8 |
| 644 | call assert_equal([expect1], prop_list(1)) |
| 645 | call assert_equal([expect2], prop_list(2)) |
| 646 | let expect3.length = 9 |
| 647 | call assert_equal([expect3], prop_list(3)) |
| 648 | call prop_clear(1, 3) |
| 649 | |
| 650 | bwipe! |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 651 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 652 | " Test deleting the first line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 653 | call Setup_three_line_prop() |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 654 | let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} |
| 655 | call assert_equal([expect_short], prop_list(1)) |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 656 | let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 657 | call assert_equal([expect2], prop_list(2)) |
| 658 | 2del |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 659 | call assert_equal([expect_short], prop_list(1)) |
| 660 | let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 661 | call assert_equal([expect2], prop_list(2)) |
| 662 | bwipe! |
| 663 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 664 | " Test deleting the last line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 665 | call Setup_three_line_prop() |
| 666 | let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 667 | call assert_equal([expect3], prop_list(3)) |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 668 | let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 669 | call assert_equal([expect4], prop_list(4)) |
| 670 | 4del |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 671 | let expect3.end = 1 |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 672 | call assert_equal([expect3], prop_list(3)) |
| 673 | call assert_equal([expect_short], prop_list(4)) |
| 674 | bwipe! |
| 675 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 676 | " Test appending a line below the multi-line text prop start. |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 677 | call Setup_three_line_prop() |
| 678 | let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 679 | call assert_equal([expect2], prop_list(2)) |
| 680 | call append(2, "new line") |
| 681 | call assert_equal([expect2], prop_list(2)) |
| 682 | let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 683 | call assert_equal([expect3], prop_list(3)) |
| 684 | bwipe! |
| 685 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 686 | call prop_type_delete('comment') |
| 687 | endfunc |
| 688 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 689 | func Test_prop_line2byte() |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 690 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 691 | new |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 692 | call setline(1, ['line1', 'second line', '']) |
Bram Moolenaar | 8cf734e | 2018-12-26 01:09:00 +0100 | [diff] [blame] | 693 | set ff=unix |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 694 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 695 | call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 696 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 697 | |
| 698 | bwipe! |
| 699 | call prop_type_delete('comment') |
| 700 | endfunc |
| 701 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 702 | func Test_prop_byte2line() |
| 703 | new |
| 704 | set ff=unix |
| 705 | call setline(1, ['one one', 'two two', 'three three', 'four four', 'five']) |
| 706 | call assert_equal(4, byte2line(line2byte(4))) |
| 707 | call assert_equal(5, byte2line(line2byte(5))) |
| 708 | |
| 709 | call prop_type_add('prop', {'highlight': 'Directory'}) |
| 710 | call prop_add(3, 1, {'length': 5, 'type': 'prop'}) |
| 711 | call assert_equal(4, byte2line(line2byte(4))) |
| 712 | call assert_equal(5, byte2line(line2byte(5))) |
| 713 | |
| 714 | bwipe! |
| 715 | call prop_type_delete('prop') |
| 716 | endfunc |
| 717 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 718 | func Test_prop_undo() |
| 719 | new |
| 720 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 721 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 722 | " Set 'undolevels' to break changes into undo-able pieces. |
| 723 | set ul& |
| 724 | |
| 725 | call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) |
| 726 | let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 727 | call assert_equal(expected, prop_list(1)) |
| 728 | |
| 729 | " Insert a character, then undo. |
| 730 | exe "normal 0lllix\<Esc>" |
| 731 | set ul& |
| 732 | let expected[0].length = 3 |
| 733 | call assert_equal(expected, prop_list(1)) |
| 734 | undo |
| 735 | let expected[0].length = 2 |
| 736 | call assert_equal(expected, prop_list(1)) |
| 737 | |
| 738 | " Delete a character, then undo |
| 739 | exe "normal 0lllx" |
| 740 | set ul& |
| 741 | let expected[0].length = 1 |
| 742 | call assert_equal(expected, prop_list(1)) |
| 743 | undo |
| 744 | let expected[0].length = 2 |
| 745 | call assert_equal(expected, prop_list(1)) |
| 746 | |
| 747 | " Delete the line, then undo |
| 748 | 1d |
| 749 | set ul& |
| 750 | call assert_equal([], prop_list(1)) |
| 751 | undo |
| 752 | call assert_equal(expected, prop_list(1)) |
| 753 | |
| 754 | " Insert a character, delete two characters, then undo with "U" |
| 755 | exe "normal 0lllix\<Esc>" |
| 756 | set ul& |
| 757 | let expected[0].length = 3 |
| 758 | call assert_equal(expected, prop_list(1)) |
| 759 | exe "normal 0lllxx" |
| 760 | set ul& |
| 761 | let expected[0].length = 1 |
| 762 | call assert_equal(expected, prop_list(1)) |
| 763 | normal U |
| 764 | let expected[0].length = 2 |
| 765 | call assert_equal(expected, prop_list(1)) |
| 766 | |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 767 | " substitute a word, then undo |
| 768 | call setline(1, 'the number 123 is highlighted.') |
| 769 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
| 770 | let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 771 | call assert_equal(expected, prop_list(1)) |
| 772 | set ul& |
| 773 | 1s/number/foo |
| 774 | let expected[0].col = 9 |
| 775 | call assert_equal(expected, prop_list(1)) |
| 776 | undo |
| 777 | let expected[0].col = 12 |
| 778 | call assert_equal(expected, prop_list(1)) |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 779 | call prop_clear(1) |
| 780 | |
| 781 | " substitute with backslash |
| 782 | call setline(1, 'the number 123 is highlighted.') |
| 783 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
| 784 | let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 785 | call assert_equal(expected, prop_list(1)) |
| 786 | 1s/the/\The |
| 787 | call assert_equal(expected, prop_list(1)) |
| 788 | 1s/^/\\ |
| 789 | let expected[0].col += 1 |
| 790 | call assert_equal(expected, prop_list(1)) |
| 791 | 1s/^/\~ |
| 792 | let expected[0].col += 1 |
| 793 | call assert_equal(expected, prop_list(1)) |
| 794 | 1s/123/12\\3 |
| 795 | let expected[0].length += 1 |
| 796 | call assert_equal(expected, prop_list(1)) |
| 797 | call prop_clear(1) |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 798 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 799 | bwipe! |
| 800 | call prop_type_delete('comment') |
| 801 | endfunc |
| 802 | |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 803 | func Test_prop_delete_text() |
| 804 | new |
| 805 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 806 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 807 | |
| 808 | " zero length property |
| 809 | call prop_add(1, 3, {'type': 'comment'}) |
| 810 | let expected = [{'col': 3, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 811 | call assert_equal(expected, prop_list(1)) |
| 812 | |
| 813 | " delete one char moves the property |
| 814 | normal! x |
| 815 | let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 816 | call assert_equal(expected, prop_list(1)) |
| 817 | |
| 818 | " delete char of the property has no effect |
| 819 | normal! lx |
| 820 | let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 821 | call assert_equal(expected, prop_list(1)) |
| 822 | |
| 823 | " delete more chars moves property to first column, is not deleted |
| 824 | normal! 0xxxx |
| 825 | let expected = [{'col': 1, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 826 | call assert_equal(expected, prop_list(1)) |
| 827 | |
| 828 | bwipe! |
| 829 | call prop_type_delete('comment') |
| 830 | endfunc |
| 831 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 832 | " screenshot test with textprop highlighting |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 833 | func Test_textprop_screenshot_various() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 834 | CheckScreendump |
Bram Moolenaar | ed79d1e | 2019-02-22 14:38:58 +0100 | [diff] [blame] | 835 | " The Vim running in the terminal needs to use utf-8. |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 836 | if g:orig_encoding != 'utf-8' |
| 837 | throw 'Skipped: not using utf-8' |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 838 | endif |
| 839 | call writefile([ |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 840 | \ "call setline(1, [" |
| 841 | \ .. "'One two'," |
| 842 | \ .. "'Numbér 123 änd thœn 4¾7.'," |
| 843 | \ .. "'--aa--bb--cc--dd--'," |
| 844 | \ .. "'// comment with error in it'," |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 845 | \ .. "'first line'," |
| 846 | \ .. "' second line '," |
| 847 | \ .. "'third line'," |
| 848 | \ .. "' fourth line'," |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 849 | \ .. "])", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 850 | \ "hi NumberProp ctermfg=blue", |
| 851 | \ "hi LongProp ctermbg=yellow", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 852 | \ "hi BackgroundProp ctermbg=lightgrey", |
| 853 | \ "hi UnderlineProp cterm=underline", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 854 | \ "call prop_type_add('number', {'highlight': 'NumberProp'})", |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 855 | \ "call prop_type_add('long', {'highlight': 'NumberProp'})", |
| 856 | \ "call prop_type_change('long', {'highlight': 'LongProp'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 857 | \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", |
| 858 | \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", |
| 859 | \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 860 | \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})", |
| 861 | \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})", |
| 862 | \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})", |
Bram Moolenaar | 58e32ab | 2019-11-12 22:44:22 +0100 | [diff] [blame] | 863 | \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 864 | \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 865 | \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", |
| 866 | \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 867 | \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", |
| 868 | \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", |
| 869 | \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", |
| 870 | \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 871 | \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})", |
| 872 | \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 873 | \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 874 | \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})", |
| 875 | \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})", |
| 876 | \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})", |
| 877 | \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})", |
Bram Moolenaar | bfd4512 | 2019-05-17 13:05:07 +0200 | [diff] [blame] | 878 | \ "set number cursorline", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 879 | \ "hi clear SpellBad", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 880 | \ "set spell", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 881 | \ "syn match Comment '//.*'", |
| 882 | \ "hi Comment ctermfg=green", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 883 | \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>", |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 884 | \ "normal 3G0lli\<BS>\<Esc>", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 885 | \ "normal 6G0i\<BS>\<Esc>", |
| 886 | \ "normal 3J", |
| 887 | \ "normal 3G", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 888 | \], 'XtestProp') |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 889 | let buf = RunVimInTerminal('-S XtestProp', {'rows': 8}) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 890 | call VerifyScreenDump(buf, 'Test_textprop_01', {}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 891 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 892 | " clean up |
| 893 | call StopVimInTerminal(buf) |
Bram Moolenaar | 2f21fa8 | 2018-12-31 20:05:56 +0100 | [diff] [blame] | 894 | call delete('XtestProp') |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 895 | endfunc |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 896 | |
| 897 | func RunTestVisualBlock(width, dump) |
| 898 | call writefile([ |
| 899 | \ "call setline(1, [" |
| 900 | \ .. "'xxxxxxxxx 123 x'," |
| 901 | \ .. "'xxxxxxxx 123 x'," |
| 902 | \ .. "'xxxxxxx 123 x'," |
| 903 | \ .. "'xxxxxx 123 x'," |
| 904 | \ .. "'xxxxx 123 x'," |
| 905 | \ .. "'xxxx 123 xx'," |
| 906 | \ .. "'xxx 123 xxx'," |
| 907 | \ .. "'xx 123 xxxx'," |
| 908 | \ .. "'x 123 xxxxx'," |
| 909 | \ .. "' 123 xxxxxx'," |
| 910 | \ .. "])", |
| 911 | \ "hi SearchProp ctermbg=yellow", |
| 912 | \ "call prop_type_add('search', {'highlight': 'SearchProp'})", |
| 913 | \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", |
| 914 | \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", |
| 915 | \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", |
| 916 | \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", |
| 917 | \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", |
| 918 | \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", |
| 919 | \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", |
| 920 | \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", |
| 921 | \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", |
| 922 | \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", |
| 923 | \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", |
| 924 | \], 'XtestPropVis') |
| 925 | let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) |
| 926 | call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) |
| 927 | |
| 928 | " clean up |
| 929 | call StopVimInTerminal(buf) |
| 930 | call delete('XtestPropVis') |
| 931 | endfunc |
| 932 | |
| 933 | " screenshot test with Visual block mode operations |
| 934 | func Test_textprop_screenshot_visual() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 935 | CheckScreendump |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 936 | |
| 937 | " Delete two columns while text props are three chars wide. |
| 938 | call RunTestVisualBlock(2, '01') |
| 939 | |
| 940 | " Same, but delete four columns |
| 941 | call RunTestVisualBlock(4, '02') |
| 942 | endfunc |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 943 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 944 | func Test_textprop_after_tab() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 945 | CheckScreendump |
Bram Moolenaar | 37e66cf | 2019-06-19 18:16:10 +0200 | [diff] [blame] | 946 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 947 | let lines =<< trim END |
| 948 | call setline(1, [ |
| 949 | \ "\txxx", |
| 950 | \ "x\txxx", |
| 951 | \ ]) |
| 952 | hi SearchProp ctermbg=yellow |
| 953 | call prop_type_add('search', {'highlight': 'SearchProp'}) |
| 954 | call prop_add(1, 2, {'length': 3, 'type': 'search'}) |
| 955 | call prop_add(2, 3, {'length': 3, 'type': 'search'}) |
| 956 | END |
| 957 | call writefile(lines, 'XtestPropTab') |
| 958 | let buf = RunVimInTerminal('-S XtestPropTab', {'rows': 6}) |
| 959 | call VerifyScreenDump(buf, 'Test_textprop_tab', {}) |
| 960 | |
| 961 | " clean up |
| 962 | call StopVimInTerminal(buf) |
| 963 | call delete('XtestPropTab') |
| 964 | endfunc |
| 965 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 966 | func Test_textprop_with_syntax() |
| 967 | CheckScreendump |
| 968 | |
| 969 | let lines =<< trim END |
| 970 | call setline(1, [ |
| 971 | \ "(abc)", |
| 972 | \ ]) |
| 973 | syn match csParens "[()]" display |
| 974 | hi! link csParens MatchParen |
| 975 | |
| 976 | call prop_type_add('TPTitle', #{ highlight: 'Title' }) |
| 977 | call prop_add(1, 2, #{type: 'TPTitle', end_col: 5}) |
| 978 | END |
| 979 | call writefile(lines, 'XtestPropSyn') |
| 980 | let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6}) |
| 981 | call VerifyScreenDump(buf, 'Test_textprop_syn_1', {}) |
| 982 | |
| 983 | " clean up |
| 984 | call StopVimInTerminal(buf) |
| 985 | call delete('XtestPropSyn') |
| 986 | endfunc |
| 987 | |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 988 | " Adding a text property to a new buffer should not fail |
| 989 | func Test_textprop_empty_buffer() |
| 990 | call prop_type_add('comment', {'highlight': 'Search'}) |
| 991 | new |
| 992 | call prop_add(1, 1, {'type': 'comment'}) |
| 993 | close |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 994 | call prop_type_delete('comment') |
| 995 | endfunc |
| 996 | |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 997 | " Adding a text property with invalid highlight should be ignored. |
| 998 | func Test_textprop_invalid_highlight() |
| 999 | call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:') |
| 1000 | new |
| 1001 | call setline(1, ['asdf','asdf']) |
| 1002 | call prop_add(1, 1, {'length': 4, 'type': 'dni'}) |
| 1003 | redraw |
| 1004 | bwipe! |
| 1005 | call prop_type_delete('dni') |
| 1006 | endfunc |
| 1007 | |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1008 | " Adding a text property to an empty buffer and then editing another |
| 1009 | func Test_textprop_empty_buffer_next() |
| 1010 | call prop_type_add("xxx", {}) |
| 1011 | call prop_add(1, 1, {"type": "xxx"}) |
| 1012 | next X |
| 1013 | call prop_type_delete('xxx') |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1014 | endfunc |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 1015 | |
| 1016 | func Test_textprop_remove_from_buf() |
| 1017 | new |
| 1018 | let buf = bufnr('') |
| 1019 | call prop_type_add('one', {'bufnr': buf}) |
| 1020 | call prop_add(1, 1, {'type': 'one', 'id': 234}) |
| 1021 | file x |
| 1022 | edit y |
| 1023 | call prop_remove({'id': 234, 'bufnr': buf}, 1) |
| 1024 | call prop_type_delete('one', {'bufnr': buf}) |
| 1025 | bwipe! x |
| 1026 | close |
| 1027 | endfunc |
Bram Moolenaar | 45311b5 | 2019-08-13 22:27:32 +0200 | [diff] [blame] | 1028 | |
| 1029 | func Test_textprop_in_unloaded_buf() |
| 1030 | edit Xaaa |
| 1031 | call setline(1, 'aaa') |
| 1032 | write |
| 1033 | edit Xbbb |
| 1034 | call setline(1, 'bbb') |
| 1035 | write |
| 1036 | let bnr = bufnr('') |
| 1037 | edit Xaaa |
| 1038 | |
| 1039 | call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'}) |
| 1040 | call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:') |
| 1041 | exe 'buf ' .. bnr |
| 1042 | call assert_equal('bbb', getline(1)) |
| 1043 | call assert_equal(0, prop_list(1)->len()) |
| 1044 | |
| 1045 | bwipe! Xaaa |
| 1046 | bwipe! Xbbb |
| 1047 | cal delete('Xaaa') |
| 1048 | cal delete('Xbbb') |
| 1049 | endfunc |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1050 | |
| 1051 | func Test_proptype_substitute2() |
| 1052 | new |
| 1053 | " text_prop.vim |
| 1054 | call setline(1, [ |
| 1055 | \ 'The num 123 is smaller than 4567.', |
| 1056 | \ '123 The number 123 is smaller than 4567.', |
| 1057 | \ '123 The number 123 is smaller than 4567.']) |
| 1058 | |
| 1059 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1060 | |
| 1061 | call prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1062 | call prop_add(2, 1, {'length': 3, 'type': 'number'}) |
| 1063 | call prop_add(3, 36, {'length': 4, 'type': 'number'}) |
| 1064 | set ul& |
| 1065 | let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, |
| 1066 | \ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, |
| 1067 | \ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}] |
| 1068 | " Add some text in between |
| 1069 | %s/\s\+/ /g |
| 1070 | call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) |
| 1071 | |
| 1072 | " remove some text |
| 1073 | :1s/[a-z]\{3\}//g |
| 1074 | let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] |
| 1075 | call assert_equal(expected, prop_list(1)) |
| 1076 | bwipe! |
| 1077 | endfunc |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1078 | |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1079 | func SaveOptions() |
| 1080 | let d = #{tabstop: &tabstop, |
| 1081 | \ softtabstop: &softtabstop, |
| 1082 | \ shiftwidth: &shiftwidth, |
| 1083 | \ expandtab: &expandtab, |
| 1084 | \ foldmethod: '"' .. &foldmethod .. '"', |
| 1085 | \ } |
| 1086 | return d |
| 1087 | endfunc |
| 1088 | |
| 1089 | func RestoreOptions(dict) |
| 1090 | for name in keys(a:dict) |
| 1091 | exe 'let &' .. name .. ' = ' .. a:dict[name] |
| 1092 | endfor |
| 1093 | endfunc |
| 1094 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1095 | func Test_textprop_noexpandtab() |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1096 | new |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1097 | let save_dict = SaveOptions() |
| 1098 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1099 | set tabstop=8 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1100 | set softtabstop=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1101 | set shiftwidth=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1102 | set noexpandtab |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1103 | set foldmethod=marker |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1104 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1105 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx") |
| 1106 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1107 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1108 | call feedkeys("0i\<tab>", "tx") |
| 1109 | call prop_remove({'type': 'test'}) |
| 1110 | call prop_add(1, 2, {'end_col': 3, 'type': 'test'}) |
| 1111 | call feedkeys("A\<left>\<tab>", "tx") |
| 1112 | call prop_remove({'type': 'test'}) |
| 1113 | try |
| 1114 | " It is correct that this does not pass |
| 1115 | call prop_add(1, 6, {'end_col': 7, 'type': 'test'}) |
| 1116 | " Has already collapsed here, start_col:6 does not result in an error |
| 1117 | call feedkeys("A\<left>\<tab>", "tx") |
| 1118 | catch /^Vim\%((\a\+)\)\=:E964/ |
| 1119 | endtry |
| 1120 | call prop_remove({'type': 'test'}) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1121 | call prop_type_delete('test') |
| 1122 | |
| 1123 | call RestoreOptions(save_dict) |
| 1124 | bwipe! |
| 1125 | endfunc |
| 1126 | |
| 1127 | func Test_textprop_noexpandtab_redraw() |
| 1128 | new |
| 1129 | let save_dict = SaveOptions() |
| 1130 | |
| 1131 | set tabstop=8 |
| 1132 | set softtabstop=4 |
| 1133 | set shiftwidth=4 |
| 1134 | set noexpandtab |
| 1135 | set foldmethod=marker |
| 1136 | |
| 1137 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx") |
| 1138 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1139 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1140 | call feedkeys("0i\<tab>", "tx") |
| 1141 | " Internally broken at the next line |
| 1142 | call feedkeys("A\<left>\<tab>", "tx") |
| 1143 | redraw |
| 1144 | " Index calculation failed internally on next line |
| 1145 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1146 | call prop_remove({'type': 'test', 'all': v:true}) |
| 1147 | call prop_type_delete('test') |
| 1148 | call prop_type_delete('test') |
| 1149 | |
| 1150 | call RestoreOptions(save_dict) |
| 1151 | bwipe! |
| 1152 | endfunc |
| 1153 | |
| 1154 | func Test_textprop_ins_str() |
| 1155 | new |
| 1156 | call setline(1, 'just some text') |
| 1157 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1158 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1159 | call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1)) |
| 1160 | |
| 1161 | call feedkeys("foi\<F8>\<Esc>", "tx") |
| 1162 | call assert_equal('just s<F8>ome text', getline(1)) |
| 1163 | call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1)) |
| 1164 | |
| 1165 | bwipe! |
| 1166 | call prop_remove({'type': 'test'}) |
| 1167 | call prop_type_delete('test') |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1168 | endfunc |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1169 | |
| 1170 | func Test_find_prop_later_in_line() |
| 1171 | new |
| 1172 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1173 | call setline(1, 'just some text') |
| 1174 | call prop_add(1, 1, {'length': 4, 'type': 'test'}) |
| 1175 | call prop_add(1, 10, {'length': 3, 'type': 'test'}) |
| 1176 | |
| 1177 | call assert_equal({'id': 0, 'lnum': 1, 'col': 10, 'end': 1, 'type': 'test', 'length': 3, 'start': 1}, |
| 1178 | \ prop_find(#{type: 'test', lnum: 1, col: 6})) |
| 1179 | |
| 1180 | bwipe! |
| 1181 | call prop_type_delete('test') |
| 1182 | endfunc |
| 1183 | |
| 1184 | func Test_find_zerowidth_prop_sol() |
| 1185 | new |
| 1186 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1187 | call setline(1, 'just some text') |
| 1188 | call prop_add(1, 1, {'length': 0, 'type': 'test'}) |
| 1189 | |
| 1190 | call assert_equal({'id': 0, 'lnum': 1, 'col': 1, 'end': 1, 'type': 'test', 'length': 0, 'start': 1}, |
| 1191 | \ prop_find(#{type: 'test', lnum: 1})) |
| 1192 | |
| 1193 | bwipe! |
| 1194 | call prop_type_delete('test') |
| 1195 | endfunc |