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 | |
| 4 | if !has('textprop') |
| 5 | finish |
| 6 | endif |
| 7 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 8 | source screendump.vim |
| 9 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 10 | " test length zero |
| 11 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 12 | func Test_proptype_global() |
| 13 | call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) |
| 14 | let proptypes = prop_type_list() |
| 15 | call assert_equal(1, len(proptypes)) |
| 16 | call assert_equal('comment', proptypes[0]) |
| 17 | |
| 18 | let proptype = prop_type_get('comment') |
| 19 | call assert_equal('Directory', proptype['highlight']) |
| 20 | call assert_equal(123, proptype['priority']) |
| 21 | call assert_equal(1, proptype['start_incl']) |
| 22 | call assert_equal(1, proptype['end_incl']) |
| 23 | |
| 24 | call prop_type_delete('comment') |
| 25 | call assert_equal(0, len(prop_type_list())) |
| 26 | |
| 27 | call prop_type_add('one', {}) |
| 28 | call assert_equal(1, len(prop_type_list())) |
| 29 | let proptype = prop_type_get('one') |
| 30 | call assert_false(has_key(proptype, 'highlight')) |
| 31 | call assert_equal(0, proptype['priority']) |
| 32 | call assert_equal(0, proptype['start_incl']) |
| 33 | call assert_equal(0, proptype['end_incl']) |
| 34 | |
| 35 | call prop_type_add('two', {}) |
| 36 | call assert_equal(2, len(prop_type_list())) |
| 37 | call prop_type_delete('one') |
| 38 | call assert_equal(1, len(prop_type_list())) |
| 39 | call prop_type_delete('two') |
| 40 | call assert_equal(0, len(prop_type_list())) |
| 41 | endfunc |
| 42 | |
| 43 | func Test_proptype_buf() |
| 44 | let bufnr = bufnr('') |
| 45 | call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) |
| 46 | let proptypes = prop_type_list({'bufnr': bufnr}) |
| 47 | call assert_equal(1, len(proptypes)) |
| 48 | call assert_equal('comment', proptypes[0]) |
| 49 | |
| 50 | let proptype = prop_type_get('comment', {'bufnr': bufnr}) |
| 51 | call assert_equal('Directory', proptype['highlight']) |
| 52 | call assert_equal(123, proptype['priority']) |
| 53 | call assert_equal(1, proptype['start_incl']) |
| 54 | call assert_equal(1, proptype['end_incl']) |
| 55 | |
| 56 | call prop_type_delete('comment', {'bufnr': bufnr}) |
| 57 | call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) |
| 58 | |
| 59 | call prop_type_add('one', {'bufnr': bufnr}) |
| 60 | let proptype = prop_type_get('one', {'bufnr': bufnr}) |
| 61 | call assert_false(has_key(proptype, 'highlight')) |
| 62 | call assert_equal(0, proptype['priority']) |
| 63 | call assert_equal(0, proptype['start_incl']) |
| 64 | call assert_equal(0, proptype['end_incl']) |
| 65 | |
| 66 | call prop_type_add('two', {'bufnr': bufnr}) |
| 67 | call assert_equal(2, len(prop_type_list({'bufnr': bufnr}))) |
| 68 | call prop_type_delete('one', {'bufnr': bufnr}) |
| 69 | call assert_equal(1, len(prop_type_list({'bufnr': bufnr}))) |
| 70 | call prop_type_delete('two', {'bufnr': bufnr}) |
| 71 | call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) |
| 72 | endfunc |
| 73 | |
| 74 | func AddPropTypes() |
| 75 | call prop_type_add('one', {}) |
| 76 | call prop_type_add('two', {}) |
| 77 | call prop_type_add('three', {}) |
| 78 | call prop_type_add('whole', {}) |
| 79 | endfunc |
| 80 | |
| 81 | func DeletePropTypes() |
| 82 | call prop_type_delete('one') |
| 83 | call prop_type_delete('two') |
| 84 | call prop_type_delete('three') |
| 85 | call prop_type_delete('whole') |
| 86 | endfunc |
| 87 | |
| 88 | func SetupPropsInFirstLine() |
| 89 | call setline(1, 'one two three') |
| 90 | call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) |
| 91 | call prop_add(1, 5, {'length': 3, 'id': 12, 'type': 'two'}) |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 92 | call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 93 | call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) |
| 94 | endfunc |
| 95 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 96 | func Get_expected_props() |
| 97 | return [ |
| 98 | \ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 99 | \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 100 | \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 101 | \ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 102 | \ ] |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 103 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 104 | |
| 105 | func Test_prop_add() |
| 106 | new |
| 107 | call AddPropTypes() |
| 108 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 109 | let expected_props = Get_expected_props() |
| 110 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 111 | call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') |
| 112 | call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') |
| 113 | |
| 114 | " Insert a line above, text props must still be there. |
| 115 | call append(0, 'empty') |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 116 | call assert_equal(expected_props, prop_list(2)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 117 | " Delete a line above, text props must still be there. |
| 118 | 1del |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 119 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 120 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 121 | " Prop without length or end column is zero length |
| 122 | call prop_clear(1) |
| 123 | call prop_add(1, 5, {'type': 'two'}) |
| 124 | let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] |
| 125 | call assert_equal(expected, prop_list(1)) |
| 126 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 127 | call DeletePropTypes() |
| 128 | bwipe! |
| 129 | endfunc |
| 130 | |
| 131 | func Test_prop_remove() |
| 132 | new |
| 133 | call AddPropTypes() |
| 134 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 135 | let props = Get_expected_props() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 136 | call assert_equal(props, prop_list(1)) |
| 137 | |
| 138 | " remove by id |
| 139 | call prop_remove({'id': 12}, 1) |
| 140 | unlet props[2] |
| 141 | call assert_equal(props, prop_list(1)) |
| 142 | |
| 143 | " remove by type |
| 144 | call prop_remove({'type': 'one'}, 1) |
| 145 | unlet props[1] |
| 146 | call assert_equal(props, prop_list(1)) |
| 147 | |
| 148 | call DeletePropTypes() |
| 149 | bwipe! |
| 150 | endfunc |
| 151 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 152 | func SetupOneLine() |
| 153 | call setline(1, 'xonex xtwoxx') |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 154 | normal gg0 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 155 | call AddPropTypes() |
| 156 | call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) |
| 157 | call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) |
| 158 | let expected = [ |
| 159 | \ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 160 | \ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
| 161 | \] |
| 162 | call assert_equal(expected, prop_list(1)) |
| 163 | return expected |
| 164 | endfunc |
| 165 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 166 | func Test_prop_add_remove_buf() |
| 167 | new |
| 168 | let bufnr = bufnr('') |
| 169 | call AddPropTypes() |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 170 | for lnum in range(1, 4) |
| 171 | call setline(lnum, 'one two three') |
| 172 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 173 | wincmd w |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 174 | for lnum in range(1, 4) |
| 175 | call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) |
| 176 | call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) |
| 177 | call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) |
| 178 | endfor |
| 179 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 180 | let props = [ |
| 181 | \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, |
| 182 | \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, |
| 183 | \ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, |
| 184 | \] |
| 185 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 186 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 187 | " remove by id |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 188 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 189 | unlet props[1] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 190 | |
| 191 | call prop_remove({'id': 12, 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 192 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 193 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 194 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 195 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 196 | |
| 197 | call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4) |
| 198 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 199 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 200 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 201 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 202 | |
| 203 | call prop_remove({'id': 12, 'bufnr': bufnr}) |
| 204 | for lnum in range(1, 4) |
| 205 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 206 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 207 | |
| 208 | " remove by type |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 209 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 210 | unlet props[0] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 211 | |
| 212 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 213 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 214 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 215 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 216 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 217 | |
| 218 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4) |
| 219 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 220 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 221 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 222 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 223 | |
| 224 | call prop_remove({'type': 'one', 'bufnr': bufnr}) |
| 225 | for lnum in range(1, 4) |
| 226 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 227 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 228 | |
| 229 | call DeletePropTypes() |
| 230 | wincmd w |
| 231 | bwipe! |
| 232 | endfunc |
| 233 | |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 234 | func Test_prop_backspace() |
| 235 | new |
| 236 | set bs=2 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 237 | let expected = SetupOneLine() " 'xonex xtwoxx' |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 238 | |
| 239 | exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" |
| 240 | call assert_equal('one xtwoxx', getline(1)) |
| 241 | let expected[0].col = 1 |
| 242 | let expected[1].col = 6 |
| 243 | call assert_equal(expected, prop_list(1)) |
| 244 | |
| 245 | call DeletePropTypes() |
| 246 | bwipe! |
| 247 | set bs& |
| 248 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 249 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 250 | func Test_prop_replace() |
| 251 | new |
| 252 | set bs=2 |
| 253 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 254 | |
| 255 | exe "normal 0Ryyy\<Esc>" |
| 256 | call assert_equal('yyyex xtwoxx', getline(1)) |
| 257 | call assert_equal(expected, prop_list(1)) |
| 258 | |
| 259 | exe "normal ftRyy\<BS>" |
| 260 | call assert_equal('yyyex xywoxx', getline(1)) |
| 261 | call assert_equal(expected, prop_list(1)) |
| 262 | |
| 263 | exe "normal 0fwRyy\<BS>" |
| 264 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 265 | call assert_equal(expected, prop_list(1)) |
| 266 | |
| 267 | exe "normal 0foRyy\<BS>\<BS>" |
| 268 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 269 | call assert_equal(expected, prop_list(1)) |
| 270 | |
| 271 | call DeletePropTypes() |
| 272 | bwipe! |
| 273 | set bs& |
| 274 | endfunc |
| 275 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 276 | func Test_prop_open_line() |
| 277 | new |
| 278 | |
| 279 | " open new line, props stay in top line |
| 280 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 281 | exe "normal o\<Esc>" |
| 282 | call assert_equal('xonex xtwoxx', getline(1)) |
| 283 | call assert_equal('', getline(2)) |
| 284 | call assert_equal(expected, prop_list(1)) |
| 285 | call DeletePropTypes() |
| 286 | |
| 287 | " move all props to next line |
| 288 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 289 | exe "normal 0i\<CR>\<Esc>" |
| 290 | call assert_equal('', getline(1)) |
| 291 | call assert_equal('xonex xtwoxx', getline(2)) |
| 292 | call assert_equal(expected, prop_list(2)) |
| 293 | call DeletePropTypes() |
| 294 | |
| 295 | " split just before prop, move all props to next line |
| 296 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 297 | exe "normal 0li\<CR>\<Esc>" |
| 298 | call assert_equal('x', getline(1)) |
| 299 | call assert_equal('onex xtwoxx', getline(2)) |
| 300 | let expected[0].col -= 1 |
| 301 | let expected[1].col -= 1 |
| 302 | call assert_equal(expected, prop_list(2)) |
| 303 | call DeletePropTypes() |
| 304 | |
| 305 | " split inside prop, split first prop |
| 306 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 307 | exe "normal 0lli\<CR>\<Esc>" |
| 308 | call assert_equal('xo', getline(1)) |
| 309 | call assert_equal('nex xtwoxx', getline(2)) |
| 310 | let exp_first = [deepcopy(expected[0])] |
| 311 | let exp_first[0].length = 1 |
| 312 | call assert_equal(exp_first, prop_list(1)) |
| 313 | let expected[0].col = 1 |
| 314 | let expected[0].length = 2 |
| 315 | let expected[1].col -= 2 |
| 316 | call assert_equal(expected, prop_list(2)) |
| 317 | call DeletePropTypes() |
| 318 | |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 319 | " split just after first prop, second prop move to next line |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 320 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 321 | exe "normal 0fea\<CR>\<Esc>" |
| 322 | call assert_equal('xone', getline(1)) |
| 323 | call assert_equal('x xtwoxx', getline(2)) |
| 324 | let exp_first = expected[0:0] |
| 325 | call assert_equal(exp_first, prop_list(1)) |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 326 | let expected = expected[1:1] |
| 327 | let expected[0].col -= 4 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 328 | call assert_equal(expected, prop_list(2)) |
| 329 | call DeletePropTypes() |
| 330 | |
| 331 | bwipe! |
| 332 | set bs& |
| 333 | endfunc |
| 334 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 335 | func Test_prop_clear() |
| 336 | new |
| 337 | call AddPropTypes() |
| 338 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 339 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 340 | |
| 341 | call prop_clear(1) |
| 342 | call assert_equal([], prop_list(1)) |
| 343 | |
| 344 | call DeletePropTypes() |
| 345 | bwipe! |
| 346 | endfunc |
| 347 | |
| 348 | func Test_prop_clear_buf() |
| 349 | new |
| 350 | call AddPropTypes() |
| 351 | call SetupPropsInFirstLine() |
| 352 | let bufnr = bufnr('') |
| 353 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 354 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 355 | |
| 356 | call prop_clear(1, 1, {'bufnr': bufnr}) |
| 357 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 358 | |
| 359 | wincmd w |
| 360 | call DeletePropTypes() |
| 361 | bwipe! |
| 362 | endfunc |
| 363 | |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 364 | func Test_prop_setline() |
| 365 | new |
| 366 | call AddPropTypes() |
| 367 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 368 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 369 | |
| 370 | call setline(1, 'foobar') |
| 371 | call assert_equal([], prop_list(1)) |
| 372 | |
| 373 | call DeletePropTypes() |
| 374 | bwipe! |
| 375 | endfunc |
| 376 | |
| 377 | func Test_prop_setbufline() |
| 378 | new |
| 379 | call AddPropTypes() |
| 380 | call SetupPropsInFirstLine() |
| 381 | let bufnr = bufnr('') |
| 382 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 383 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 384 | |
| 385 | call setbufline(bufnr, 1, 'foobar') |
| 386 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 387 | |
| 388 | wincmd w |
| 389 | call DeletePropTypes() |
| 390 | bwipe! |
| 391 | endfunc |
| 392 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 393 | func Test_prop_substitute() |
| 394 | new |
| 395 | " Set first line to 'one two three' |
| 396 | call AddPropTypes() |
| 397 | call SetupPropsInFirstLine() |
| 398 | let expected_props = Get_expected_props() |
| 399 | call assert_equal(expected_props, prop_list(1)) |
| 400 | |
| 401 | " Change "n" in "one" to XX: 'oXXe two three' |
| 402 | s/n/XX/ |
| 403 | let expected_props[0].length += 1 |
| 404 | let expected_props[1].length += 1 |
| 405 | let expected_props[2].col += 1 |
| 406 | let expected_props[3].col += 1 |
| 407 | call assert_equal(expected_props, prop_list(1)) |
| 408 | |
| 409 | " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' |
| 410 | s/t//g |
| 411 | let expected_props[0].length -= 2 |
| 412 | let expected_props[2].length -= 1 |
| 413 | let expected_props[3].length -= 1 |
| 414 | let expected_props[3].col -= 1 |
| 415 | call assert_equal(expected_props, prop_list(1)) |
| 416 | |
| 417 | " Split the line by changing w to line break: 'oXXe ', 'o hree' |
| 418 | " The long prop is split and spans both lines. |
| 419 | " The props on "two" and "three" move to the next line. |
| 420 | s/w/\r/ |
| 421 | let new_props = [ |
| 422 | \ copy(expected_props[0]), |
| 423 | \ copy(expected_props[2]), |
| 424 | \ copy(expected_props[3]), |
| 425 | \ ] |
| 426 | let expected_props[0].length = 5 |
| 427 | unlet expected_props[3] |
| 428 | unlet expected_props[2] |
| 429 | call assert_equal(expected_props, prop_list(1)) |
| 430 | |
| 431 | let new_props[0].length = 6 |
| 432 | let new_props[1].col = 1 |
| 433 | let new_props[1].length = 1 |
| 434 | let new_props[2].col = 3 |
| 435 | call assert_equal(new_props, prop_list(2)) |
| 436 | |
| 437 | call DeletePropTypes() |
| 438 | bwipe! |
| 439 | endfunc |
| 440 | |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 441 | func Test_prop_change_indent() |
| 442 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 443 | new |
| 444 | call setline(1, [' xxx', 'yyyyy']) |
| 445 | call prop_add(2, 2, {'length': 2, 'type': 'comment'}) |
| 446 | let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} |
| 447 | call assert_equal([expect], prop_list(2)) |
| 448 | |
| 449 | set shiftwidth=3 |
| 450 | normal 2G>> |
| 451 | call assert_equal(' yyyyy', getline(2)) |
| 452 | let expect.col += 3 |
| 453 | call assert_equal([expect], prop_list(2)) |
| 454 | |
| 455 | normal 2G== |
| 456 | call assert_equal(' yyyyy', getline(2)) |
| 457 | let expect.col = 6 |
| 458 | call assert_equal([expect], prop_list(2)) |
| 459 | |
| 460 | call prop_clear(2) |
| 461 | call prop_add(2, 2, {'length': 5, 'type': 'comment'}) |
| 462 | let expect.col = 2 |
| 463 | let expect.length = 5 |
| 464 | call assert_equal([expect], prop_list(2)) |
| 465 | |
| 466 | normal 2G<< |
| 467 | call assert_equal(' yyyyy', getline(2)) |
| 468 | let expect.length = 2 |
| 469 | call assert_equal([expect], prop_list(2)) |
| 470 | |
| 471 | set shiftwidth& |
| 472 | call prop_type_delete('comment') |
| 473 | endfunc |
| 474 | |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 475 | " Setup a three line prop in lines 2 - 4. |
| 476 | " Add short props in line 1 and 5. |
| 477 | func Setup_three_line_prop() |
| 478 | new |
| 479 | call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) |
| 480 | call prop_add(1, 2, {'length': 1, 'type': 'comment'}) |
| 481 | call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) |
| 482 | call prop_add(5, 2, {'length': 1, 'type': 'comment'}) |
| 483 | endfunc |
| 484 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 485 | func Test_prop_multiline() |
| 486 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 487 | new |
| 488 | call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) |
| 489 | |
| 490 | " start halfway line 1, end halfway line 3 |
| 491 | call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) |
| 492 | let expect1 = {'col': 3, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 493 | call assert_equal([expect1], prop_list(1)) |
| 494 | let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 495 | call assert_equal([expect2], prop_list(2)) |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 496 | 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] | 497 | call assert_equal([expect3], prop_list(3)) |
| 498 | call prop_clear(1, 3) |
| 499 | |
| 500 | " include all three lines |
| 501 | call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) |
| 502 | let expect1.col = 1 |
| 503 | let expect1.length = 8 |
| 504 | call assert_equal([expect1], prop_list(1)) |
| 505 | call assert_equal([expect2], prop_list(2)) |
| 506 | let expect3.length = 9 |
| 507 | call assert_equal([expect3], prop_list(3)) |
| 508 | call prop_clear(1, 3) |
| 509 | |
| 510 | bwipe! |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 511 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 512 | " Test deleting the first line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 513 | call Setup_three_line_prop() |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 514 | let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} |
| 515 | call assert_equal([expect_short], prop_list(1)) |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 516 | let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 517 | call assert_equal([expect2], prop_list(2)) |
| 518 | 2del |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 519 | call assert_equal([expect_short], prop_list(1)) |
| 520 | let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 521 | call assert_equal([expect2], prop_list(2)) |
| 522 | bwipe! |
| 523 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 524 | " Test deleting the last line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 525 | call Setup_three_line_prop() |
| 526 | let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 527 | call assert_equal([expect3], prop_list(3)) |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 528 | 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] | 529 | call assert_equal([expect4], prop_list(4)) |
| 530 | 4del |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 531 | let expect3.end = 1 |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 532 | call assert_equal([expect3], prop_list(3)) |
| 533 | call assert_equal([expect_short], prop_list(4)) |
| 534 | bwipe! |
| 535 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 536 | " Test appending a line below the multi-line text prop start. |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 537 | call Setup_three_line_prop() |
| 538 | let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} |
| 539 | call assert_equal([expect2], prop_list(2)) |
| 540 | call append(2, "new line") |
| 541 | call assert_equal([expect2], prop_list(2)) |
| 542 | let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} |
| 543 | call assert_equal([expect3], prop_list(3)) |
| 544 | bwipe! |
| 545 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 546 | call prop_type_delete('comment') |
| 547 | endfunc |
| 548 | |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 549 | func Test_prop_byteoff() |
| 550 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 551 | new |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 552 | call setline(1, ['line1', 'second line', '']) |
Bram Moolenaar | 8cf734e | 2018-12-26 01:09:00 +0100 | [diff] [blame] | 553 | set ff=unix |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 554 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 555 | call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 556 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 557 | |
| 558 | bwipe! |
| 559 | call prop_type_delete('comment') |
| 560 | endfunc |
| 561 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 562 | func Test_prop_undo() |
| 563 | new |
| 564 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 565 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 566 | " Set 'undolevels' to break changes into undo-able pieces. |
| 567 | set ul& |
| 568 | |
| 569 | call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) |
| 570 | let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 571 | call assert_equal(expected, prop_list(1)) |
| 572 | |
| 573 | " Insert a character, then undo. |
| 574 | exe "normal 0lllix\<Esc>" |
| 575 | set ul& |
| 576 | let expected[0].length = 3 |
| 577 | call assert_equal(expected, prop_list(1)) |
| 578 | undo |
| 579 | let expected[0].length = 2 |
| 580 | call assert_equal(expected, prop_list(1)) |
| 581 | |
| 582 | " Delete a character, then undo |
| 583 | exe "normal 0lllx" |
| 584 | set ul& |
| 585 | let expected[0].length = 1 |
| 586 | call assert_equal(expected, prop_list(1)) |
| 587 | undo |
| 588 | let expected[0].length = 2 |
| 589 | call assert_equal(expected, prop_list(1)) |
| 590 | |
| 591 | " Delete the line, then undo |
| 592 | 1d |
| 593 | set ul& |
| 594 | call assert_equal([], prop_list(1)) |
| 595 | undo |
| 596 | call assert_equal(expected, prop_list(1)) |
| 597 | |
| 598 | " Insert a character, delete two characters, then undo with "U" |
| 599 | exe "normal 0lllix\<Esc>" |
| 600 | set ul& |
| 601 | let expected[0].length = 3 |
| 602 | call assert_equal(expected, prop_list(1)) |
| 603 | exe "normal 0lllxx" |
| 604 | set ul& |
| 605 | let expected[0].length = 1 |
| 606 | call assert_equal(expected, prop_list(1)) |
| 607 | normal U |
| 608 | let expected[0].length = 2 |
| 609 | call assert_equal(expected, prop_list(1)) |
| 610 | |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 611 | " substitute a word, then undo |
| 612 | call setline(1, 'the number 123 is highlighted.') |
| 613 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
| 614 | let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 615 | call assert_equal(expected, prop_list(1)) |
| 616 | set ul& |
| 617 | 1s/number/foo |
| 618 | let expected[0].col = 9 |
| 619 | call assert_equal(expected, prop_list(1)) |
| 620 | undo |
| 621 | let expected[0].col = 12 |
| 622 | call assert_equal(expected, prop_list(1)) |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 623 | call prop_clear(1) |
| 624 | |
| 625 | " substitute with backslash |
| 626 | call setline(1, 'the number 123 is highlighted.') |
| 627 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
| 628 | let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] |
| 629 | call assert_equal(expected, prop_list(1)) |
| 630 | 1s/the/\The |
| 631 | call assert_equal(expected, prop_list(1)) |
| 632 | 1s/^/\\ |
| 633 | let expected[0].col += 1 |
| 634 | call assert_equal(expected, prop_list(1)) |
| 635 | 1s/^/\~ |
| 636 | let expected[0].col += 1 |
| 637 | call assert_equal(expected, prop_list(1)) |
| 638 | 1s/123/12\\3 |
| 639 | let expected[0].length += 1 |
| 640 | call assert_equal(expected, prop_list(1)) |
| 641 | call prop_clear(1) |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 642 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 643 | bwipe! |
| 644 | call prop_type_delete('comment') |
| 645 | endfunc |
| 646 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 647 | " screenshot test with textprop highlighting |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 648 | func Test_textprop_screenshot_various() |
Bram Moolenaar | ed79d1e | 2019-02-22 14:38:58 +0100 | [diff] [blame] | 649 | " The Vim running in the terminal needs to use utf-8. |
| 650 | if !CanRunVimInTerminal() || g:orig_encoding != 'utf-8' |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 651 | return |
| 652 | endif |
| 653 | call writefile([ |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 654 | \ "call setline(1, [" |
| 655 | \ .. "'One two'," |
| 656 | \ .. "'Numbér 123 änd thœn 4¾7.'," |
| 657 | \ .. "'--aa--bb--cc--dd--'," |
| 658 | \ .. "'// comment with error in it'," |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 659 | \ .. "'first line'," |
| 660 | \ .. "' second line '," |
| 661 | \ .. "'third line'," |
| 662 | \ .. "' fourth line'," |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 663 | \ .. "])", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 664 | \ "hi NumberProp ctermfg=blue", |
| 665 | \ "hi LongProp ctermbg=yellow", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 666 | \ "hi BackgroundProp ctermbg=lightgrey", |
| 667 | \ "hi UnderlineProp cterm=underline", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 668 | \ "call prop_type_add('number', {'highlight': 'NumberProp'})", |
| 669 | \ "call prop_type_add('long', {'highlight': 'LongProp'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 670 | \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", |
| 671 | \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", |
| 672 | \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 673 | \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 1})", |
| 674 | \ "call prop_type_add('error', {'highlight': 'UnderlineProp', 'combine': 1})", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 675 | \ "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] | 676 | \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", |
| 677 | \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 678 | \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", |
| 679 | \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", |
| 680 | \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", |
| 681 | \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 682 | \ "call prop_add(4, 12, {'length': 10, 'type': 'background'})", |
| 683 | \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 684 | \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})", |
| 685 | \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})", |
| 686 | \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})", |
| 687 | \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})", |
Bram Moolenaar | bfd4512 | 2019-05-17 13:05:07 +0200 | [diff] [blame] | 688 | \ "set number cursorline", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 689 | \ "hi clear SpellBad", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 690 | \ "set spell", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 691 | \ "syn match Comment '//.*'", |
| 692 | \ "hi Comment ctermfg=green", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 693 | \ "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] | 694 | \ "normal 3G0lli\<BS>\<Esc>", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 695 | \ "normal 6G0i\<BS>\<Esc>", |
| 696 | \ "normal 3J", |
| 697 | \ "normal 3G", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 698 | \], 'XtestProp') |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 699 | let buf = RunVimInTerminal('-S XtestProp', {'rows': 8}) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 700 | call VerifyScreenDump(buf, 'Test_textprop_01', {}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 701 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 702 | " clean up |
| 703 | call StopVimInTerminal(buf) |
Bram Moolenaar | 2f21fa8 | 2018-12-31 20:05:56 +0100 | [diff] [blame] | 704 | call delete('XtestProp') |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 705 | endfunc |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 706 | |
| 707 | func RunTestVisualBlock(width, dump) |
| 708 | call writefile([ |
| 709 | \ "call setline(1, [" |
| 710 | \ .. "'xxxxxxxxx 123 x'," |
| 711 | \ .. "'xxxxxxxx 123 x'," |
| 712 | \ .. "'xxxxxxx 123 x'," |
| 713 | \ .. "'xxxxxx 123 x'," |
| 714 | \ .. "'xxxxx 123 x'," |
| 715 | \ .. "'xxxx 123 xx'," |
| 716 | \ .. "'xxx 123 xxx'," |
| 717 | \ .. "'xx 123 xxxx'," |
| 718 | \ .. "'x 123 xxxxx'," |
| 719 | \ .. "' 123 xxxxxx'," |
| 720 | \ .. "])", |
| 721 | \ "hi SearchProp ctermbg=yellow", |
| 722 | \ "call prop_type_add('search', {'highlight': 'SearchProp'})", |
| 723 | \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", |
| 724 | \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", |
| 725 | \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", |
| 726 | \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", |
| 727 | \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", |
| 728 | \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", |
| 729 | \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", |
| 730 | \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", |
| 731 | \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", |
| 732 | \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", |
| 733 | \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", |
| 734 | \], 'XtestPropVis') |
| 735 | let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) |
| 736 | call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) |
| 737 | |
| 738 | " clean up |
| 739 | call StopVimInTerminal(buf) |
| 740 | call delete('XtestPropVis') |
| 741 | endfunc |
| 742 | |
| 743 | " screenshot test with Visual block mode operations |
| 744 | func Test_textprop_screenshot_visual() |
| 745 | if !CanRunVimInTerminal() |
| 746 | return |
| 747 | endif |
| 748 | |
| 749 | " Delete two columns while text props are three chars wide. |
| 750 | call RunTestVisualBlock(2, '01') |
| 751 | |
| 752 | " Same, but delete four columns |
| 753 | call RunTestVisualBlock(4, '02') |
| 754 | endfunc |