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 | CheckFeature textprop |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 5 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 6 | source util/screendump.vim |
| 7 | import './util/vim9.vim' as v9 |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 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('') |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 42 | call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 1024690 | 2022-08-08 17:08:05 +0100 | [diff] [blame] | 73 | def Test_proptype_add_remove() |
| 74 | # add and remove a prop type so that the array is empty |
| 75 | prop_type_add('local', {bufnr: bufnr('%')}) |
| 76 | prop_type_delete('local', {bufnr: bufnr('%')}) |
| 77 | prop_type_add('global', {highlight: 'ErrorMsg'}) |
| 78 | prop_add(1, 1, {length: 1, type: 'global'}) |
| 79 | redraw |
| 80 | |
| 81 | prop_clear(1) |
| 82 | prop_type_delete('global') |
| 83 | enddef |
| 84 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 85 | def Test_proptype_buf_list() |
| 86 | new |
| 87 | var bufnr = bufnr('') |
| 88 | try |
| 89 | prop_type_add('global', {}) |
| 90 | prop_type_add('local', {bufnr: bufnr}) |
| 91 | |
| 92 | prop_add(1, 1, {type: 'global'}) |
| 93 | prop_add(1, 1, {type: 'local'}) |
| 94 | |
| 95 | assert_equal([ |
| 96 | {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1}, |
| 97 | {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1}, |
| 98 | ], prop_list(1)) |
| 99 | assert_equal( |
| 100 | {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1}, |
| 101 | prop_find({lnum: 1, type: 'local'})) |
| 102 | assert_equal( |
| 103 | {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1}, |
| 104 | prop_find({lnum: 1, type: 'global'})) |
| 105 | |
| 106 | prop_remove({type: 'global'}, 1) |
| 107 | prop_remove({type: 'local'}, 1) |
| 108 | finally |
| 109 | prop_type_delete('global') |
| 110 | prop_type_delete('local', {bufnr: bufnr}) |
| 111 | bwipe! |
| 112 | endtry |
| 113 | enddef |
| 114 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 115 | func AddPropTypes() |
| 116 | call prop_type_add('one', {}) |
| 117 | call prop_type_add('two', {}) |
| 118 | call prop_type_add('three', {}) |
| 119 | call prop_type_add('whole', {}) |
| 120 | endfunc |
| 121 | |
| 122 | func DeletePropTypes() |
| 123 | call prop_type_delete('one') |
| 124 | call prop_type_delete('two') |
| 125 | call prop_type_delete('three') |
| 126 | call prop_type_delete('whole') |
| 127 | endfunc |
| 128 | |
| 129 | func SetupPropsInFirstLine() |
| 130 | call setline(1, 'one two three') |
| 131 | call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 132 | eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'}) |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 133 | call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 134 | call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) |
| 135 | endfunc |
| 136 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 137 | func Get_expected_props() |
| 138 | return [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 139 | \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1}, |
| 140 | \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 141 | \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
| 142 | \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 143 | \ ] |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 144 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 145 | |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 146 | func Test_prop_find() |
| 147 | new |
| 148 | call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 149 | |
| 150 | " Add two text props on lines 1 and 5, and one spanning lines 2 to 4. |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 151 | call prop_type_add('prop_name', {'highlight': 'Directory'}) |
| 152 | call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) |
| 153 | call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) |
| 154 | call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) |
| 155 | |
| 156 | let expected = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 157 | \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1}, |
| 158 | \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0}, |
| 159 | \ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1} |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 160 | \ ] |
| 161 | |
| 162 | " Starting at line 5 col 1 this should find the prop at line 5 col 4. |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 163 | call cursor(5, 1) |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 164 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 165 | call assert_equal(expected[2], result) |
| 166 | |
| 167 | " With skipstart left at false (default), this should find the prop at line |
| 168 | " 5 col 4. |
| 169 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b') |
| 170 | call assert_equal(expected[2], result) |
| 171 | |
| 172 | " With skipstart set to true, this should skip the prop at line 5 col 4. |
| 173 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b') |
| 174 | unlet result.length |
| 175 | call assert_equal(expected[1], result) |
| 176 | |
| 177 | " Search backwards from line 1 col 10 to find the prop on the same line. |
| 178 | let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b') |
| 179 | call assert_equal(expected[0], result) |
| 180 | |
| 181 | " with skipstart set to false, if the start position is anywhere between the |
| 182 | " start and end lines of a text prop (searching forward or backward), the |
| 183 | " result should be the prop on the first line (the line with 'start' set to 1). |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 184 | call cursor(3, 1) |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 185 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 186 | unlet result.length |
| 187 | call assert_equal(expected[1], result) |
| 188 | let result = prop_find({'type': 'prop_name'}, 'b') |
| 189 | unlet result.length |
| 190 | call assert_equal(expected[1], result) |
| 191 | |
| 192 | " with skipstart set to true, if the start position is anywhere between the |
| 193 | " start and end lines of a text prop (searching forward or backward), all lines |
| 194 | " of the prop will be skipped. |
| 195 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b') |
| 196 | call assert_equal(expected[0], result) |
| 197 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f') |
| 198 | call assert_equal(expected[2], result) |
| 199 | |
| 200 | " Use skipstart to search through all props with type name 'prop_name'. |
| 201 | " First forward... |
| 202 | let lnum = 1 |
| 203 | let col = 1 |
| 204 | let i = 0 |
| 205 | for exp in expected |
| 206 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f') |
| 207 | if !has_key(exp, "length") |
| 208 | unlet result.length |
| 209 | endif |
| 210 | call assert_equal(exp, result) |
| 211 | let lnum = result.lnum |
| 212 | let col = result.col |
| 213 | let i = i + 1 |
| 214 | endfor |
| 215 | |
| 216 | " ...then backwards. |
| 217 | let lnum = 6 |
| 218 | let col = 4 |
| 219 | let i = 2 |
| 220 | while i >= 0 |
| 221 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b') |
| 222 | if !has_key(expected[i], "length") |
| 223 | unlet result.length |
| 224 | endif |
| 225 | call assert_equal(expected[i], result) |
| 226 | let lnum = result.lnum |
| 227 | let col = result.col |
| 228 | let i = i - 1 |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 229 | endwhile |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 230 | |
| 231 | " Starting from line 6 col 1 search backwards for prop with id 10. |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 232 | call cursor(6, 1) |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 233 | let result = prop_find({'id': 10, 'skipstart': 1}, 'b') |
| 234 | call assert_equal(expected[0], result) |
| 235 | |
| 236 | " Starting from line 1 col 1 search forwards for prop with id 12. |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 237 | call cursor(1, 1) |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 238 | let result = prop_find({'id': 12}, 'f') |
| 239 | call assert_equal(expected[2], result) |
| 240 | |
| 241 | " Search for a prop with an unknown id. |
| 242 | let result = prop_find({'id': 999}, 'f') |
| 243 | call assert_equal({}, result) |
| 244 | |
| 245 | " Search backwards from the proceeding position of the prop with id 11 |
| 246 | " (at line num 2 col 4). This should return an empty dict. |
| 247 | let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b') |
| 248 | call assert_equal({}, result) |
| 249 | |
| 250 | " When lnum is given and col is omitted, use column 1. |
| 251 | let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f') |
| 252 | call assert_equal(expected[0], result) |
| 253 | |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 254 | " Negative ID is possible, just like prop is not found. |
Bram Moolenaar | 8e3fc13 | 2021-07-31 18:33:57 +0200 | [diff] [blame] | 255 | call assert_equal({}, prop_find({'id': -1})) |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 256 | call assert_equal({}, prop_find({'id': -2})) |
Bram Moolenaar | 8e3fc13 | 2021-07-31 18:33:57 +0200 | [diff] [blame] | 257 | |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 258 | call prop_clear(1, 6) |
| 259 | |
| 260 | " Default ID is zero |
| 261 | call prop_add(5, 4, {'type': 'prop_name', 'length': 1}) |
| 262 | call assert_equal(#{lnum: 5, id: 0, col: 4, type_bufnr: 0, end: 1, type: 'prop_name', length: 1, start: 1}, prop_find({'id': 0})) |
| 263 | |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 264 | call prop_type_delete('prop_name') |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 265 | call prop_clear(1, 6) |
Bram Moolenaar | 4da7a25 | 2020-09-02 19:59:00 +0200 | [diff] [blame] | 266 | bwipe! |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 267 | endfunc |
| 268 | |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 269 | def Test_prop_find2() |
| 270 | # Multiple props per line, start on the first, should find the second. |
| 271 | new |
| 272 | ['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1) |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 273 | prop_type_add('misspell', {highlight: 'ErrorMsg'}) |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 274 | for lnum in [1, 2] |
| 275 | for col in [8, 14, 24, 38] |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 276 | prop_add(lnum, col, {type: 'misspell', length: 2}) |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 277 | endfor |
| 278 | endfor |
| 279 | cursor(1, 8) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 280 | var expected = {type_bufnr: 0, lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1} |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 281 | var result = prop_find({type: 'misspell', skipstart: true}, 'f') |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 282 | assert_equal(expected, result) |
| 283 | |
| 284 | prop_type_delete('misspell') |
| 285 | bwipe! |
| 286 | enddef |
| 287 | |
Bram Moolenaar | 346f18e | 2020-03-13 21:36:40 +0100 | [diff] [blame] | 288 | func Test_prop_find_smaller_len_than_match_col() |
| 289 | new |
| 290 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 291 | call setline(1, ['xxxx', 'x']) |
| 292 | call prop_add(1, 4, {'type': 'test'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 293 | call assert_equal( |
| 294 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1}, |
Bram Moolenaar | 346f18e | 2020-03-13 21:36:40 +0100 | [diff] [blame] | 295 | \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b')) |
| 296 | bwipe! |
| 297 | call prop_type_delete('test') |
| 298 | endfunc |
| 299 | |
Bram Moolenaar | 24f21fd | 2021-03-27 22:07:29 +0100 | [diff] [blame] | 300 | func Test_prop_find_with_both_option_enabled() |
| 301 | " Initialize |
| 302 | new |
| 303 | call AddPropTypes() |
| 304 | call SetupPropsInFirstLine() |
| 305 | let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})}) |
| 306 | " Test |
| 307 | call assert_fails("call prop_find({'both': 1})", 'E968:') |
| 308 | call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:') |
| 309 | call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:') |
| 310 | call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1})) |
| 311 | call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1})) |
| 312 | call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1})) |
| 313 | call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1})) |
| 314 | " Clean up |
| 315 | call DeletePropTypes() |
| 316 | bwipe! |
| 317 | endfunc |
| 318 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 319 | func Test_prop_add() |
| 320 | new |
| 321 | call AddPropTypes() |
| 322 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 323 | let expected_props = Get_expected_props() |
| 324 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 325 | call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') |
| 326 | call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 327 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 328 | " Insert a line above, text props must still be there. |
| 329 | call append(0, 'empty') |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 330 | call assert_equal(expected_props, prop_list(2)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 331 | " Delete a line above, text props must still be there. |
| 332 | 1del |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 333 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 334 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 335 | " Prop without length or end column is zero length |
| 336 | call prop_clear(1) |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 337 | call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) |
| 338 | call prop_add(1, 5, #{type: 'included'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 339 | let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}] |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 340 | call assert_equal(expected, prop_list(1)) |
| 341 | |
| 342 | " Inserting text makes the prop bigger. |
| 343 | exe "normal 5|ixx\<Esc>" |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 344 | let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}] |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 345 | call assert_equal(expected, prop_list(1)) |
| 346 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 347 | call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') |
| 348 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 349 | call DeletePropTypes() |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 350 | call prop_type_delete('included') |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 351 | bwipe! |
| 352 | endfunc |
| 353 | |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 354 | " Test for the prop_add_list() function |
| 355 | func Test_prop_add_list() |
| 356 | new |
| 357 | call AddPropTypes() |
| 358 | call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten']) |
| 359 | call prop_add_list(#{type: 'one', id: 2}, |
| 360 | \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]]) |
| 361 | call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one', |
| 362 | \ length: 2, start: 1}], prop_list(1)) |
| 363 | call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one', |
| 364 | \ length: 2, start: 1}], prop_list(2)) |
| 365 | call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one', |
| 366 | \ length: 7, start: 1}], prop_list(3)) |
| 367 | call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one', |
| 368 | \ length: 5, start: 0}], prop_list(4)) |
Bram Moolenaar | d93009e | 2022-10-13 14:35:24 +0100 | [diff] [blame] | 369 | call prop_remove(#{id: 2}) |
| 370 | call assert_equal([], prop_list(1)) |
| 371 | |
| 372 | call prop_add_list(#{type: 'one', id: 3}, |
| 373 | \ [[1, 1, 1, 3], [2, 5, 2, 7, 9]]) |
| 374 | call assert_equal([#{id: 3, col: 1, type_bufnr: 0, end: 1, type: 'one', |
| 375 | \ length: 2, start: 1}], prop_list(1)) |
| 376 | call assert_equal([#{id: 9, col: 5, type_bufnr: 0, end: 1, type: 'one', |
| 377 | \ length: 2, start: 1}], prop_list(2)) |
| 378 | |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 379 | call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:') |
| 380 | call assert_fails('call prop_add_list({}, {})', 'E1211:') |
| 381 | call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:') |
| 382 | call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:') |
| 383 | call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:') |
| 384 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:') |
| 385 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:') |
| 386 | call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:') |
| 387 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:') |
| 388 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:') |
| 389 | call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:') |
| 390 | call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') |
| 391 | call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') |
| 392 | call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:') |
Bram Moolenaar | d83392a | 2022-09-01 12:22:46 +0100 | [diff] [blame] | 393 | call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E1298:') |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 394 | call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:') |
Christian Brabandt | 701c863 | 2024-09-08 20:05:23 +0200 | [diff] [blame] | 395 | call assert_fails('call prop_add_list(#{type: "one", id: 2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:') |
| 396 | call assert_fails('call prop_add_list(#{type: "one", id: -2147483648}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E1510:') |
Bram Moolenaar | 4997f2a | 2022-10-13 14:00:45 +0100 | [diff] [blame] | 397 | |
| 398 | " only one error for multiple wrong values |
| 399 | call assert_fails('call prop_add_list(#{type: "one"}, [[{}, [], 0z00, 0.3]])', ['E728:', 'E728:']) |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 400 | call DeletePropTypes() |
| 401 | bw! |
| 402 | endfunc |
| 403 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 404 | func Test_prop_remove() |
| 405 | new |
| 406 | call AddPropTypes() |
| 407 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 408 | let props = Get_expected_props() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 409 | call assert_equal(props, prop_list(1)) |
| 410 | |
| 411 | " remove by id |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 412 | call assert_equal(1, {'id': 12}->prop_remove(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 413 | unlet props[2] |
| 414 | call assert_equal(props, prop_list(1)) |
| 415 | |
| 416 | " remove by type |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 417 | call assert_equal(1, prop_remove({'type': 'one'}, 1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 418 | unlet props[1] |
| 419 | call assert_equal(props, prop_list(1)) |
| 420 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 421 | " remove from unknown buffer |
| 422 | call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:') |
| 423 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 424 | call DeletePropTypes() |
| 425 | bwipe! |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 426 | |
| 427 | new |
| 428 | call AddPropTypes() |
| 429 | call SetupPropsInFirstLine() |
| 430 | call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) |
| 431 | let props = Get_expected_props() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 432 | call insert(props, #{type_bufnr: 0, col: 6, length: 2, id: 11, type: 'three', start: 1, end: 1}, 3) |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 433 | call assert_equal(props, prop_list(1)) |
| 434 | call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) |
| 435 | unlet props[3] |
| 436 | call assert_equal(props, prop_list(1)) |
| 437 | |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 438 | call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:') |
| 439 | call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:') |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 440 | |
| 441 | call DeletePropTypes() |
| 442 | bwipe! |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 443 | |
| 444 | new |
| 445 | call AddPropTypes() |
| 446 | call SetupPropsInFirstLine() |
| 447 | let props = Get_expected_props() " [whole, one, two, three] |
| 448 | call assert_equal(props, prop_list(1)) |
| 449 | |
| 450 | " remove one by types |
| 451 | call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1)) |
| 452 | unlet props[1] " [whole, two, three] |
| 453 | call assert_equal(props, prop_list(1)) |
| 454 | |
| 455 | " remove 'all' by types |
| 456 | call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1)) |
| 457 | unlet props[0] " [two, three] |
| 458 | unlet props[1] " [three] |
| 459 | call assert_equal(props, prop_list(1)) |
| 460 | |
| 461 | " remove none by types |
| 462 | call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1)) |
| 463 | call assert_equal(props, prop_list(1)) |
| 464 | |
| 465 | " no types |
| 466 | call assert_fails("call prop_remove({'types': []}, 1)", 'E968:') |
| 467 | call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:') |
| 468 | |
| 469 | " only one of types and type can be supplied |
| 470 | call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:') |
| 471 | |
| 472 | call DeletePropTypes() |
| 473 | bwipe! |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 474 | endfunc |
| 475 | |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 476 | def Test_prop_add_vim9() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 477 | prop_type_add('comment', { |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 478 | highlight: 'Directory', |
| 479 | priority: 123, |
| 480 | start_incl: true, |
| 481 | end_incl: true, |
| 482 | combine: false, |
| 483 | }) |
| 484 | prop_type_delete('comment') |
| 485 | enddef |
| 486 | |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 487 | def Test_prop_remove_vim9() |
| 488 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 489 | g:AddPropTypes() |
| 490 | g:SetupPropsInFirstLine() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 491 | assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true})) |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 492 | g:DeletePropTypes() |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 493 | bwipe! |
| 494 | enddef |
| 495 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 496 | func SetupOneLine() |
| 497 | call setline(1, 'xonex xtwoxx') |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 498 | normal gg0 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 499 | call AddPropTypes() |
| 500 | call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) |
| 501 | call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) |
| 502 | let expected = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 503 | \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 504 | \ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 505 | \] |
| 506 | call assert_equal(expected, prop_list(1)) |
| 507 | return expected |
| 508 | endfunc |
| 509 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 510 | func Test_prop_add_remove_buf() |
| 511 | new |
| 512 | let bufnr = bufnr('') |
| 513 | call AddPropTypes() |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 514 | for lnum in range(1, 4) |
| 515 | call setline(lnum, 'one two three') |
| 516 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 517 | wincmd w |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 518 | for lnum in range(1, 4) |
| 519 | call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) |
| 520 | call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) |
| 521 | call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) |
| 522 | endfor |
| 523 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 524 | let props = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 525 | \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 526 | \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
| 527 | \ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1}, |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 528 | \] |
| 529 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 530 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 531 | " remove by id |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 532 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 533 | unlet props[1] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 534 | |
| 535 | call prop_remove({'id': 12, 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 536 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 537 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 538 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 539 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 540 | |
| 541 | call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4) |
| 542 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 543 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 544 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 545 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 546 | |
| 547 | call prop_remove({'id': 12, 'bufnr': bufnr}) |
| 548 | for lnum in range(1, 4) |
| 549 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 550 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 551 | |
| 552 | " remove by type |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 553 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 554 | unlet props[0] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 555 | |
| 556 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 557 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 558 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 559 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 560 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 561 | |
| 562 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4) |
| 563 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 564 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 565 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 566 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 567 | |
| 568 | call prop_remove({'type': 'one', 'bufnr': bufnr}) |
| 569 | for lnum in range(1, 4) |
| 570 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 571 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 572 | |
| 573 | call DeletePropTypes() |
| 574 | wincmd w |
| 575 | bwipe! |
| 576 | endfunc |
| 577 | |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 578 | func Test_prop_backspace() |
| 579 | new |
| 580 | set bs=2 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 581 | let expected = SetupOneLine() " 'xonex xtwoxx' |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 582 | |
| 583 | exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" |
| 584 | call assert_equal('one xtwoxx', getline(1)) |
| 585 | let expected[0].col = 1 |
| 586 | let expected[1].col = 6 |
| 587 | call assert_equal(expected, prop_list(1)) |
| 588 | |
| 589 | call DeletePropTypes() |
| 590 | bwipe! |
| 591 | set bs& |
| 592 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 593 | |
LemonBoy | d0b1a09 | 2022-05-12 18:45:18 +0100 | [diff] [blame] | 594 | func Test_prop_change() |
| 595 | new |
| 596 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 597 | |
| 598 | " Characterwise. |
| 599 | exe "normal 7|c$\<Esc>" |
| 600 | call assert_equal('xonex ', getline(1)) |
| 601 | call assert_equal(expected[:0], prop_list(1)) |
| 602 | " Linewise. |
| 603 | exe "normal cc\<Esc>" |
| 604 | call assert_equal('', getline(1)) |
| 605 | call assert_equal([], prop_list(1)) |
| 606 | |
| 607 | call DeletePropTypes() |
| 608 | bwipe! |
| 609 | set bs& |
| 610 | endfunc |
| 611 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 612 | func Test_prop_replace() |
| 613 | new |
| 614 | set bs=2 |
| 615 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 616 | |
| 617 | exe "normal 0Ryyy\<Esc>" |
| 618 | call assert_equal('yyyex xtwoxx', getline(1)) |
| 619 | call assert_equal(expected, prop_list(1)) |
| 620 | |
| 621 | exe "normal ftRyy\<BS>" |
| 622 | call assert_equal('yyyex xywoxx', getline(1)) |
| 623 | call assert_equal(expected, prop_list(1)) |
| 624 | |
| 625 | exe "normal 0fwRyy\<BS>" |
| 626 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 627 | call assert_equal(expected, prop_list(1)) |
| 628 | |
| 629 | exe "normal 0foRyy\<BS>\<BS>" |
| 630 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 631 | call assert_equal(expected, prop_list(1)) |
| 632 | |
LemonBoy | 0d534d9 | 2022-05-21 11:20:42 +0100 | [diff] [blame] | 633 | " Replace three 1-byte chars with three 2-byte ones. |
| 634 | exe "normal 0l3rΓΈ" |
| 635 | call assert_equal('yΓΈΓΈΓΈx xyyoxx', getline(1)) |
| 636 | let expected[0].length += 3 |
| 637 | let expected[1].col += 3 |
| 638 | call assert_equal(expected, prop_list(1)) |
| 639 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 640 | call DeletePropTypes() |
| 641 | bwipe! |
| 642 | set bs& |
| 643 | endfunc |
| 644 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 645 | func Test_prop_open_line() |
| 646 | new |
| 647 | |
| 648 | " open new line, props stay in top line |
| 649 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 650 | exe "normal o\<Esc>" |
| 651 | call assert_equal('xonex xtwoxx', getline(1)) |
| 652 | call assert_equal('', getline(2)) |
| 653 | call assert_equal(expected, prop_list(1)) |
| 654 | call DeletePropTypes() |
| 655 | |
| 656 | " move all props to next line |
| 657 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 658 | exe "normal 0i\<CR>\<Esc>" |
| 659 | call assert_equal('', getline(1)) |
| 660 | call assert_equal('xonex xtwoxx', getline(2)) |
| 661 | call assert_equal(expected, prop_list(2)) |
| 662 | call DeletePropTypes() |
| 663 | |
| 664 | " split just before prop, move all props to next line |
| 665 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 666 | exe "normal 0li\<CR>\<Esc>" |
| 667 | call assert_equal('x', getline(1)) |
| 668 | call assert_equal('onex xtwoxx', getline(2)) |
| 669 | let expected[0].col -= 1 |
| 670 | let expected[1].col -= 1 |
| 671 | call assert_equal(expected, prop_list(2)) |
| 672 | call DeletePropTypes() |
| 673 | |
| 674 | " split inside prop, split first prop |
| 675 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 676 | exe "normal 0lli\<CR>\<Esc>" |
| 677 | call assert_equal('xo', getline(1)) |
| 678 | call assert_equal('nex xtwoxx', getline(2)) |
| 679 | let exp_first = [deepcopy(expected[0])] |
| 680 | let exp_first[0].length = 1 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 681 | let exp_first[0].end = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 682 | call assert_equal(exp_first, prop_list(1)) |
| 683 | let expected[0].col = 1 |
| 684 | let expected[0].length = 2 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 685 | let expected[0].start = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 686 | let expected[1].col -= 2 |
| 687 | call assert_equal(expected, prop_list(2)) |
| 688 | call DeletePropTypes() |
| 689 | |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 690 | " split just after first prop, second prop move to next line |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 691 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 692 | exe "normal 0fea\<CR>\<Esc>" |
| 693 | call assert_equal('xone', getline(1)) |
| 694 | call assert_equal('x xtwoxx', getline(2)) |
| 695 | let exp_first = expected[0:0] |
| 696 | call assert_equal(exp_first, prop_list(1)) |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 697 | let expected = expected[1:1] |
| 698 | let expected[0].col -= 4 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 699 | call assert_equal(expected, prop_list(2)) |
| 700 | call DeletePropTypes() |
| 701 | |
LemonBoy | 788c06a | 2022-05-14 18:48:05 +0100 | [diff] [blame] | 702 | " split at the space character with 'ai' active, the leading space is removed |
| 703 | " in the second line and the prop is shifted accordingly. |
| 704 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 705 | set ai |
| 706 | exe "normal 6|i\<CR>\<Esc>" |
| 707 | call assert_equal('xonex', getline(1)) |
| 708 | call assert_equal('xtwoxx', getline(2)) |
| 709 | let expected[1].col -= 6 |
| 710 | call assert_equal(expected, prop_list(1) + prop_list(2)) |
| 711 | set ai& |
| 712 | call DeletePropTypes() |
| 713 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 714 | bwipe! |
| 715 | set bs& |
| 716 | endfunc |
| 717 | |
Bram Moolenaar | ecb00c7 | 2022-08-07 14:55:14 +0100 | [diff] [blame] | 718 | func Test_prop_put() |
| 719 | new |
| 720 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 721 | |
| 722 | let @a = 'new' |
| 723 | " insert just after the prop |
| 724 | normal 03l"ap |
| 725 | " insert inside the prop |
| 726 | normal 02l"ap |
| 727 | " insert just before the prop |
| 728 | normal 0"ap |
| 729 | |
| 730 | call assert_equal('xnewonnewenewx xtwoxx', getline(1)) |
| 731 | let expected[0].col += 3 |
| 732 | let expected[0].length += 3 |
| 733 | let expected[1].col += 9 |
| 734 | call assert_equal(expected, prop_list(1)) |
| 735 | |
| 736 | " Visually select 4 chars in the prop and put "AB" to replace them |
| 737 | let @a = 'AB' |
| 738 | normal 05lv3l"ap |
| 739 | call assert_equal('xnewoABenewx xtwoxx', getline(1)) |
| 740 | let expected[0].length -= 2 |
| 741 | let expected[1].col -= 2 |
| 742 | call assert_equal(expected, prop_list(1)) |
| 743 | |
| 744 | call DeletePropTypes() |
| 745 | bwipe! |
| 746 | endfunc |
| 747 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 748 | func Test_prop_clear() |
| 749 | new |
| 750 | call AddPropTypes() |
| 751 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 752 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 753 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 754 | eval 1->prop_clear() |
| 755 | call assert_equal([], 1->prop_list()) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 756 | |
| 757 | call DeletePropTypes() |
| 758 | bwipe! |
| 759 | endfunc |
| 760 | |
| 761 | func Test_prop_clear_buf() |
| 762 | new |
| 763 | call AddPropTypes() |
| 764 | call SetupPropsInFirstLine() |
| 765 | let bufnr = bufnr('') |
| 766 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 767 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 768 | |
| 769 | call prop_clear(1, 1, {'bufnr': bufnr}) |
| 770 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 771 | |
| 772 | wincmd w |
| 773 | call DeletePropTypes() |
| 774 | bwipe! |
| 775 | endfunc |
| 776 | |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 777 | func Test_prop_setline() |
| 778 | new |
| 779 | call AddPropTypes() |
| 780 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 781 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 782 | |
| 783 | call setline(1, 'foobar') |
| 784 | call assert_equal([], prop_list(1)) |
| 785 | |
| 786 | call DeletePropTypes() |
| 787 | bwipe! |
| 788 | endfunc |
| 789 | |
| 790 | func Test_prop_setbufline() |
| 791 | new |
| 792 | call AddPropTypes() |
| 793 | call SetupPropsInFirstLine() |
| 794 | let bufnr = bufnr('') |
| 795 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 796 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 797 | |
| 798 | call setbufline(bufnr, 1, 'foobar') |
| 799 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 800 | |
| 801 | wincmd w |
| 802 | call DeletePropTypes() |
| 803 | bwipe! |
| 804 | endfunc |
| 805 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 806 | func Test_prop_substitute() |
| 807 | new |
| 808 | " Set first line to 'one two three' |
| 809 | call AddPropTypes() |
| 810 | call SetupPropsInFirstLine() |
| 811 | let expected_props = Get_expected_props() |
| 812 | call assert_equal(expected_props, prop_list(1)) |
| 813 | |
| 814 | " Change "n" in "one" to XX: 'oXXe two three' |
| 815 | s/n/XX/ |
| 816 | let expected_props[0].length += 1 |
| 817 | let expected_props[1].length += 1 |
| 818 | let expected_props[2].col += 1 |
| 819 | let expected_props[3].col += 1 |
| 820 | call assert_equal(expected_props, prop_list(1)) |
| 821 | |
| 822 | " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' |
| 823 | s/t//g |
| 824 | let expected_props[0].length -= 2 |
| 825 | let expected_props[2].length -= 1 |
| 826 | let expected_props[3].length -= 1 |
| 827 | let expected_props[3].col -= 1 |
| 828 | call assert_equal(expected_props, prop_list(1)) |
| 829 | |
| 830 | " Split the line by changing w to line break: 'oXXe ', 'o hree' |
| 831 | " The long prop is split and spans both lines. |
| 832 | " The props on "two" and "three" move to the next line. |
| 833 | s/w/\r/ |
| 834 | let new_props = [ |
| 835 | \ copy(expected_props[0]), |
| 836 | \ copy(expected_props[2]), |
| 837 | \ copy(expected_props[3]), |
| 838 | \ ] |
| 839 | let expected_props[0].length = 5 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 840 | let expected_props[0].end = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 841 | unlet expected_props[3] |
| 842 | unlet expected_props[2] |
| 843 | call assert_equal(expected_props, prop_list(1)) |
| 844 | |
| 845 | let new_props[0].length = 6 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 846 | let new_props[0].start = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 847 | let new_props[1].col = 1 |
| 848 | let new_props[1].length = 1 |
| 849 | let new_props[2].col = 3 |
| 850 | call assert_equal(new_props, prop_list(2)) |
| 851 | |
| 852 | call DeletePropTypes() |
| 853 | bwipe! |
| 854 | endfunc |
| 855 | |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 856 | func Test_prop_change_indent() |
| 857 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 858 | new |
| 859 | call setline(1, [' xxx', 'yyyyy']) |
| 860 | call prop_add(2, 2, {'length': 2, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 861 | let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0} |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 862 | call assert_equal([expect], prop_list(2)) |
| 863 | |
| 864 | set shiftwidth=3 |
| 865 | normal 2G>> |
| 866 | call assert_equal(' yyyyy', getline(2)) |
| 867 | let expect.col += 3 |
| 868 | call assert_equal([expect], prop_list(2)) |
| 869 | |
| 870 | normal 2G== |
| 871 | call assert_equal(' yyyyy', getline(2)) |
| 872 | let expect.col = 6 |
| 873 | call assert_equal([expect], prop_list(2)) |
| 874 | |
| 875 | call prop_clear(2) |
| 876 | call prop_add(2, 2, {'length': 5, 'type': 'comment'}) |
| 877 | let expect.col = 2 |
| 878 | let expect.length = 5 |
| 879 | call assert_equal([expect], prop_list(2)) |
| 880 | |
| 881 | normal 2G<< |
| 882 | call assert_equal(' yyyyy', getline(2)) |
| 883 | let expect.length = 2 |
| 884 | call assert_equal([expect], prop_list(2)) |
| 885 | |
| 886 | set shiftwidth& |
| 887 | call prop_type_delete('comment') |
| 888 | endfunc |
| 889 | |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 890 | " Setup a three line prop in lines 2 - 4. |
| 891 | " Add short props in line 1 and 5. |
| 892 | func Setup_three_line_prop() |
| 893 | new |
| 894 | call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) |
| 895 | call prop_add(1, 2, {'length': 1, 'type': 'comment'}) |
| 896 | call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) |
| 897 | call prop_add(5, 2, {'length': 1, 'type': 'comment'}) |
| 898 | endfunc |
| 899 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 900 | func Test_prop_multiline() |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 901 | eval 'comment'->prop_type_add({'highlight': 'Directory'}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 902 | new |
| 903 | call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) |
| 904 | |
| 905 | " start halfway line 1, end halfway line 3 |
| 906 | call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 907 | let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0} |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 908 | call assert_equal([expect1], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 909 | let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0} |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 910 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 911 | let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0} |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 912 | call assert_equal([expect3], prop_list(3)) |
| 913 | call prop_clear(1, 3) |
| 914 | |
| 915 | " include all three lines |
| 916 | call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) |
| 917 | let expect1.col = 1 |
| 918 | let expect1.length = 8 |
| 919 | call assert_equal([expect1], prop_list(1)) |
| 920 | call assert_equal([expect2], prop_list(2)) |
| 921 | let expect3.length = 9 |
| 922 | call assert_equal([expect3], prop_list(3)) |
| 923 | call prop_clear(1, 3) |
| 924 | |
| 925 | bwipe! |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 926 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 927 | " Test deleting the first line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 928 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 929 | let expect_short = #{type_bufnr: 0, col: 2, length: 1, type: 'comment', start: 1, end: 1, id: 0} |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 930 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 931 | let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0} |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 932 | call assert_equal([expect2], prop_list(2)) |
| 933 | 2del |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 934 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 935 | let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0} |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 936 | call assert_equal([expect2], prop_list(2)) |
| 937 | bwipe! |
| 938 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 939 | " Test deleting the last line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 940 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 941 | let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0} |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 942 | call assert_equal([expect3], prop_list(3)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 943 | let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0} |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 944 | call assert_equal([expect4], prop_list(4)) |
| 945 | 4del |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 946 | let expect3.end = 1 |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 947 | call assert_equal([expect3], prop_list(3)) |
| 948 | call assert_equal([expect_short], prop_list(4)) |
| 949 | bwipe! |
| 950 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 951 | " Test appending a line below the multi-line text prop start. |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 952 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 953 | let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0} |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 954 | call assert_equal([expect2], prop_list(2)) |
| 955 | call append(2, "new line") |
| 956 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 957 | let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0} |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 958 | call assert_equal([expect3], prop_list(3)) |
| 959 | bwipe! |
| 960 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 961 | call prop_type_delete('comment') |
| 962 | endfunc |
| 963 | |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 964 | func Run_test_with_line2byte(add_props) |
| 965 | new |
| 966 | setlocal ff=unix |
| 967 | if a:add_props |
| 968 | call prop_type_add('textprop', #{highlight: 'Search'}) |
| 969 | endif |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 970 | " Add a text prop to every fourth line and then change every fifth line so |
| 971 | " that it causes a data block split a few times. |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 972 | for nr in range(1, 1000) |
| 973 | call setline(nr, 'some longer text here') |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 974 | if a:add_props && nr % 4 == 0 |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 975 | call prop_add(nr, 13, #{type: 'textprop', length: 4}) |
| 976 | endif |
| 977 | endfor |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 978 | let expected = 22 * 997 + 1 |
| 979 | call assert_equal(expected, line2byte(998)) |
| 980 | |
| 981 | for nr in range(1, 1000, 5) |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 982 | exe nr .. "s/longer/much more/" |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 983 | let expected += 3 |
| 984 | call assert_equal(expected, line2byte(998), 'line ' .. nr) |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 985 | endfor |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 986 | |
| 987 | if a:add_props |
| 988 | call prop_type_delete('textprop') |
| 989 | endif |
| 990 | bwipe! |
| 991 | endfunc |
| 992 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 993 | func Test_prop_line2byte() |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 994 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 995 | new |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 996 | call setline(1, ['line1', 'second line', '']) |
Bram Moolenaar | 8cf734e | 2018-12-26 01:09:00 +0100 | [diff] [blame] | 997 | set ff=unix |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 998 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 999 | call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 1000 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 1001 | bwipe! |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 1002 | |
| 1003 | new |
Bram Moolenaar | a401bba | 2021-08-15 15:04:41 +0200 | [diff] [blame] | 1004 | setlocal ff=unix |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 1005 | call setline(1, range(500)) |
| 1006 | call assert_equal(1491, line2byte(401)) |
| 1007 | call prop_add(2, 1, {'type': 'comment'}) |
| 1008 | call prop_add(222, 1, {'type': 'comment'}) |
| 1009 | call assert_equal(1491, line2byte(401)) |
| 1010 | call prop_remove({'type': 'comment'}) |
| 1011 | call assert_equal(1491, line2byte(401)) |
| 1012 | bwipe! |
| 1013 | |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 1014 | new |
Bram Moolenaar | 49b9304 | 2021-08-25 17:02:00 +0200 | [diff] [blame] | 1015 | setlocal ff=unix |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 1016 | call setline(1, range(520)) |
| 1017 | call assert_equal(1491, line2byte(401)) |
| 1018 | call prop_add(2, 1, {'type': 'comment'}) |
| 1019 | call assert_equal(1491, line2byte(401)) |
| 1020 | 2delete |
| 1021 | call assert_equal(1489, line2byte(400)) |
| 1022 | bwipe! |
| 1023 | |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 1024 | " Add many lines so that the data block is split. |
| 1025 | " With and without props should give the same result. |
| 1026 | call Run_test_with_line2byte(0) |
| 1027 | call Run_test_with_line2byte(1) |
| 1028 | |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 1029 | call prop_type_delete('comment') |
| 1030 | endfunc |
| 1031 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 1032 | func Test_prop_byte2line() |
| 1033 | new |
| 1034 | set ff=unix |
| 1035 | call setline(1, ['one one', 'two two', 'three three', 'four four', 'five']) |
| 1036 | call assert_equal(4, byte2line(line2byte(4))) |
| 1037 | call assert_equal(5, byte2line(line2byte(5))) |
| 1038 | |
| 1039 | call prop_type_add('prop', {'highlight': 'Directory'}) |
| 1040 | call prop_add(3, 1, {'length': 5, 'type': 'prop'}) |
| 1041 | call assert_equal(4, byte2line(line2byte(4))) |
| 1042 | call assert_equal(5, byte2line(line2byte(5))) |
| 1043 | |
| 1044 | bwipe! |
| 1045 | call prop_type_delete('prop') |
| 1046 | endfunc |
| 1047 | |
Bram Moolenaar | 59ff640 | 2021-01-30 17:16:28 +0100 | [diff] [blame] | 1048 | func Test_prop_goto_byte() |
| 1049 | new |
| 1050 | call setline(1, '') |
| 1051 | call setline(2, 'two three') |
| 1052 | call setline(3, '') |
| 1053 | call setline(4, 'four five') |
| 1054 | |
| 1055 | call prop_type_add('testprop', {'highlight': 'Directory'}) |
| 1056 | call search('^two') |
| 1057 | call prop_add(line('.'), col('.'), { |
| 1058 | \ 'length': len('two'), |
| 1059 | \ 'type': 'testprop' |
| 1060 | \ }) |
| 1061 | |
| 1062 | call search('two \zsthree') |
| 1063 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 1064 | exe expected_pos .. 'goto' |
| 1065 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 1066 | eval actual_pos->assert_equal(expected_pos) |
| 1067 | |
| 1068 | call search('four \zsfive') |
| 1069 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 1070 | exe expected_pos .. 'goto' |
| 1071 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 1072 | eval actual_pos->assert_equal(expected_pos) |
| 1073 | |
| 1074 | call prop_type_delete('testprop') |
| 1075 | bwipe! |
| 1076 | endfunc |
| 1077 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1078 | func Test_prop_undo() |
| 1079 | new |
| 1080 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 1081 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 1082 | " Set 'undolevels' to break changes into undo-able pieces. |
| 1083 | set ul& |
| 1084 | |
| 1085 | call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1086 | let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}] |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1087 | call assert_equal(expected, prop_list(1)) |
| 1088 | |
| 1089 | " Insert a character, then undo. |
| 1090 | exe "normal 0lllix\<Esc>" |
| 1091 | set ul& |
| 1092 | let expected[0].length = 3 |
| 1093 | call assert_equal(expected, prop_list(1)) |
| 1094 | undo |
| 1095 | let expected[0].length = 2 |
| 1096 | call assert_equal(expected, prop_list(1)) |
| 1097 | |
| 1098 | " Delete a character, then undo |
| 1099 | exe "normal 0lllx" |
| 1100 | set ul& |
| 1101 | let expected[0].length = 1 |
| 1102 | call assert_equal(expected, prop_list(1)) |
| 1103 | undo |
| 1104 | let expected[0].length = 2 |
| 1105 | call assert_equal(expected, prop_list(1)) |
| 1106 | |
| 1107 | " Delete the line, then undo |
| 1108 | 1d |
| 1109 | set ul& |
| 1110 | call assert_equal([], prop_list(1)) |
| 1111 | undo |
| 1112 | call assert_equal(expected, prop_list(1)) |
| 1113 | |
| 1114 | " Insert a character, delete two characters, then undo with "U" |
| 1115 | exe "normal 0lllix\<Esc>" |
| 1116 | set ul& |
| 1117 | let expected[0].length = 3 |
| 1118 | call assert_equal(expected, prop_list(1)) |
| 1119 | exe "normal 0lllxx" |
| 1120 | set ul& |
| 1121 | let expected[0].length = 1 |
| 1122 | call assert_equal(expected, prop_list(1)) |
| 1123 | normal U |
| 1124 | let expected[0].length = 2 |
| 1125 | call assert_equal(expected, prop_list(1)) |
| 1126 | |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1127 | " substitute a word, then undo |
| 1128 | call setline(1, 'the number 123 is highlighted.') |
| 1129 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1130 | let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1131 | call assert_equal(expected, prop_list(1)) |
| 1132 | set ul& |
| 1133 | 1s/number/foo |
| 1134 | let expected[0].col = 9 |
| 1135 | call assert_equal(expected, prop_list(1)) |
| 1136 | undo |
| 1137 | let expected[0].col = 12 |
| 1138 | call assert_equal(expected, prop_list(1)) |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 1139 | call prop_clear(1) |
| 1140 | |
| 1141 | " substitute with backslash |
| 1142 | call setline(1, 'the number 123 is highlighted.') |
| 1143 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1144 | let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 1145 | call assert_equal(expected, prop_list(1)) |
| 1146 | 1s/the/\The |
| 1147 | call assert_equal(expected, prop_list(1)) |
| 1148 | 1s/^/\\ |
| 1149 | let expected[0].col += 1 |
| 1150 | call assert_equal(expected, prop_list(1)) |
| 1151 | 1s/^/\~ |
| 1152 | let expected[0].col += 1 |
| 1153 | call assert_equal(expected, prop_list(1)) |
| 1154 | 1s/123/12\\3 |
| 1155 | let expected[0].length += 1 |
| 1156 | call assert_equal(expected, prop_list(1)) |
| 1157 | call prop_clear(1) |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1158 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1159 | bwipe! |
| 1160 | call prop_type_delete('comment') |
| 1161 | endfunc |
| 1162 | |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1163 | func Test_prop_delete_text() |
| 1164 | new |
| 1165 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 1166 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 1167 | |
| 1168 | " zero length property |
| 1169 | call prop_add(1, 3, {'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1170 | let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1171 | call assert_equal(expected, prop_list(1)) |
| 1172 | |
| 1173 | " delete one char moves the property |
| 1174 | normal! x |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1175 | let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1176 | call assert_equal(expected, prop_list(1)) |
| 1177 | |
| 1178 | " delete char of the property has no effect |
| 1179 | normal! lx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1180 | let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1181 | call assert_equal(expected, prop_list(1)) |
| 1182 | |
| 1183 | " delete more chars moves property to first column, is not deleted |
| 1184 | normal! 0xxxx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1185 | let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1186 | call assert_equal(expected, prop_list(1)) |
| 1187 | |
| 1188 | bwipe! |
| 1189 | call prop_type_delete('comment') |
| 1190 | endfunc |
| 1191 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1192 | " screenshot test with textprop highlighting |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1193 | func Test_textprop_screenshot_various() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1194 | CheckScreendump |
Bram Moolenaar | ed79d1e | 2019-02-22 14:38:58 +0100 | [diff] [blame] | 1195 | " The Vim running in the terminal needs to use utf-8. |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1196 | if g:orig_encoding != 'utf-8' |
| 1197 | throw 'Skipped: not using utf-8' |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1198 | endif |
| 1199 | call writefile([ |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1200 | \ "call setline(1, [" |
| 1201 | \ .. "'One two'," |
| 1202 | \ .. "'NumbΓ©r 123 Γ€nd thΕn 4ΒΎ7.'," |
| 1203 | \ .. "'--aa--bb--cc--dd--'," |
| 1204 | \ .. "'// comment with error in it'," |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1205 | \ .. "'first line'," |
| 1206 | \ .. "' second line '," |
| 1207 | \ .. "'third line'," |
| 1208 | \ .. "' fourth line'," |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1209 | \ .. "])", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1210 | \ "hi NumberProp ctermfg=blue", |
| 1211 | \ "hi LongProp ctermbg=yellow", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1212 | \ "hi BackgroundProp ctermbg=lightgrey", |
| 1213 | \ "hi UnderlineProp cterm=underline", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1214 | \ "call prop_type_add('number', {'highlight': 'NumberProp'})", |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 1215 | \ "call prop_type_add('long', {'highlight': 'NumberProp'})", |
| 1216 | \ "call prop_type_change('long', {'highlight': 'LongProp'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1217 | \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", |
| 1218 | \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", |
| 1219 | \ "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] | 1220 | \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})", |
| 1221 | \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})", |
| 1222 | \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})", |
Bram Moolenaar | 58e32ab | 2019-11-12 22:44:22 +0100 | [diff] [blame] | 1223 | \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1224 | \ "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] | 1225 | \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", |
| 1226 | \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1227 | \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", |
| 1228 | \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", |
| 1229 | \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", |
| 1230 | \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1231 | \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})", |
| 1232 | \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1233 | \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1234 | \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})", |
| 1235 | \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})", |
| 1236 | \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})", |
| 1237 | \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})", |
Bram Moolenaar | bfd4512 | 2019-05-17 13:05:07 +0200 | [diff] [blame] | 1238 | \ "set number cursorline", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 1239 | \ "hi clear SpellBad", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1240 | \ "set spell", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1241 | \ "syn match Comment '//.*'", |
| 1242 | \ "hi Comment ctermfg=green", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1243 | \ "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] | 1244 | \ "normal 3G0lli\<BS>\<Esc>", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1245 | \ "normal 6G0i\<BS>\<Esc>", |
| 1246 | \ "normal 3J", |
| 1247 | \ "normal 3G", |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1248 | \], 'XtestProp', 'D') |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1249 | let buf = RunVimInTerminal('-S XtestProp', {'rows': 8}) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1250 | call VerifyScreenDump(buf, 'Test_textprop_01', {}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 1251 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1252 | " clean up |
| 1253 | call StopVimInTerminal(buf) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1254 | endfunc |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1255 | |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1256 | func Test_textprop_hl_override() |
| 1257 | CheckScreendump |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 1258 | CheckRunVimInTerminal |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1259 | |
| 1260 | let lines =<< trim END |
| 1261 | call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three']) |
| 1262 | hi OverProp ctermfg=blue ctermbg=yellow |
| 1263 | hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green |
| 1264 | hi Vsual ctermfg=cyan ctermbg=grey |
| 1265 | call prop_type_add('under', #{highlight: 'OverProp'}) |
| 1266 | call prop_type_add('over', #{highlight: 'OverProp', override: 1}) |
| 1267 | call prop_add(1, 5, #{type: 'under', length: 4}) |
| 1268 | call prop_add(1, 13, #{type: 'over', length: 4}) |
| 1269 | call prop_add(2, 5, #{type: 'under', length: 4}) |
| 1270 | call prop_add(2, 13, #{type: 'over', length: 4}) |
| 1271 | call prop_add(3, 5, #{type: 'under', length: 4}) |
| 1272 | call prop_add(3, 13, #{type: 'over', length: 4}) |
| 1273 | set cursorline |
| 1274 | 2 |
| 1275 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1276 | call writefile(lines, 'XtestOverProp', 'D') |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1277 | let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8}) |
| 1278 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {}) |
| 1279 | |
| 1280 | call term_sendkeys(buf, "3Gllv$hh") |
| 1281 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {}) |
| 1282 | call term_sendkeys(buf, "\<Esc>") |
| 1283 | |
| 1284 | " clean up |
| 1285 | call StopVimInTerminal(buf) |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1286 | endfunc |
| 1287 | |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1288 | func RunTestVisualBlock(width, dump) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 1289 | CheckScreendump |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1290 | call writefile([ |
| 1291 | \ "call setline(1, [" |
| 1292 | \ .. "'xxxxxxxxx 123 x'," |
| 1293 | \ .. "'xxxxxxxx 123 x'," |
| 1294 | \ .. "'xxxxxxx 123 x'," |
| 1295 | \ .. "'xxxxxx 123 x'," |
| 1296 | \ .. "'xxxxx 123 x'," |
| 1297 | \ .. "'xxxx 123 xx'," |
| 1298 | \ .. "'xxx 123 xxx'," |
| 1299 | \ .. "'xx 123 xxxx'," |
| 1300 | \ .. "'x 123 xxxxx'," |
| 1301 | \ .. "' 123 xxxxxx'," |
| 1302 | \ .. "])", |
| 1303 | \ "hi SearchProp ctermbg=yellow", |
| 1304 | \ "call prop_type_add('search', {'highlight': 'SearchProp'})", |
| 1305 | \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", |
| 1306 | \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", |
| 1307 | \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", |
| 1308 | \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", |
| 1309 | \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", |
| 1310 | \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", |
| 1311 | \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", |
| 1312 | \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", |
| 1313 | \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", |
| 1314 | \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", |
| 1315 | \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1316 | \], 'XtestPropVis', 'D') |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1317 | let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) |
| 1318 | call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) |
| 1319 | |
| 1320 | " clean up |
| 1321 | call StopVimInTerminal(buf) |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1322 | endfunc |
| 1323 | |
| 1324 | " screenshot test with Visual block mode operations |
| 1325 | func Test_textprop_screenshot_visual() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1326 | CheckScreendump |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1327 | |
| 1328 | " Delete two columns while text props are three chars wide. |
| 1329 | call RunTestVisualBlock(2, '01') |
| 1330 | |
| 1331 | " Same, but delete four columns |
| 1332 | call RunTestVisualBlock(4, '02') |
| 1333 | endfunc |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1334 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1335 | func Test_textprop_after_tab() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1336 | CheckScreendump |
Bram Moolenaar | 37e66cf | 2019-06-19 18:16:10 +0200 | [diff] [blame] | 1337 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1338 | let lines =<< trim END |
| 1339 | call setline(1, [ |
| 1340 | \ "\txxx", |
| 1341 | \ "x\txxx", |
| 1342 | \ ]) |
| 1343 | hi SearchProp ctermbg=yellow |
| 1344 | call prop_type_add('search', {'highlight': 'SearchProp'}) |
| 1345 | call prop_add(1, 2, {'length': 3, 'type': 'search'}) |
| 1346 | call prop_add(2, 3, {'length': 3, 'type': 'search'}) |
| 1347 | END |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 1348 | call writefile(lines, 'XtextPropTab', 'D') |
| 1349 | let buf = RunVimInTerminal('-S XtextPropTab', {'rows': 6}) |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1350 | call VerifyScreenDump(buf, 'Test_textprop_tab', {}) |
| 1351 | |
| 1352 | " clean up |
| 1353 | call StopVimInTerminal(buf) |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1354 | endfunc |
| 1355 | |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 1356 | func Test_textprop_nesting() |
| 1357 | CheckScreendump |
| 1358 | |
| 1359 | let lines =<< trim END |
| 1360 | vim9script |
| 1361 | var lines =<< trim LINESEND |
| 1362 | |
| 1363 | const func: func.IFunction = ({ |
| 1364 | setLoading |
| 1365 | }) => { |
| 1366 | LINESEND |
| 1367 | setline(1, lines) |
| 1368 | prop_type_add('prop_add_test', {highlight: "ErrorMsg"}) |
| 1369 | prop_add(2, 31, {type: 'prop_add_test', end_lnum: 4, end_col: 2}) |
| 1370 | var text = 'text long enough to wrap line, text long enough to wrap line, text long enough to wrap line...' |
| 1371 | prop_add(2, 0, {type: 'prop_add_test', text_wrap: 'truncate', text_align: 'after', text: text}) |
| 1372 | END |
| 1373 | call writefile(lines, 'XtextpropNesting', 'D') |
| 1374 | let buf = RunVimInTerminal('-S XtextpropNesting', {'rows': 8}) |
| 1375 | call VerifyScreenDump(buf, 'Test_textprop_nesting', {}) |
| 1376 | |
| 1377 | " clean up |
| 1378 | call StopVimInTerminal(buf) |
| 1379 | endfunc |
| 1380 | |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1381 | func Test_textprop_nowrap_scrolled() |
| 1382 | CheckScreendump |
| 1383 | |
| 1384 | let lines =<< trim END |
| 1385 | vim9script |
| 1386 | set nowrap |
| 1387 | setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns)) |
| 1388 | prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1389 | prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1390 | prop_add(1, 32, {'length': 4, 'type': 'number'}) |
| 1391 | feedkeys('gg20zl', 'nxt') |
| 1392 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1393 | call writefile(lines, 'XtestNowrap', 'D') |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1394 | let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6}) |
| 1395 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {}) |
| 1396 | |
| 1397 | call term_sendkeys(buf, "$") |
| 1398 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {}) |
| 1399 | |
| 1400 | " clean up |
| 1401 | call StopVimInTerminal(buf) |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1402 | endfunc |
| 1403 | |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1404 | func Test_textprop_text_priority() |
| 1405 | CheckScreendump |
| 1406 | |
| 1407 | let lines =<< trim END |
| 1408 | call setline(1, "function( call, argument, here )") |
| 1409 | |
| 1410 | call prop_type_add('one', #{highlight: 'Error'}) |
| 1411 | call prop_type_add('two', #{highlight: 'Function'}) |
| 1412 | call prop_type_add('three', #{highlight: 'DiffChange'}) |
| 1413 | call prop_type_add('arg', #{highlight: 'Search'}) |
| 1414 | |
| 1415 | call prop_add(1, 27, #{type: 'arg', length: len('here')}) |
| 1416 | call prop_add(1, 27, #{type: 'three', text: 'three: '}) |
| 1417 | call prop_add(1, 11, #{type: 'one', text: 'one: '}) |
| 1418 | call prop_add(1, 11, #{type: 'arg', length: len('call')}) |
| 1419 | call prop_add(1, 17, #{type: 'two', text: 'two: '}) |
| 1420 | call prop_add(1, 17, #{type: 'arg', length: len('argument')}) |
| 1421 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1422 | call writefile(lines, 'XtestPropPrio', 'D') |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1423 | let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5}) |
| 1424 | call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {}) |
| 1425 | |
| 1426 | " clean up |
| 1427 | call StopVimInTerminal(buf) |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1428 | endfunc |
| 1429 | |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 1430 | func Test_textprop_in_empty_popup() |
| 1431 | CheckScreendump |
| 1432 | |
| 1433 | let lines =<< trim END |
| 1434 | vim9script |
| 1435 | |
| 1436 | hi def link FilterMenuMatch Constant |
| 1437 | prop_type_add('FilterMenuMatch', { |
| 1438 | highlight: "FilterMenuMatch", |
| 1439 | override: true, |
| 1440 | priority: 1000, |
| 1441 | combine: true, |
| 1442 | }) |
| 1443 | |
| 1444 | var winid = popup_create([{text: "hello", props: [ |
| 1445 | {col: 1, length: 1, type: 'FilterMenuMatch'}, |
| 1446 | {col: 2, length: 1, type: 'FilterMenuMatch'}, |
| 1447 | ]}], { |
| 1448 | minwidth: 20, |
| 1449 | minheight: 10, |
| 1450 | cursorline: false, |
| 1451 | highlight: "None", |
| 1452 | border: [], |
| 1453 | }) |
| 1454 | |
| 1455 | win_execute(winid, "setl nu cursorline cursorlineopt=both") |
| 1456 | popup_settext(winid, []) |
| 1457 | redraw |
| 1458 | END |
| 1459 | call writefile(lines, 'XtestPropEmptyPopup', 'D') |
| 1460 | let buf = RunVimInTerminal('-S XtestPropEmptyPopup', #{rows: 20, cols: 40}) |
| 1461 | call VerifyScreenDump(buf, 'Test_prop_in_empty_popup', {}) |
| 1462 | |
| 1463 | " clean up |
| 1464 | call StopVimInTerminal(buf) |
| 1465 | endfunc |
| 1466 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1467 | func Test_textprop_with_syntax() |
| 1468 | CheckScreendump |
| 1469 | |
| 1470 | let lines =<< trim END |
| 1471 | call setline(1, [ |
| 1472 | \ "(abc)", |
| 1473 | \ ]) |
| 1474 | syn match csParens "[()]" display |
| 1475 | hi! link csParens MatchParen |
| 1476 | |
| 1477 | call prop_type_add('TPTitle', #{ highlight: 'Title' }) |
| 1478 | call prop_add(1, 2, #{type: 'TPTitle', end_col: 5}) |
| 1479 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1480 | call writefile(lines, 'XtestPropSyn', 'D') |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1481 | let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6}) |
| 1482 | call VerifyScreenDump(buf, 'Test_textprop_syn_1', {}) |
| 1483 | |
| 1484 | " clean up |
| 1485 | call StopVimInTerminal(buf) |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1486 | endfunc |
| 1487 | |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1488 | " Adding a text property to a new buffer should not fail |
| 1489 | func Test_textprop_empty_buffer() |
| 1490 | call prop_type_add('comment', {'highlight': 'Search'}) |
| 1491 | new |
| 1492 | call prop_add(1, 1, {'type': 'comment'}) |
| 1493 | close |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1494 | call prop_type_delete('comment') |
| 1495 | endfunc |
| 1496 | |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 1497 | " Adding a text property with invalid highlight should be ignored. |
| 1498 | func Test_textprop_invalid_highlight() |
| 1499 | call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:') |
| 1500 | new |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 1501 | call setline(1, ['asdf', 'asdf']) |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 1502 | call prop_add(1, 1, {'length': 4, 'type': 'dni'}) |
| 1503 | redraw |
| 1504 | bwipe! |
| 1505 | call prop_type_delete('dni') |
| 1506 | endfunc |
| 1507 | |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1508 | " Adding a text property to an empty buffer and then editing another |
| 1509 | func Test_textprop_empty_buffer_next() |
| 1510 | call prop_type_add("xxx", {}) |
| 1511 | call prop_add(1, 1, {"type": "xxx"}) |
| 1512 | next X |
| 1513 | call prop_type_delete('xxx') |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1514 | endfunc |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 1515 | |
| 1516 | func Test_textprop_remove_from_buf() |
| 1517 | new |
| 1518 | let buf = bufnr('') |
| 1519 | call prop_type_add('one', {'bufnr': buf}) |
| 1520 | call prop_add(1, 1, {'type': 'one', 'id': 234}) |
| 1521 | file x |
| 1522 | edit y |
| 1523 | call prop_remove({'id': 234, 'bufnr': buf}, 1) |
| 1524 | call prop_type_delete('one', {'bufnr': buf}) |
| 1525 | bwipe! x |
| 1526 | close |
| 1527 | endfunc |
Bram Moolenaar | 45311b5 | 2019-08-13 22:27:32 +0200 | [diff] [blame] | 1528 | |
| 1529 | func Test_textprop_in_unloaded_buf() |
| 1530 | edit Xaaa |
| 1531 | call setline(1, 'aaa') |
| 1532 | write |
| 1533 | edit Xbbb |
| 1534 | call setline(1, 'bbb') |
| 1535 | write |
| 1536 | let bnr = bufnr('') |
| 1537 | edit Xaaa |
| 1538 | |
| 1539 | call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'}) |
| 1540 | call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:') |
| 1541 | exe 'buf ' .. bnr |
| 1542 | call assert_equal('bbb', getline(1)) |
| 1543 | call assert_equal(0, prop_list(1)->len()) |
| 1544 | |
| 1545 | bwipe! Xaaa |
| 1546 | bwipe! Xbbb |
| 1547 | cal delete('Xaaa') |
| 1548 | cal delete('Xbbb') |
| 1549 | endfunc |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1550 | |
| 1551 | func Test_proptype_substitute2() |
| 1552 | new |
| 1553 | " text_prop.vim |
| 1554 | call setline(1, [ |
| 1555 | \ 'The num 123 is smaller than 4567.', |
| 1556 | \ '123 The number 123 is smaller than 4567.', |
| 1557 | \ '123 The number 123 is smaller than 4567.']) |
| 1558 | |
| 1559 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1560 | |
| 1561 | call prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1562 | call prop_add(2, 1, {'length': 3, 'type': 'number'}) |
| 1563 | call prop_add(3, 36, {'length': 4, 'type': 'number'}) |
| 1564 | set ul& |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1565 | let expected = [ |
| 1566 | \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1}, |
| 1567 | \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1}, |
| 1568 | \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}] |
| 1569 | |
| 1570 | " TODO |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1571 | if 0 |
| 1572 | " Add some text in between |
| 1573 | %s/\s\+/ /g |
| 1574 | call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1575 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1576 | " remove some text |
| 1577 | :1s/[a-z]\{3\}//g |
| 1578 | let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] |
| 1579 | call assert_equal(expected, prop_list(1)) |
| 1580 | endif |
| 1581 | |
| 1582 | call prop_type_delete('number') |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1583 | bwipe! |
| 1584 | endfunc |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1585 | |
Bram Moolenaar | 8902b31 | 2020-09-20 21:04:35 +0200 | [diff] [blame] | 1586 | " This was causing property corruption. |
| 1587 | func Test_proptype_substitute3() |
| 1588 | new |
| 1589 | call setline(1, ['abcxxx', 'def']) |
| 1590 | call prop_type_add("test", {"highlight": "Search"}) |
| 1591 | call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"}) |
| 1592 | %s/x\+$// |
| 1593 | redraw |
| 1594 | |
| 1595 | call prop_type_delete('test') |
| 1596 | bwipe! |
| 1597 | endfunc |
| 1598 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1599 | func Test_proptype_substitute_join() |
| 1600 | new |
| 1601 | call setline(1, [ |
| 1602 | \ 'This is some end', |
| 1603 | \ 'start is highlighted end', |
| 1604 | \ 'some is highlighted', |
| 1605 | \ 'start is also highlighted']) |
| 1606 | |
| 1607 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1608 | |
| 1609 | call prop_add(1, 6, {'length': 2, 'type': 'number'}) |
| 1610 | call prop_add(2, 7, {'length': 2, 'type': 'number'}) |
| 1611 | call prop_add(3, 6, {'length': 2, 'type': 'number'}) |
| 1612 | call prop_add(4, 7, {'length': 2, 'type': 'number'}) |
Dominique Pelle | b49dfd0 | 2023-04-14 21:54:25 +0100 | [diff] [blame] | 1613 | " The highlighted "is" in line 1, 2 and 4 is kept and adjusted. |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1614 | " The highlighted "is" in line 3 is deleted. |
| 1615 | let expected = [ |
| 1616 | \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1}, |
| 1617 | \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1}, |
| 1618 | \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}] |
| 1619 | |
| 1620 | s/end\nstart/joined/ |
| 1621 | s/end\n.*\nstart/joined/ |
| 1622 | call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1)) |
| 1623 | call assert_equal(expected, prop_list(1)) |
| 1624 | |
| 1625 | call prop_type_delete('number') |
| 1626 | bwipe! |
| 1627 | endfunc |
| 1628 | |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1629 | func SaveOptions() |
| 1630 | let d = #{tabstop: &tabstop, |
| 1631 | \ softtabstop: &softtabstop, |
| 1632 | \ shiftwidth: &shiftwidth, |
| 1633 | \ expandtab: &expandtab, |
| 1634 | \ foldmethod: '"' .. &foldmethod .. '"', |
| 1635 | \ } |
| 1636 | return d |
| 1637 | endfunc |
| 1638 | |
| 1639 | func RestoreOptions(dict) |
| 1640 | for name in keys(a:dict) |
| 1641 | exe 'let &' .. name .. ' = ' .. a:dict[name] |
| 1642 | endfor |
| 1643 | endfunc |
| 1644 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1645 | func Test_textprop_noexpandtab() |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1646 | new |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1647 | let save_dict = SaveOptions() |
| 1648 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1649 | set tabstop=8 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1650 | set softtabstop=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1651 | set shiftwidth=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1652 | set noexpandtab |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1653 | set foldmethod=marker |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1654 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1655 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx") |
| 1656 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1657 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1658 | call feedkeys("0i\<tab>", "tx") |
| 1659 | call prop_remove({'type': 'test'}) |
| 1660 | call prop_add(1, 2, {'end_col': 3, 'type': 'test'}) |
| 1661 | call feedkeys("A\<left>\<tab>", "tx") |
| 1662 | call prop_remove({'type': 'test'}) |
| 1663 | try |
| 1664 | " It is correct that this does not pass |
| 1665 | call prop_add(1, 6, {'end_col': 7, 'type': 'test'}) |
| 1666 | " Has already collapsed here, start_col:6 does not result in an error |
| 1667 | call feedkeys("A\<left>\<tab>", "tx") |
| 1668 | catch /^Vim\%((\a\+)\)\=:E964/ |
| 1669 | endtry |
| 1670 | call prop_remove({'type': 'test'}) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1671 | call prop_type_delete('test') |
| 1672 | |
| 1673 | call RestoreOptions(save_dict) |
| 1674 | bwipe! |
| 1675 | endfunc |
| 1676 | |
| 1677 | func Test_textprop_noexpandtab_redraw() |
| 1678 | new |
| 1679 | let save_dict = SaveOptions() |
| 1680 | |
| 1681 | set tabstop=8 |
| 1682 | set softtabstop=4 |
| 1683 | set shiftwidth=4 |
| 1684 | set noexpandtab |
| 1685 | set foldmethod=marker |
| 1686 | |
| 1687 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx") |
| 1688 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1689 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1690 | call feedkeys("0i\<tab>", "tx") |
| 1691 | " Internally broken at the next line |
| 1692 | call feedkeys("A\<left>\<tab>", "tx") |
| 1693 | redraw |
| 1694 | " Index calculation failed internally on next line |
| 1695 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1696 | call prop_remove({'type': 'test', 'all': v:true}) |
| 1697 | call prop_type_delete('test') |
| 1698 | call prop_type_delete('test') |
| 1699 | |
| 1700 | call RestoreOptions(save_dict) |
| 1701 | bwipe! |
| 1702 | endfunc |
| 1703 | |
| 1704 | func Test_textprop_ins_str() |
| 1705 | new |
| 1706 | call setline(1, 'just some text') |
| 1707 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1708 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1709 | call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1)) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1710 | |
| 1711 | call feedkeys("foi\<F8>\<Esc>", "tx") |
| 1712 | call assert_equal('just s<F8>ome text', getline(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1713 | call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1)) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1714 | |
| 1715 | bwipe! |
| 1716 | call prop_remove({'type': 'test'}) |
| 1717 | call prop_type_delete('test') |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1718 | endfunc |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1719 | |
| 1720 | func Test_find_prop_later_in_line() |
| 1721 | new |
| 1722 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1723 | call setline(1, 'just some text') |
| 1724 | call prop_add(1, 1, {'length': 4, 'type': 'test'}) |
| 1725 | call prop_add(1, 10, {'length': 3, 'type': 'test'}) |
| 1726 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1727 | call assert_equal( |
| 1728 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1}, |
| 1729 | \ prop_find(#{type: 'test', lnum: 1, col: 6})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1730 | |
| 1731 | bwipe! |
| 1732 | call prop_type_delete('test') |
| 1733 | endfunc |
| 1734 | |
| 1735 | func Test_find_zerowidth_prop_sol() |
| 1736 | new |
| 1737 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1738 | call setline(1, 'just some text') |
| 1739 | call prop_add(1, 1, {'length': 0, 'type': 'test'}) |
| 1740 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1741 | call assert_equal( |
| 1742 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1}, |
| 1743 | \ prop_find(#{type: 'test', lnum: 1})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1744 | |
| 1745 | bwipe! |
| 1746 | call prop_type_delete('test') |
| 1747 | endfunc |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1748 | |
| 1749 | " Test for passing invalid arguments to prop_xxx() functions |
| 1750 | func Test_prop_func_invalid_args() |
| 1751 | call assert_fails('call prop_clear(1, 2, [])', 'E715:') |
| 1752 | call assert_fails('call prop_clear(-1, 2)', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1753 | call assert_fails('call prop_find(test_null_dict())', 'E1297:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1754 | call assert_fails('call prop_find({"bufnr" : []})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1755 | call assert_fails('call prop_find({})', 'E968:') |
| 1756 | call assert_fails('call prop_find({}, "x")', 'E474:') |
| 1757 | call assert_fails('call prop_find({"lnum" : -2})', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1758 | call assert_fails('call prop_list(1, [])', 'E1206:') |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 1759 | call assert_fails('call prop_list(-1, {})', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1760 | call assert_fails('call prop_remove([])', 'E1206:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1761 | call assert_fails('call prop_remove({}, -2)', 'E16:') |
| 1762 | call assert_fails('call prop_remove({})', 'E968:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1763 | call assert_fails('call prop_type_add([], {})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1764 | call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1765 | call assert_fails("call prop_type_delete([])", 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1766 | call assert_fails("call prop_type_delete('xyz', [])", 'E715:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1767 | call assert_fails("call prop_type_get([])", 'E730:') |
Bram Moolenaar | 89469d1 | 2022-12-02 20:46:26 +0000 | [diff] [blame] | 1768 | call assert_fails("call prop_type_get('', [])", 'E475:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1769 | call assert_fails("call prop_type_list([])", 'E715:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1770 | call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:') |
| 1771 | call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:') |
| 1772 | call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1773 | call assert_fails('call prop_add(1, 1, 0)', 'E1206:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1774 | |
| 1775 | new |
| 1776 | call setline(1, ['first', 'second']) |
| 1777 | call prop_type_add('xxx', {}) |
| 1778 | |
| 1779 | call assert_fails("call prop_type_add('xxx', {})", 'E969:') |
| 1780 | call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:') |
| 1781 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:') |
| 1782 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:') |
| 1783 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:') |
| 1784 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:') |
| 1785 | call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:') |
Christian Brabandt | 701c863 | 2024-09-08 20:05:23 +0200 | [diff] [blame] | 1786 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': 2147483648})", 'E1510:') |
| 1787 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'id': -2147483648})", 'E1510:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1788 | |
| 1789 | call prop_type_delete('xxx') |
| 1790 | bwipe! |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1791 | endfunc |
| 1792 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1793 | func Test_prop_split_join() |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1794 | new |
| 1795 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1796 | call setline(1, 'just some text') |
| 1797 | call prop_add(1, 6, {'length': 4, 'type': 'test'}) |
| 1798 | |
| 1799 | " Split in middle of "some" |
| 1800 | execute "normal! 8|i\<CR>" |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1801 | call assert_equal( |
| 1802 | \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}], |
| 1803 | \ prop_list(1)) |
| 1804 | call assert_equal( |
| 1805 | \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}], |
| 1806 | \ prop_list(2)) |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1807 | |
| 1808 | " Join the two lines back together |
| 1809 | normal! 1GJ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1810 | call assert_equal([#{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'test', length: 5, start: 1}], prop_list(1)) |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1811 | |
| 1812 | bwipe! |
| 1813 | call prop_type_delete('test') |
| 1814 | endfunc |
| 1815 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1816 | func Test_prop_increment_decrement() |
| 1817 | new |
| 1818 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1819 | call setline(1, 'its 998 times') |
| 1820 | call prop_add(1, 5, {'length': 3, 'type': 'test'}) |
| 1821 | |
| 1822 | exe "normal! 0f9\<C-A>" |
| 1823 | eval getline(1)->assert_equal('its 999 times') |
| 1824 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1825 | \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}]) |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1826 | |
| 1827 | exe "normal! 0f9\<C-A>" |
| 1828 | eval getline(1)->assert_equal('its 1000 times') |
| 1829 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1830 | \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}]) |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1831 | |
| 1832 | bwipe! |
| 1833 | call prop_type_delete('test') |
| 1834 | endfunc |
| 1835 | |
Bram Moolenaar | 8b51b7f | 2020-09-15 21:34:18 +0200 | [diff] [blame] | 1836 | func Test_prop_block_insert() |
| 1837 | new |
| 1838 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1839 | call setline(1, ['one ', 'two ']) |
| 1840 | call prop_add(1, 1, {'length': 3, 'type': 'test'}) |
| 1841 | call prop_add(2, 1, {'length': 3, 'type': 'test'}) |
| 1842 | |
| 1843 | " insert "xx" in the first column of both lines |
| 1844 | exe "normal! gg0\<C-V>jIxx\<Esc>" |
| 1845 | eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1846 | let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}] |
Bram Moolenaar | 8b51b7f | 2020-09-15 21:34:18 +0200 | [diff] [blame] | 1847 | eval prop_list(1)->assert_equal(expected) |
| 1848 | eval prop_list(2)->assert_equal(expected) |
| 1849 | |
| 1850 | " insert "yy" inside the text props to make them longer |
| 1851 | exe "normal! gg03l\<C-V>jIyy\<Esc>" |
| 1852 | eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo ']) |
| 1853 | let expected[0].length = 5 |
| 1854 | eval prop_list(1)->assert_equal(expected) |
| 1855 | eval prop_list(2)->assert_equal(expected) |
| 1856 | |
| 1857 | " insert "zz" after the text props, text props don't change |
| 1858 | exe "normal! gg07l\<C-V>jIzz\<Esc>" |
| 1859 | eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz ']) |
| 1860 | eval prop_list(1)->assert_equal(expected) |
| 1861 | eval prop_list(2)->assert_equal(expected) |
| 1862 | |
| 1863 | bwipe! |
| 1864 | call prop_type_delete('test') |
| 1865 | endfunc |
| 1866 | |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 1867 | " this was causing an ml_get error because w_botline was wrong |
| 1868 | func Test_prop_one_line_window() |
| 1869 | enew |
| 1870 | call range(2)->setline(1) |
| 1871 | call prop_type_add('testprop', {}) |
| 1872 | call prop_add(1, 1, {'type': 'testprop'}) |
| 1873 | call popup_create('popup', {'textprop': 'testprop'}) |
| 1874 | $ |
| 1875 | new |
| 1876 | wincmd _ |
| 1877 | call feedkeys("\r", 'xt') |
| 1878 | redraw |
| 1879 | |
| 1880 | call popup_clear() |
| 1881 | call prop_type_delete('testprop') |
| 1882 | close |
| 1883 | bwipe! |
| 1884 | endfunc |
| 1885 | |
Bram Moolenaar | f05a1e5 | 2022-08-02 11:48:53 +0100 | [diff] [blame] | 1886 | def Test_prop_column_zero_error() |
| 1887 | prop_type_add('proptype', {highlight: 'Search'}) |
| 1888 | var caught = false |
| 1889 | try |
| 1890 | popup_create([{ |
| 1891 | text: 'a', |
| 1892 | props: [{col: 0, length: 1, type: 'type'}], |
| 1893 | }], {}) |
| 1894 | catch /E964:/ |
| 1895 | caught = true |
| 1896 | endtry |
| 1897 | assert_true(caught) |
| 1898 | |
| 1899 | popup_clear() |
| 1900 | prop_type_delete('proptype') |
| 1901 | enddef |
| 1902 | |
Bram Moolenaar | 840f91f | 2021-05-26 22:32:10 +0200 | [diff] [blame] | 1903 | " This was calling ml_append_int() and copy a text property from a previous |
| 1904 | " line at the wrong moment. Exact text length matters. |
| 1905 | def Test_prop_splits_data_block() |
| 1906 | new |
| 1907 | var lines: list<string> = [repeat('x', 35)]->repeat(41) |
| 1908 | + [repeat('!', 35)] |
| 1909 | + [repeat('x', 35)]->repeat(56) |
| 1910 | lines->setline(1) |
| 1911 | prop_type_add('someprop', {highlight: 'ErrorMsg'}) |
| 1912 | prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'}) |
| 1913 | prop_remove({type: 'someprop'}, 1) |
| 1914 | prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'}) |
| 1915 | prop_remove({type: 'someprop'}, 35, 43) |
| 1916 | assert_equal([], prop_list(42)) |
| 1917 | |
| 1918 | bwipe! |
| 1919 | prop_type_delete('someprop') |
| 1920 | enddef |
| 1921 | |
Bram Moolenaar | 4cd5c52 | 2021-06-27 13:04:00 +0200 | [diff] [blame] | 1922 | " This was calling ml_delete_int() and try to change text properties. |
| 1923 | def Test_prop_add_delete_line() |
| 1924 | new |
| 1925 | var a = 10 |
| 1926 | var b = 20 |
| 1927 | repeat([''], a)->append('$') |
| 1928 | prop_type_add('Test', {highlight: 'ErrorMsg'}) |
| 1929 | for lnum in range(1, a) |
| 1930 | for col in range(1, b) |
| 1931 | prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'}) |
| 1932 | endfor |
| 1933 | endfor |
| 1934 | |
| 1935 | # check deleting lines is OK |
| 1936 | :5del |
| 1937 | :1del |
| 1938 | :$del |
| 1939 | |
| 1940 | prop_type_delete('Test') |
| 1941 | bwipe! |
| 1942 | enddef |
| 1943 | |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1944 | " This test is to detect a regression related to #10430. It is not an attempt |
| 1945 | " fully cover deleting lines in the presence of multi-line properties. |
| 1946 | def Test_delete_line_within_multiline_prop() |
| 1947 | new |
| 1948 | setline(1, '# Top.') |
| 1949 | append(1, ['some_text = """', 'A string.', '"""', '# Bottom.']) |
| 1950 | prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1951 | prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1952 | prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9}) |
| 1953 | prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4}) |
| 1954 | |
| 1955 | # The property for line 3 should extend into the previous and next lines. |
| 1956 | var props = prop_list(3) |
| 1957 | var prop = props[0] |
| 1958 | assert_equal(1, len(props)) |
| 1959 | assert_equal(0, prop['start']) |
| 1960 | assert_equal(0, prop['end']) |
| 1961 | |
| 1962 | # This deletion should run without raising an exception. |
| 1963 | try |
| 1964 | :2 del |
| 1965 | catch |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1966 | assert_report('Line delete should have worked, but it raised an error.') |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1967 | endtry |
| 1968 | |
| 1969 | # The property for line 2 (was 3) should no longer extend into the previous |
| 1970 | # line. |
| 1971 | props = prop_list(2) |
| 1972 | prop = props[0] |
| 1973 | assert_equal(1, len(props)) |
| 1974 | assert_equal(1, prop['start'], 'Property was not changed to start within the line.') |
| 1975 | |
| 1976 | # This deletion should run without raising an exception. |
| 1977 | try |
| 1978 | :3 del |
| 1979 | catch |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1980 | assert_report('Line delete should have worked, but it raised an error.') |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1981 | endtry |
| 1982 | |
| 1983 | # The property for line 2 (originally 3) should no longer extend into the next |
| 1984 | # line. |
| 1985 | props = prop_list(2) |
| 1986 | prop = props[0] |
| 1987 | assert_equal(1, len(props)) |
| 1988 | assert_equal(1, prop['end'], 'Property was not changed to end within the line.') |
| 1989 | |
| 1990 | prop_type_delete('Identifier') |
| 1991 | prop_type_delete('String') |
| 1992 | bwip! |
| 1993 | enddef |
| 1994 | |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1995 | func Test_prop_in_linebreak() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 1996 | CheckScreendump |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1997 | CheckRunVimInTerminal |
| 1998 | |
| 1999 | let lines =<< trim END |
| 2000 | set breakindent linebreak breakat+=] |
| 2001 | call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2002 | call prop_type_add('test', #{highlight: 'MatchParen'}) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2003 | call prop_add(1, 51, #{length: 1, type: 'test'}) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2004 | func AddMatch() |
| 2005 | syntax on |
| 2006 | syntax match xTest /.*/ |
| 2007 | hi link xTest Comment |
| 2008 | set signcolumn=yes |
| 2009 | endfunc |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2010 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2011 | call writefile(lines, 'XscriptPropLinebreak', 'D') |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2012 | let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10}) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2013 | call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {}) |
| 2014 | |
| 2015 | call term_sendkeys(buf, ":call AddMatch()\<CR>") |
| 2016 | call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {}) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2017 | |
| 2018 | call StopVimInTerminal(buf) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2019 | endfunc |
| 2020 | |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 2021 | func Test_prop_with_linebreak() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2022 | CheckScreendump |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 2023 | CheckRunVimInTerminal |
| 2024 | |
| 2025 | let lines =<< trim END |
| 2026 | vim9script |
| 2027 | set linebreak |
| 2028 | setline(1, 'one twoword') |
| 2029 | prop_type_add('test', {highlight: 'Special'}) |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2030 | prop_add(1, 4, {text: ': virtual text', type: 'test'}) |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 2031 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2032 | call writefile(lines, 'XscriptPropWithLinebreak', 'D') |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 2033 | let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50}) |
| 2034 | call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {}) |
| 2035 | call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>") |
| 2036 | call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {}) |
| 2037 | |
| 2038 | call StopVimInTerminal(buf) |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 2039 | endfunc |
| 2040 | |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2041 | func Test_prop_with_wrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2042 | CheckScreendump |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2043 | CheckRunVimInTerminal |
| 2044 | |
| 2045 | let lines =<< trim END |
| 2046 | vim9script |
| 2047 | set linebreak |
| 2048 | setline(1, 'asdf '->repeat(15)) |
| 2049 | prop_type_add('test', {highlight: 'Special'}) |
| 2050 | prop_add(1, 43, {text: 'some virtual text', type: 'test'}) |
Bram Moolenaar | 1aeb3eb | 2023-01-01 14:04:51 +0000 | [diff] [blame] | 2051 | normal G$ |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2052 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2053 | call writefile(lines, 'XscriptPropWithWrap', 'D') |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2054 | let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50}) |
| 2055 | call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {}) |
| 2056 | |
| 2057 | call StopVimInTerminal(buf) |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2058 | endfunc |
| 2059 | |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2060 | func Test_prop_after_tab() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2061 | CheckScreendump |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2062 | CheckRunVimInTerminal |
| 2063 | |
| 2064 | let lines =<< trim END |
| 2065 | set breakindent linebreak breakat+=] |
| 2066 | call setline(1, "\t[xxx]") |
| 2067 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 2068 | call prop_add(1, 2, #{length: 1, type: 'test'}) |
| 2069 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2070 | call writefile(lines, 'XscriptPropAfterTab', 'D') |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2071 | let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10}) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2072 | call VerifyScreenDump(buf, 'Test_prop_after_tab', {}) |
| 2073 | |
| 2074 | call StopVimInTerminal(buf) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2075 | endfunc |
| 2076 | |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2077 | func Test_prop_before_tab() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2078 | CheckScreendump |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2079 | CheckRunVimInTerminal |
| 2080 | |
| 2081 | let lines =<< trim END |
| 2082 | call setline(1, ["\tx"]->repeat(6)) |
| 2083 | call prop_type_add('test', #{highlight: 'Search'}) |
| 2084 | call prop_add(1, 1, #{type: 'test', text: '123'}) |
| 2085 | call prop_add(2, 1, #{type: 'test', text: '1234567'}) |
| 2086 | call prop_add(3, 1, #{type: 'test', text: '12345678'}) |
| 2087 | call prop_add(4, 1, #{type: 'test', text: '123456789'}) |
| 2088 | call prop_add(5, 2, #{type: 'test', text: 'ABC'}) |
| 2089 | call prop_add(6, 3, #{type: 'test', text: 'ABC'}) |
| 2090 | normal gg0 |
| 2091 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2092 | call writefile(lines, 'XscriptPropBeforeTab', 'D') |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2093 | let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8}) |
| 2094 | call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {}) |
| 2095 | call term_sendkeys(buf, "$") |
| 2096 | call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {}) |
| 2097 | call term_sendkeys(buf, "j0") |
| 2098 | call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {}) |
| 2099 | call term_sendkeys(buf, "$") |
| 2100 | call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {}) |
| 2101 | call term_sendkeys(buf, "j0") |
| 2102 | call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {}) |
| 2103 | call term_sendkeys(buf, "$") |
| 2104 | call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {}) |
| 2105 | call term_sendkeys(buf, "j0") |
| 2106 | call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {}) |
| 2107 | call term_sendkeys(buf, "$") |
| 2108 | call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {}) |
| 2109 | call term_sendkeys(buf, "j") |
| 2110 | call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {}) |
| 2111 | call term_sendkeys(buf, "j") |
| 2112 | call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {}) |
| 2113 | |
| 2114 | call StopVimInTerminal(buf) |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2115 | endfunc |
| 2116 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2117 | func Test_prop_after_linebreak() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2118 | CheckScreendump |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2119 | CheckRunVimInTerminal |
| 2120 | |
| 2121 | let lines =<< trim END |
| 2122 | set linebreak wrap |
| 2123 | call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1) |
| 2124 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 2125 | call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'}) |
| 2126 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2127 | call writefile(lines, 'XscriptPropAfterLinebreak', 'D') |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2128 | let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10}) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2129 | call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {}) |
| 2130 | |
| 2131 | call StopVimInTerminal(buf) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2132 | endfunc |
| 2133 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 2134 | " Buffer number of 0 should be ignored, as if the parameter wasn't passed. |
| 2135 | def Test_prop_bufnr_zero() |
| 2136 | new |
| 2137 | try |
| 2138 | var bufnr = bufnr('') |
| 2139 | setline(1, 'hello') |
| 2140 | prop_type_add('bufnr-global', {highlight: 'ErrorMsg'}) |
| 2141 | prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr}) |
| 2142 | |
| 2143 | prop_add(1, 1, {type: 'bufnr-global', length: 1}) |
| 2144 | prop_add(1, 2, {type: 'bufnr-buffer', length: 1}) |
| 2145 | |
| 2146 | var list = prop_list(1) |
| 2147 | assert_equal([ |
| 2148 | {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1}, |
| 2149 | {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1}, |
| 2150 | ], list) |
| 2151 | |
| 2152 | assert_equal( |
| 2153 | {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1}, |
| 2154 | prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr})) |
| 2155 | |
| 2156 | assert_equal( |
| 2157 | {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1}, |
| 2158 | prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr})) |
| 2159 | finally |
| 2160 | bwipe! |
| 2161 | prop_type_delete('bufnr-global') |
| 2162 | endtry |
| 2163 | enddef |
| 2164 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2165 | " Tests for the prop_list() function |
| 2166 | func Test_prop_list() |
| 2167 | let lines =<< trim END |
| 2168 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2169 | call g:AddPropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2170 | call setline(1, repeat([repeat('a', 60)], 10)) |
| 2171 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2172 | call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7}) |
| 2173 | call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14}) |
| 2174 | call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15}) |
| 2175 | call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22}) |
| 2176 | call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23}) |
| 2177 | call assert_equal([ |
| 2178 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2179 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2180 | \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2181 | \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1)) |
| 2182 | #" text properties between a few lines |
| 2183 | call assert_equal([ |
| 2184 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2185 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2186 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2187 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2188 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 2189 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2190 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 2191 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2192 | \ prop_list(2, {'end_lnum': 5})) |
| 2193 | #" text properties across all the lines |
| 2194 | call assert_equal([ |
| 2195 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2196 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2197 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2198 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2199 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 2200 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2201 | \ prop_list(1, {'types': ['one'], 'end_lnum': -1})) |
| 2202 | #" text properties with the specified identifier |
| 2203 | call assert_equal([ |
| 2204 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2205 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2206 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 2207 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2208 | \ prop_list(1, {'ids': [20], 'end_lnum': 10})) |
| 2209 | #" text properties of the specified type and id |
| 2210 | call assert_equal([ |
| 2211 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2212 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2213 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2214 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2215 | \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20})) |
| 2216 | call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10})) |
| 2217 | call assert_equal([], prop_list(6, {'end_lnum': 10})) |
| 2218 | call assert_equal([], prop_list(2, {'end_lnum': 2})) |
| 2219 | #" error cases |
| 2220 | call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:') |
| 2221 | call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:') |
| 2222 | call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:') |
| 2223 | call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})", |
| 2224 | \ 'E971:') |
| 2225 | call assert_fails("echo prop_list(1, {'types': ['one', 'blue'], |
| 2226 | \ 'end_lnum': 10})", 'E971:') |
| 2227 | call assert_fails("echo prop_list(1, {'types': ['one', 10], |
| 2228 | \ 'end_lnum': 10})", 'E928:') |
| 2229 | call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:') |
| 2230 | call assert_equal([], prop_list(2, {'types': []})) |
| 2231 | call assert_equal([], prop_list(2, {'types': test_null_list()})) |
| 2232 | call assert_fails("call prop_list(1, {'types': {}})", 'E714:') |
| 2233 | call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:') |
| 2234 | call assert_equal([], prop_list(2, {'types': ['one'], |
| 2235 | \ 'ids': test_null_list()})) |
| 2236 | call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []})) |
| 2237 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})", |
| 2238 | \ 'E714:') |
| 2239 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})", |
| 2240 | \ 'E714:') |
| 2241 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})", |
| 2242 | \ 'E745:') |
| 2243 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})", |
| 2244 | \ 'E745:') |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 2245 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2246 | #" get text properties from a non-current buffer |
| 2247 | wincmd w |
| 2248 | call assert_equal([ |
| 2249 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2250 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2251 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2252 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2253 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2254 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2255 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2256 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2257 | \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4})) |
| 2258 | wincmd w |
| 2259 | |
| 2260 | #" get text properties after clearing all the properties |
| 2261 | call prop_clear(1, line('$')) |
| 2262 | call assert_equal([], prop_list(1, {'end_lnum': 10})) |
| 2263 | |
| 2264 | call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2265 | call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6}) |
| 2266 | call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6}) |
| 2267 | #" get text properties with a list of types |
| 2268 | call assert_equal([ |
| 2269 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2270 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2271 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2272 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2273 | \ prop_list(2, {'types': ['one', 'two']})) |
| 2274 | call assert_equal([ |
| 2275 | \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2276 | \ 'type': 'three', 'length': 2, 'start': 1}, |
| 2277 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2278 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2279 | \ prop_list(2, {'types': ['one', 'three']})) |
| 2280 | #" get text properties with a list of identifiers |
| 2281 | call assert_equal([ |
| 2282 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2283 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2284 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2285 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2286 | \ prop_list(2, {'ids': [5, 10, 20]})) |
| 2287 | call prop_clear(1, line('$')) |
| 2288 | call assert_equal([], prop_list(2, {'types': ['one', 'two']})) |
| 2289 | call assert_equal([], prop_list(2, {'ids': [5, 10, 20]})) |
| 2290 | |
| 2291 | #" get text properties from a hidden buffer |
| 2292 | edit! Xaaa |
| 2293 | call setline(1, repeat([repeat('b', 60)], 10)) |
| 2294 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2295 | call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10}) |
| 2296 | VAR bnr = bufnr() |
| 2297 | hide edit Xbbb |
| 2298 | call assert_equal([ |
| 2299 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2300 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2301 | \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1, |
| 2302 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2303 | \ prop_list(1, {'bufnr': bnr, |
| 2304 | \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1})) |
| 2305 | #" get text properties from an unloaded buffer |
| 2306 | bunload! Xaaa |
| 2307 | call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1})) |
| 2308 | |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2309 | call g:DeletePropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2310 | :%bw! |
| 2311 | END |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2312 | call v9.CheckLegacyAndVim9Success(lines) |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2313 | endfunc |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 2314 | |
LemonBoy | 9bd3ce2 | 2022-04-18 21:54:02 +0100 | [diff] [blame] | 2315 | func Test_prop_find_prev_on_same_line() |
| 2316 | new |
| 2317 | |
| 2318 | call setline(1, 'the quikc bronw fox jumsp over the layz dog') |
| 2319 | call prop_type_add('misspell', #{highlight: 'ErrorMsg'}) |
| 2320 | for col in [8, 14, 24, 38] |
| 2321 | call prop_add(1, col, #{type: 'misspell', length: 2}) |
| 2322 | endfor |
| 2323 | |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 2324 | call cursor(1, 18) |
LemonBoy | 9bd3ce2 | 2022-04-18 21:54:02 +0100 | [diff] [blame] | 2325 | let expected = [ |
| 2326 | \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}, |
| 2327 | \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1} |
| 2328 | \ ] |
| 2329 | |
| 2330 | let result = prop_find(#{type: 'misspell'}, 'b') |
| 2331 | call assert_equal(expected[0], result) |
| 2332 | let result = prop_find(#{type: 'misspell'}, 'f') |
| 2333 | call assert_equal(expected[1], result) |
| 2334 | |
| 2335 | call prop_type_delete('misspell') |
| 2336 | bwipe! |
| 2337 | endfunc |
| 2338 | |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2339 | func Test_prop_spell() |
| 2340 | new |
| 2341 | set spell |
| 2342 | call AddPropTypes() |
| 2343 | |
| 2344 | call setline(1, ["helo world", "helo helo helo"]) |
| 2345 | call prop_add(1, 1, #{type: 'one', length: 4}) |
| 2346 | call prop_add(1, 6, #{type: 'two', length: 5}) |
| 2347 | call prop_add(2, 1, #{type: 'three', length: 4}) |
| 2348 | call prop_add(2, 6, #{type: 'three', length: 4}) |
| 2349 | call prop_add(2, 11, #{type: 'three', length: 4}) |
| 2350 | |
| 2351 | " The first prop over 'helo' increases its length after the word is corrected |
| 2352 | " to 'Hello', the second one is shifted to the right. |
| 2353 | let expected = [ |
| 2354 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2355 | \ 'length': 5, 'start': 1}, |
| 2356 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2357 | \ 'length': 5, 'start': 1} |
| 2358 | \ ] |
| 2359 | call feedkeys("z=1\<CR>", 'xt') |
| 2360 | |
| 2361 | call assert_equal('Hello world', getline(1)) |
| 2362 | call assert_equal(expected, prop_list(1)) |
| 2363 | |
| 2364 | " Repeat the replacement done by z= |
| 2365 | spellrepall |
| 2366 | |
| 2367 | let expected = [ |
| 2368 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2369 | \ 'length': 5, 'start': 1}, |
| 2370 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2371 | \ 'length': 5, 'start': 1}, |
| 2372 | \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2373 | \ 'length': 5, 'start': 1} |
| 2374 | \ ] |
| 2375 | call assert_equal('Hello Hello Hello', getline(2)) |
| 2376 | call assert_equal(expected, prop_list(2)) |
| 2377 | |
| 2378 | call DeletePropTypes() |
| 2379 | set spell& |
| 2380 | bwipe! |
| 2381 | endfunc |
| 2382 | |
LemonBoy | 4b93674 | 2022-05-13 21:56:28 +0100 | [diff] [blame] | 2383 | func Test_prop_shift_block() |
| 2384 | new |
| 2385 | call AddPropTypes() |
| 2386 | |
| 2387 | call setline(1, ['some highlighted text']->repeat(2)) |
| 2388 | call prop_add(1, 10, #{type: 'one', length: 11}) |
| 2389 | call prop_add(2, 10, #{type: 'two', length: 11}) |
| 2390 | |
| 2391 | call cursor(1, 1) |
| 2392 | call feedkeys("5l\<c-v>>", 'nxt') |
| 2393 | call cursor(2, 1) |
| 2394 | call feedkeys("5l\<c-v><", 'nxt') |
| 2395 | |
| 2396 | let expected = [ |
| 2397 | \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2398 | \ 'length': 11, 'start' : 1}, |
| 2399 | \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2400 | \ 'length': 11, 'start' : 1} |
| 2401 | \ ] |
| 2402 | call assert_equal(expected, prop_list(1, #{end_lnum: 2})) |
| 2403 | |
| 2404 | call DeletePropTypes() |
| 2405 | bwipe! |
| 2406 | endfunc |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2407 | |
LemonBoy | 698cb4c | 2022-05-14 18:10:15 +0100 | [diff] [blame] | 2408 | func Test_prop_insert_multiline() |
| 2409 | new |
| 2410 | call AddPropTypes() |
| 2411 | |
| 2412 | call setline(1, ['foobar', 'barbaz']) |
| 2413 | call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'}) |
| 2414 | |
| 2415 | call feedkeys("1Goquxqux\<Esc>", 'nxt') |
| 2416 | call feedkeys("2GOquxqux\<Esc>", 'nxt') |
| 2417 | |
| 2418 | let lines =<< trim END |
| 2419 | foobar |
| 2420 | quxqux |
| 2421 | quxqux |
| 2422 | barbaz |
| 2423 | END |
| 2424 | call assert_equal(lines, getline(1, '$')) |
| 2425 | let expected = [ |
| 2426 | \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 2427 | \ 'length': 4 , 'start': 1}, |
LemonBoy | 698cb4c | 2022-05-14 18:10:15 +0100 | [diff] [blame] | 2428 | \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2429 | \ 'length': 7, 'start': 0}, |
| 2430 | \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2431 | \ 'length': 7, 'start': 0}, |
| 2432 | \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2433 | \ 'length': 3, 'start': 0} |
| 2434 | \ ] |
| 2435 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2436 | |
| 2437 | call DeletePropTypes() |
| 2438 | bwipe! |
| 2439 | endfunc |
| 2440 | |
LemonBoy | b559b30 | 2022-05-15 13:08:02 +0100 | [diff] [blame] | 2441 | func Test_prop_blockwise_change() |
| 2442 | new |
| 2443 | call AddPropTypes() |
| 2444 | |
| 2445 | call setline(1, ['foooooo', 'bar', 'baaaaz']) |
| 2446 | call prop_add(1, 1, #{end_col: 3, type: 'one'}) |
| 2447 | call prop_add(2, 1, #{end_col: 3, type: 'two'}) |
| 2448 | call prop_add(3, 1, #{end_col: 3, type: 'three'}) |
| 2449 | |
| 2450 | " Replace the first two columns with '123', since 'start_incl' is false the |
| 2451 | " prop is not extended. |
| 2452 | call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt') |
| 2453 | |
| 2454 | let lines =<< trim END |
| 2455 | 123oooooo |
| 2456 | 123ar |
| 2457 | 123aaaaz |
| 2458 | END |
| 2459 | call assert_equal(lines, getline(1, '$')) |
| 2460 | let expected = [ |
| 2461 | \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2462 | \ 'length': 1, 'start': 1}, |
| 2463 | \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2464 | \ 'length': 1, 'start': 1}, |
| 2465 | \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 , |
| 2466 | \ 'type': 'three', 'length': 1, 'start': 1} |
| 2467 | \ ] |
| 2468 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2469 | |
| 2470 | call DeletePropTypes() |
| 2471 | bwipe! |
| 2472 | endfunc |
| 2473 | |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2474 | func Do_test_props_do_not_affect_byte_offsets(ff, increment) |
| 2475 | new |
| 2476 | let lcount = 410 |
| 2477 | |
| 2478 | " File format affects byte-offset calculations, so make sure it is known. |
| 2479 | exec 'setlocal fileformat=' . a:ff |
| 2480 | |
| 2481 | " Fill the buffer with varying length lines. We need a suitably large number |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2482 | " to force Vim code through paths where previous error have occurred. This |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2483 | " is more 'art' than 'science'. |
| 2484 | let text = 'a' |
| 2485 | call setline(1, text) |
| 2486 | let offsets = [1] |
| 2487 | for idx in range(lcount) |
| 2488 | call add(offsets, offsets[idx] + len(text) + a:increment) |
| 2489 | if (idx % 6) == 0 |
| 2490 | let text = text . 'a' |
| 2491 | endif |
| 2492 | call append(line('$'), text) |
| 2493 | endfor |
| 2494 | |
| 2495 | " Set a property that spans a few lines to cause Vim's internal buffer code |
| 2496 | " to perform a reasonable amount of rearrangement. |
| 2497 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2498 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2}) |
| 2499 | |
| 2500 | for idx in range(lcount) |
| 2501 | let boff = line2byte(idx + 1) |
| 2502 | call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1)) |
| 2503 | endfor |
| 2504 | |
| 2505 | call prop_type_delete('one') |
| 2506 | bwipe! |
| 2507 | endfunc |
| 2508 | |
| 2509 | func Test_props_do_not_affect_byte_offsets() |
| 2510 | call Do_test_props_do_not_affect_byte_offsets('unix', 1) |
| 2511 | endfunc |
| 2512 | |
| 2513 | func Test_props_do_not_affect_byte_offsets_dos() |
| 2514 | call Do_test_props_do_not_affect_byte_offsets('dos', 2) |
| 2515 | endfunc |
| 2516 | |
| 2517 | func Test_props_do_not_affect_byte_offsets_editline() |
| 2518 | new |
| 2519 | let lcount = 410 |
| 2520 | |
| 2521 | " File format affects byte-offset calculations, so make sure it is known. |
| 2522 | setlocal fileformat=unix |
| 2523 | |
| 2524 | " Fill the buffer with varying length lines. We need a suitably large number |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2525 | " to force Vim code through paths where previous error have occurred. This |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2526 | " is more 'art' than 'science'. |
| 2527 | let text = 'aa' |
| 2528 | call setline(1, text) |
| 2529 | let offsets = [1] |
| 2530 | for idx in range(lcount) |
| 2531 | call add(offsets, offsets[idx] + len(text) + 1) |
| 2532 | if (idx % 6) == 0 |
| 2533 | let text = text . 'a' |
| 2534 | endif |
| 2535 | call append(line('$'), text) |
| 2536 | endfor |
| 2537 | |
| 2538 | " Set a property that just covers the first line. When this test was |
| 2539 | " developed, this did not trigger a byte-offset error. |
| 2540 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2541 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3}) |
| 2542 | |
| 2543 | for idx in range(lcount) |
| 2544 | let boff = line2byte(idx + 1) |
| 2545 | call assert_equal(offsets[idx], boff, |
| 2546 | \ 'Confounding bad byte offset at line ' . (idx + 1)) |
| 2547 | endfor |
| 2548 | |
| 2549 | " Insert text in the middle of the first line, keeping the property |
| 2550 | " unchanged. |
| 2551 | :1 |
| 2552 | normal aHello |
| 2553 | for idx in range(1, lcount) |
| 2554 | let offsets[idx] = offsets[idx] + 5 |
| 2555 | endfor |
| 2556 | |
| 2557 | for idx in range(lcount) |
| 2558 | let boff = line2byte(idx + 1) |
| 2559 | call assert_equal(offsets[idx], boff, |
| 2560 | \ 'Bad byte offset at line ' . (idx + 1)) |
| 2561 | endfor |
| 2562 | |
| 2563 | call prop_type_delete('one') |
| 2564 | bwipe! |
| 2565 | endfunc |
| 2566 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2567 | func Test_prop_inserts_text() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2568 | CheckScreendump |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2569 | CheckRunVimInTerminal |
| 2570 | |
| 2571 | " Just a basic check for now |
| 2572 | let lines =<< trim END |
| 2573 | call setline(1, 'insert some text here and other text there and some more text after wrapping') |
| 2574 | call prop_type_add('someprop', #{highlight: 'ErrorMsg'}) |
| 2575 | call prop_type_add('otherprop', #{highlight: 'Search'}) |
| 2576 | call prop_type_add('moreprop', #{highlight: 'DiffAdd'}) |
| 2577 | call prop_add(1, 18, #{type: 'someprop', text: 'SOME '}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 2578 | call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2579 | call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2580 | normal $ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2581 | |
| 2582 | call setline(2, 'prepost') |
| 2583 | call prop_type_add('multibyte', #{highlight: 'Visual'}) |
| 2584 | call prop_add(2, 4, #{type: 'multibyte', text: 'sΓΆmeεεΉ³tΓ©xt'}) |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2585 | |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2586 | call setline(3, 'Foo foo = { 1, 2 };') |
Bram Moolenaar | 3331dd0 | 2022-08-10 16:49:02 +0100 | [diff] [blame] | 2587 | call prop_type_add('testprop', #{highlight: 'Comment'}) |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2588 | call prop_add(3, 13, #{type: 'testprop', text: '.x='}) |
| 2589 | call prop_add(3, 16, #{type: 'testprop', text: '.y='}) |
| 2590 | |
| 2591 | call setline(4, '') |
| 2592 | call prop_add(4, 1, #{type: 'someprop', text: 'empty line'}) |
Bram Moolenaar | 3331dd0 | 2022-08-10 16:49:02 +0100 | [diff] [blame] | 2593 | |
| 2594 | call setline(5, 'look highlight') |
| 2595 | call prop_type_add('nohi', #{}) |
| 2596 | call prop_add(5, 6, #{type: 'nohi', text: 'no '}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2597 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2598 | call writefile(lines, 'XscriptPropsWithText', 'D') |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2599 | let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60}) |
Bram Moolenaar | 711483c | 2022-07-30 21:33:46 +0100 | [diff] [blame] | 2600 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {}) |
| 2601 | |
| 2602 | call term_sendkeys(buf, ":set signcolumn=yes\<CR>") |
| 2603 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2604 | |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2605 | call term_sendkeys(buf, "2G$") |
| 2606 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {}) |
| 2607 | |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2608 | call term_sendkeys(buf, "3Gf1") |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2609 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {}) |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2610 | call term_sendkeys(buf, "f2") |
| 2611 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {}) |
| 2612 | |
| 2613 | call term_sendkeys(buf, "4G") |
| 2614 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {}) |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2615 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2616 | call StopVimInTerminal(buf) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2617 | endfunc |
| 2618 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2619 | func Test_prop_inserts_text_highlight() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2620 | CheckScreendump |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2621 | CheckRunVimInTerminal |
| 2622 | |
| 2623 | " Just a basic check for now |
| 2624 | let lines =<< trim END |
| 2625 | call setline(1, 'insert some text (here) and there') |
| 2626 | call prop_type_add('someprop', #{highlight: 'ErrorMsg'}) |
| 2627 | let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'}) |
| 2628 | set hlsearch |
| 2629 | let thematch = matchaddpos("DiffAdd", [[1, 18]]) |
| 2630 | func DoAfter() |
| 2631 | call prop_remove(#{id: g:bef_prop}) |
| 2632 | call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'}) |
| 2633 | let g:thematch = matchaddpos("DiffAdd", [[1, 18]]) |
| 2634 | let @/ = '' |
| 2635 | endfunc |
| 2636 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2637 | call writefile(lines, 'XscriptPropsWithHighlight', 'D') |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2638 | let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60}) |
| 2639 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {}) |
| 2640 | call term_sendkeys(buf, "/text (he\<CR>") |
| 2641 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {}) |
| 2642 | call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>") |
| 2643 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {}) |
| 2644 | |
| 2645 | call term_sendkeys(buf, ":call DoAfter()\<CR>") |
| 2646 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {}) |
| 2647 | call term_sendkeys(buf, "/text (he\<CR>") |
| 2648 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {}) |
| 2649 | call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>") |
| 2650 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {}) |
| 2651 | |
| 2652 | call StopVimInTerminal(buf) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2653 | endfunc |
| 2654 | |
zeertzjq | d809c0a | 2023-08-27 11:17:39 +0200 | [diff] [blame] | 2655 | func Test_prop_inserts_text_normal_gM() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2656 | CheckScreendump |
zeertzjq | d809c0a | 2023-08-27 11:17:39 +0200 | [diff] [blame] | 2657 | CheckRunVimInTerminal |
| 2658 | |
| 2659 | let lines =<< trim END |
| 2660 | call setline(1, '123456789') |
| 2661 | call prop_type_add('theprop', #{highlight: 'Special'}) |
| 2662 | call prop_add(1, 3, {'type': 'theprop', 'text': 'bbb'}) |
| 2663 | call prop_add(1, 8, {'type': 'theprop', 'text': 'bbb'}) |
| 2664 | END |
| 2665 | call writefile(lines, 'XscriptPropsNormal_gM', 'D') |
| 2666 | let buf = RunVimInTerminal('-S XscriptPropsNormal_gM', #{rows: 3, cols: 60}) |
| 2667 | call term_sendkeys(buf, "gM") |
| 2668 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gM', {}) |
| 2669 | |
| 2670 | call StopVimInTerminal(buf) |
| 2671 | endfunc |
| 2672 | |
| 2673 | func Run_test_prop_inserts_text_normal_gj_gk(cmd) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2674 | CheckScreendump |
zeertzjq | d809c0a | 2023-08-27 11:17:39 +0200 | [diff] [blame] | 2675 | CheckRunVimInTerminal |
| 2676 | |
| 2677 | let lines =<< trim END |
| 2678 | call setline(1, repeat([repeat('a', 55)], 2)) |
| 2679 | call prop_type_add('theprop', {}) |
| 2680 | call prop_add(1, 41, {'type': 'theprop', 'text': repeat('b', 10)}) |
| 2681 | call prop_add(2, 41, {'type': 'theprop', 'text': repeat('b', 10)}) |
| 2682 | END |
| 2683 | let lines = insert(lines, a:cmd) |
| 2684 | call writefile(lines, 'XscriptPropsNormal_gj_gk', 'D') |
| 2685 | let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk', #{rows: 6, cols: 60}) |
| 2686 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_1', {}) |
| 2687 | call term_sendkeys(buf, "gj") |
| 2688 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_2', {}) |
| 2689 | call term_sendkeys(buf, "gj") |
| 2690 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_3', {}) |
| 2691 | call term_sendkeys(buf, "gj") |
| 2692 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_4', {}) |
| 2693 | call term_sendkeys(buf, "gk") |
| 2694 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_5', {}) |
| 2695 | call term_sendkeys(buf, "gk") |
| 2696 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_6', {}) |
| 2697 | call term_sendkeys(buf, "gk") |
| 2698 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_normal_gj_gk_7', {}) |
| 2699 | |
| 2700 | call StopVimInTerminal(buf) |
| 2701 | endfunc |
| 2702 | |
| 2703 | func Test_prop_inserts_text_normal_gj_gk() |
| 2704 | call Run_test_prop_inserts_text_normal_gj_gk('') |
| 2705 | call Run_test_prop_inserts_text_normal_gj_gk('set virtualedit=all') |
| 2706 | endfunc |
| 2707 | |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2708 | func Test_prop_normal_gj_gk_gM_with_outer_virtual_text() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2709 | CheckScreendump |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2710 | CheckRunVimInTerminal |
| 2711 | |
| 2712 | let lines =<< trim END |
| 2713 | vim9script |
| 2714 | setlocal number |
| 2715 | setline(1, ['First line fits on screen line.', '', 'Third line fits on screen line.']) |
| 2716 | |
| 2717 | var vt = 'test' |
| 2718 | prop_type_add(vt, {highlight: 'ToDo'}) |
| 2719 | for ln in range(1, line('$')) |
| 2720 | prop_add(ln, 0, {type: vt, text: 'Above', text_align: 'above'}) |
| 2721 | prop_add(ln, 0, {type: vt, text: 'After text wraps to next line.', text_align: 'after', text_wrap: 'wrap'}) |
| 2722 | prop_add(ln, 0, {type: vt, text: 'Right text wraps to next line.', text_align: 'right', text_wrap: 'wrap'}) |
| 2723 | prop_add(ln, 0, {type: vt, text: 'Below', text_align: 'below'}) |
| 2724 | endfor |
| 2725 | normal 3l |
| 2726 | END |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2727 | call writefile(lines, 'XscriptPropsNormal_gj_gk_gM_with_outer_text', 'D') |
| 2728 | let buf = RunVimInTerminal('-S XscriptPropsNormal_gj_gk_gM_with_outer_text', #{rows: 16, cols: 40}) |
| 2729 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2730 | |
| 2731 | call term_sendkeys(buf, "gj") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2732 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2733 | call term_sendkeys(buf, "gj") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2734 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2735 | call term_sendkeys(buf, "gk") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2736 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_2', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2737 | call term_sendkeys(buf, "gk") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2738 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2739 | |
| 2740 | call term_sendkeys(buf, "2gj") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2741 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_3', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2742 | call term_sendkeys(buf, "2gk") |
Dylan Thacker-Smith | 366c81a | 2024-03-24 09:46:56 +0100 | [diff] [blame] | 2743 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_1', {}) |
| 2744 | |
| 2745 | call term_sendkeys(buf, "gM") |
| 2746 | call VerifyScreenDump(buf, 'Test_prop_normal_gj_gk_gM_with_outer_virtual_text_4', {}) |
Dylan Thacker-Smith | b2d124c | 2024-03-24 09:43:25 +0100 | [diff] [blame] | 2747 | |
| 2748 | call StopVimInTerminal(buf) |
| 2749 | endfunc |
| 2750 | |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2751 | func Test_prop_inserts_text_visual_block() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2752 | CheckScreendump |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2753 | CheckRunVimInTerminal |
| 2754 | |
| 2755 | let lines =<< trim END |
zeertzjq | fc30584 | 2023-08-19 13:27:03 +0200 | [diff] [blame] | 2756 | call setline(1, repeat(['123456789'], 4)) |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2757 | call prop_type_add('theprop', #{highlight: 'Special'}) |
| 2758 | call prop_add(2, 2, {'type': 'theprop', 'text': '-ε£-'}) |
zeertzjq | fc30584 | 2023-08-19 13:27:03 +0200 | [diff] [blame] | 2759 | call prop_add(3, 3, {'type': 'theprop', 'text': 'ε£'}) |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2760 | END |
| 2761 | call writefile(lines, 'XscriptPropsVisualBlock', 'D') |
| 2762 | let buf = RunVimInTerminal('-S XscriptPropsVisualBlock', #{rows: 6, cols: 60}) |
| 2763 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_1', {}) |
zeertzjq | fc30584 | 2023-08-19 13:27:03 +0200 | [diff] [blame] | 2764 | call term_sendkeys(buf, "\<C-V>3jl") |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2765 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_2', {}) |
| 2766 | call term_sendkeys(buf, "l") |
| 2767 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_3', {}) |
| 2768 | call term_sendkeys(buf, "4l") |
| 2769 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_4', {}) |
| 2770 | call term_sendkeys(buf, "Ol") |
| 2771 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_5', {}) |
| 2772 | call term_sendkeys(buf, "l") |
| 2773 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_6', {}) |
| 2774 | call term_sendkeys(buf, "l") |
| 2775 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_7', {}) |
| 2776 | |
| 2777 | call StopVimInTerminal(buf) |
| 2778 | endfunc |
| 2779 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2780 | func Run_test_prop_inserts_text_showbreak(cmd) |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2781 | CheckScreendump |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2782 | CheckRunVimInTerminal |
| 2783 | |
| 2784 | let lines =<< trim END |
| 2785 | highlight! link LineNr Normal |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 2786 | setlocal number showbreak=+ breakindent breakindentopt=shift:2 |
| 2787 | setlocal scrolloff=0 smoothscroll |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2788 | call setline(1, repeat('a', 28)) |
| 2789 | call prop_type_add('theprop', #{highlight: 'Special'}) |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2790 | call prop_add(1, 28, #{type: 'theprop', text: repeat('123', 23)}) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2791 | normal! $ |
| 2792 | END |
| 2793 | let lines = insert(lines, a:cmd) |
| 2794 | call writefile(lines, 'XscriptPropsShowbreak', 'D') |
| 2795 | let buf = RunVimInTerminal('-S XscriptPropsShowbreak', #{rows: 6, cols: 30}) |
| 2796 | call term_sendkeys(buf, ":set noruler\<CR>") |
| 2797 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_1', {}) |
| 2798 | call term_sendkeys(buf, "\<C-E>") |
| 2799 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_2', {}) |
| 2800 | call term_sendkeys(buf, "\<C-E>") |
| 2801 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_3', {}) |
| 2802 | call term_sendkeys(buf, "\<C-E>") |
| 2803 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_4', {}) |
| 2804 | call term_sendkeys(buf, "\<C-E>") |
| 2805 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_5', {}) |
| 2806 | call term_sendkeys(buf, "zbi") |
| 2807 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_6', {}) |
| 2808 | call term_sendkeys(buf, "\<BS>") |
| 2809 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_7', {}) |
| 2810 | call term_sendkeys(buf, "\<Esc>l") |
| 2811 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_8', {}) |
| 2812 | call term_sendkeys(buf, "\<C-E>") |
| 2813 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_9', {}) |
| 2814 | call term_sendkeys(buf, "\<C-E>") |
| 2815 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_10', {}) |
| 2816 | call term_sendkeys(buf, "\<C-E>") |
| 2817 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_11', {}) |
| 2818 | call term_sendkeys(buf, "\<C-E>") |
| 2819 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_12', {}) |
| 2820 | call term_sendkeys(buf, "023x$") |
| 2821 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_13', {}) |
| 2822 | call term_sendkeys(buf, "\<C-E>") |
| 2823 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_14', {}) |
| 2824 | call term_sendkeys(buf, "\<C-E>") |
| 2825 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_15', {}) |
| 2826 | call term_sendkeys(buf, "\<C-E>") |
| 2827 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_16', {}) |
| 2828 | call term_sendkeys(buf, "zbi") |
| 2829 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_17', {}) |
| 2830 | call term_sendkeys(buf, "\<C-U>") |
| 2831 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_18', {}) |
| 2832 | call term_sendkeys(buf, "\<Esc>") |
| 2833 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_19', {}) |
| 2834 | call term_sendkeys(buf, "\<C-E>") |
| 2835 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_20', {}) |
| 2836 | call term_sendkeys(buf, "\<C-E>") |
| 2837 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_21', {}) |
zeertzjq | 1193951 | 2023-08-23 20:58:01 +0200 | [diff] [blame] | 2838 | call term_sendkeys(buf, "zbx") |
| 2839 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_22', {}) |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 2840 | call term_sendkeys(buf, "26ia\<Esc>a") |
| 2841 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_23', {}) |
| 2842 | call term_sendkeys(buf, "\<C-\>\<C-O>:setlocal breakindentopt=\<CR>") |
| 2843 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_showbreak_24', {}) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2844 | |
| 2845 | call StopVimInTerminal(buf) |
| 2846 | endfunc |
| 2847 | |
| 2848 | func Test_prop_inserts_text_showbreak() |
| 2849 | call Run_test_prop_inserts_text_showbreak('') |
| 2850 | " because of 'breakindent' the screendumps are the same |
| 2851 | call Run_test_prop_inserts_text_showbreak('set cpoptions+=n') |
| 2852 | endfunc |
| 2853 | |
| 2854 | func Test_prop_before_tab_skipcol() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2855 | CheckScreendump |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2856 | CheckRunVimInTerminal |
| 2857 | |
| 2858 | let lines =<< trim END |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 2859 | setlocal list listchars=tab:<-> scrolloff=0 smoothscroll |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2860 | call setline(1, repeat("\t", 4) .. 'a') |
| 2861 | call prop_type_add('theprop', #{highlight: 'Special'}) |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2862 | call prop_add(1, 4, #{type: 'theprop', text: repeat('12', 32)}) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2863 | normal! $ |
| 2864 | END |
| 2865 | call writefile(lines, 'XscriptPropsBeforeTabSkipcol', 'D') |
| 2866 | let buf = RunVimInTerminal('-S XscriptPropsBeforeTabSkipcol', #{rows: 6, cols: 30}) |
| 2867 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_1', {}) |
| 2868 | call term_sendkeys(buf, "\<C-E>") |
| 2869 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_2', {}) |
| 2870 | call term_sendkeys(buf, "\<C-E>") |
| 2871 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_3', {}) |
| 2872 | call term_sendkeys(buf, "\<C-E>") |
| 2873 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_4', {}) |
| 2874 | call term_sendkeys(buf, "zbh") |
| 2875 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_5', {}) |
| 2876 | call term_sendkeys(buf, "i") |
| 2877 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_6', {}) |
| 2878 | call term_sendkeys(buf, "\<C-O>:setlocal nolist\<CR>") |
| 2879 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_7', {}) |
| 2880 | call term_sendkeys(buf, "\<Esc>l") |
| 2881 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_8', {}) |
| 2882 | call term_sendkeys(buf, "\<C-E>") |
| 2883 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_9', {}) |
| 2884 | call term_sendkeys(buf, "\<C-E>") |
| 2885 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_10', {}) |
| 2886 | call term_sendkeys(buf, "\<C-E>") |
| 2887 | call VerifyScreenDump(buf, 'Test_prop_before_tab_skipcol_11', {}) |
| 2888 | |
| 2889 | call StopVimInTerminal(buf) |
| 2890 | endfunc |
| 2891 | |
zeertzjq | 6e55e85 | 2023-08-30 16:55:09 +0200 | [diff] [blame] | 2892 | func Test_prop_inserts_text_before_linebreak() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2893 | CheckScreendump |
zeertzjq | 6e55e85 | 2023-08-30 16:55:09 +0200 | [diff] [blame] | 2894 | CheckRunVimInTerminal |
| 2895 | |
| 2896 | let lines =<< trim END |
| 2897 | setlocal linebreak showbreak=+ breakindent breakindentopt=shift:2 |
| 2898 | call setline(1, repeat('a', 50) .. ' ' .. repeat('c', 45)) |
| 2899 | call prop_type_add('theprop', #{highlight: 'Special'}) |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2900 | call prop_add(1, 51, #{type: 'theprop', text: repeat('b', 10)}) |
zeertzjq | 6e55e85 | 2023-08-30 16:55:09 +0200 | [diff] [blame] | 2901 | normal! $ |
| 2902 | END |
| 2903 | call writefile(lines, 'XscriptPropsBeforeLinebreak', 'D') |
| 2904 | let buf = RunVimInTerminal('-S XscriptPropsBeforeLinebreak', #{rows: 6, cols: 50}) |
| 2905 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_1', {}) |
| 2906 | call term_sendkeys(buf, '05x$') |
| 2907 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_linebreak_2', {}) |
| 2908 | |
| 2909 | call StopVimInTerminal(buf) |
| 2910 | endfunc |
| 2911 | |
zeertzjq | ac2d881 | 2023-08-31 18:07:30 +0200 | [diff] [blame] | 2912 | func Test_prop_inserts_text_before_double_width_wrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2913 | CheckScreendump |
zeertzjq | ac2d881 | 2023-08-31 18:07:30 +0200 | [diff] [blame] | 2914 | CheckRunVimInTerminal |
| 2915 | |
| 2916 | let lines =<< trim END |
| 2917 | call setline(1, repeat('a', 40) .. 'ε£' .. '12345') |
| 2918 | call prop_type_add('theprop', #{highlight: 'Special'}) |
| 2919 | call prop_add(1, 41, #{type: 'theprop', text: repeat('b', 9)}) |
| 2920 | normal! $ |
| 2921 | END |
| 2922 | call writefile(lines, 'XscriptPropsBeforeDoubleWidthWrap', 'D') |
| 2923 | let buf = RunVimInTerminal('-S XscriptPropsBeforeDoubleWidthWrap', #{rows: 3, cols: 50}) |
| 2924 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_1', {}) |
zeertzjq | b5d6b5c | 2024-07-18 21:13:31 +0200 | [diff] [blame] | 2925 | call term_sendkeys(buf, 'g0') |
| 2926 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_2', {}) |
| 2927 | call term_sendkeys(buf, ":set showbreak=+++\<CR>") |
| 2928 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_before_double_width_wrap_3', {}) |
zeertzjq | ac2d881 | 2023-08-31 18:07:30 +0200 | [diff] [blame] | 2929 | |
| 2930 | call StopVimInTerminal(buf) |
| 2931 | endfunc |
| 2932 | |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 2933 | func Test_prop_inserts_text_lcs_extends() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2934 | CheckScreendump |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 2935 | CheckRunVimInTerminal |
| 2936 | |
| 2937 | let lines =<< trim END |
| 2938 | setlocal nowrap list listchars=extends:! |
| 2939 | call setline(1, repeat('a', &columns + 1)) |
| 2940 | call prop_type_add('theprop', #{highlight: 'Special'}) |
| 2941 | call prop_add(1, &columns + 2, #{type: 'theprop', text: 'bbb'}) |
| 2942 | END |
| 2943 | call writefile(lines, 'XscriptPropsListExtends', 'D') |
| 2944 | let buf = RunVimInTerminal('-S XscriptPropsListExtends', #{rows: 3, cols: 50}) |
| 2945 | call term_sendkeys(buf, '20l') |
| 2946 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_1', {}) |
| 2947 | call term_sendkeys(buf, 'zl') |
| 2948 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_2', {}) |
| 2949 | call term_sendkeys(buf, 'zl') |
| 2950 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_3', {}) |
| 2951 | call term_sendkeys(buf, 'zl') |
| 2952 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_4', {}) |
| 2953 | call term_sendkeys(buf, 'zl') |
| 2954 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_lcs_extends_5', {}) |
| 2955 | |
| 2956 | call StopVimInTerminal(buf) |
| 2957 | endfunc |
| 2958 | |
Bram Moolenaar | fb593c5 | 2022-09-17 18:57:36 +0100 | [diff] [blame] | 2959 | func Test_prop_add_with_text_fails() |
| 2960 | call prop_type_add('failing', #{highlight: 'ErrorMsg'}) |
| 2961 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:') |
| 2962 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:') |
| 2963 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:') |
| 2964 | |
| 2965 | call prop_type_delete('failing') |
| 2966 | endfunc |
| 2967 | |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2968 | func Test_props_with_text_right_align_twice() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2969 | CheckScreendump |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2970 | CheckRunVimInTerminal |
| 2971 | |
| 2972 | let lines =<< trim END |
| 2973 | call setline(1, ["some text some text some text some text", 'line two']) |
Bram Moolenaar | fb593c5 | 2022-09-17 18:57:36 +0100 | [diff] [blame] | 2974 | call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'}) |
| 2975 | call prop_type_add('MyPadding', #{highlight: 'DiffChange'}) |
Bram Moolenaar | c8bf59e | 2022-08-28 16:39:22 +0100 | [diff] [blame] | 2976 | call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'}) |
| 2977 | call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'}) |
| 2978 | call prop_add(1, 0, #{type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right'}) |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2979 | normal G$ |
| 2980 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2981 | call writefile(lines, 'XscriptPropsRightAlign', 'D') |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2982 | let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8}) |
| 2983 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {}) |
| 2984 | |
| 2985 | call term_sendkeys(buf, "ggisome more text\<Esc>G$") |
| 2986 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {}) |
| 2987 | |
Bram Moolenaar | c8bf59e | 2022-08-28 16:39:22 +0100 | [diff] [blame] | 2988 | call term_sendkeys(buf, ":set signcolumn=yes\<CR>") |
| 2989 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {}) |
| 2990 | |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2991 | call StopVimInTerminal(buf) |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2992 | endfunc |
| 2993 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2994 | func Test_props_with_text_after() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2995 | CheckScreendump |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2996 | CheckRunVimInTerminal |
| 2997 | |
| 2998 | let lines =<< trim END |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2999 | set showbreak=+++ |
Bram Moolenaar | 73c3842 | 2022-08-07 11:53:40 +0100 | [diff] [blame] | 3000 | set breakindent |
| 3001 | call setline(1, ' some text here and other text there') |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 3002 | call prop_type_add('rightprop', #{highlight: 'ErrorMsg'}) |
| 3003 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3004 | call prop_type_add('belowprop', #{highlight: 'DiffAdd'}) |
| 3005 | call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 3006 | call prop_add(1, 0, #{type: 'afterprop', text: "\tAFTER\t", text_align: 'after'}) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 3007 | call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'}) |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 3008 | call prop_add(1, 0, #{type: 'belowprop', text: ' ALSO BELOW ', text_align: 'below'}) |
Bram Moolenaar | 84b247f | 2022-08-01 11:17:40 +0100 | [diff] [blame] | 3009 | |
| 3010 | call setline(2, 'Last line.') |
| 3011 | call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'}) |
| 3012 | normal G$ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 3013 | |
| 3014 | call setline(3, 'right here') |
| 3015 | call prop_add(3, 0, #{type: 'rightprop', text: 'sΓΆmeεεΉ³tΓ©xt', text_align: 'right'}) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 3016 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3017 | call writefile(lines, 'XscriptPropsWithTextAfter', 'D') |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 3018 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60}) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 3019 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {}) |
| 3020 | |
| 3021 | call StopVimInTerminal(buf) |
Bram Moolenaar | 82b14c1 | 2022-08-10 19:50:47 +0100 | [diff] [blame] | 3022 | |
| 3023 | call assert_fails('call prop_add(1, 2, #{text: "yes", text_align: "right", type: "some"})', 'E1294:') |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 3024 | endfunc |
| 3025 | |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 3026 | func Test_props_with_text_after_and_list() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3027 | CheckScreendump |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 3028 | CheckRunVimInTerminal |
| 3029 | |
| 3030 | let lines =<< trim END |
| 3031 | vim9script |
| 3032 | setline(1, ['one', 'two']) |
| 3033 | prop_type_add('test', {highlight: 'Special'}) |
| 3034 | prop_add(1, 0, { |
| 3035 | type: 'test', |
| 3036 | text: range(50)->join(' '), |
| 3037 | text_align: 'after', |
| 3038 | text_padding_left: 3 |
| 3039 | }) |
| 3040 | prop_add(1, 0, { |
| 3041 | type: 'test', |
| 3042 | text: range(50)->join('-'), |
| 3043 | text_align: 'after', |
| 3044 | text_padding_left: 5 |
| 3045 | }) |
| 3046 | prop_add(1, 0, { |
| 3047 | type: 'test', |
| 3048 | text: range(50)->join('.'), |
| 3049 | text_align: 'after', |
| 3050 | text_padding_left: 1 |
| 3051 | }) |
| 3052 | normal G$ |
| 3053 | END |
| 3054 | call writefile(lines, 'XscriptPropsAfter', 'D') |
| 3055 | let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60}) |
| 3056 | call VerifyScreenDump(buf, 'Test_props_after_1', {}) |
| 3057 | |
| 3058 | call term_sendkeys(buf, ":set list\<CR>") |
| 3059 | call VerifyScreenDump(buf, 'Test_props_after_2', {}) |
| 3060 | |
| 3061 | call StopVimInTerminal(buf) |
| 3062 | endfunc |
| 3063 | |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3064 | func Test_props_with_text_after_below_trunc() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3065 | CheckScreendump |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3066 | CheckRunVimInTerminal |
| 3067 | |
| 3068 | let lines =<< trim END |
| 3069 | vim9script |
| 3070 | edit foobar |
| 3071 | set showbreak=+++ |
| 3072 | setline(1, ['onasdf asdf asdf asdf asd fas df', 'two']) |
| 3073 | prop_type_add('test', {highlight: 'Special'}) |
| 3074 | prop_add(1, 0, { |
| 3075 | type: 'test', |
| 3076 | text: 'the quick brown fox jumps over the lazy dog', |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3077 | text_align: 'after', |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3078 | }) |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3079 | prop_type_add('another', {highlight: 'DiffChange'}) |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3080 | prop_add(1, 0, { |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3081 | type: 'another', |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3082 | text: 'the quick brown fox jumps over the lazy dog', |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3083 | text_align: 'below', |
| 3084 | text_padding_left: 4, |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3085 | }) |
| 3086 | normal G$ |
| 3087 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3088 | call writefile(lines, 'XscriptPropsAfterTrunc', 'D') |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3089 | let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60}) |
| 3090 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {}) |
| 3091 | |
Bram Moolenaar | ccf2837 | 2022-10-10 21:10:03 +0100 | [diff] [blame] | 3092 | call term_sendkeys(buf, ":set number\<CR>") |
| 3093 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {}) |
| 3094 | |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3095 | call term_sendkeys(buf, ":set cursorline\<CR>gg") |
| 3096 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_3', {}) |
| 3097 | |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3098 | call StopVimInTerminal(buf) |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 3099 | endfunc |
| 3100 | |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 3101 | func Test_props_with_text_truncated_just_before_after() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3102 | CheckScreendump |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 3103 | CheckRunVimInTerminal |
| 3104 | |
| 3105 | let lines =<< trim END |
| 3106 | vim9script |
| 3107 | set showbreak=+++ |
| 3108 | set list listchars=extends:> |
| 3109 | set nowrap |
| 3110 | |
| 3111 | setline(1, [ |
| 3112 | 'here is text long enough to fill the row', |
| 3113 | 'second line', |
| 3114 | ]) |
| 3115 | |
| 3116 | prop_type_add("test", {"highlight": "Error"}) |
Dylan Thacker-Smith | 515f734 | 2024-03-28 12:01:14 +0100 | [diff] [blame] | 3117 | prop_add(1, 0, {type: "test", text_align: "right", text: "right text"}) |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 3118 | def g:AddPropBelow() |
| 3119 | prop_add(1, 0, {type: "test", text_align: "below", text: "below text"}) |
| 3120 | enddef |
Dylan Thacker-Smith | 515f734 | 2024-03-28 12:01:14 +0100 | [diff] [blame] | 3121 | def g:AddPropAfter() |
| 3122 | prop_add(1, 0, {type: "test", text: "after text", text_padding_left: 1}) |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 3123 | enddef |
| 3124 | normal G$ |
| 3125 | END |
| 3126 | call writefile(lines, 'XscriptPropsWithTextTruncatedJustBeforeAfter', 'D') |
| 3127 | let buf = RunVimInTerminal('-S XscriptPropsWithTextTruncatedJustBeforeAfter', #{rows: 8, cols: 40}) |
| 3128 | call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_1', {}) |
| 3129 | |
| 3130 | call term_sendkeys(buf, ":call AddPropBelow()\<CR>") |
| 3131 | call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {}) |
| 3132 | |
Dylan Thacker-Smith | 515f734 | 2024-03-28 12:01:14 +0100 | [diff] [blame] | 3133 | call term_sendkeys(buf, ":call AddPropAfter()\<CR>:\<Esc>") |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 3134 | call VerifyScreenDump(buf, 'Test_props_with_text_truncated_just_before_after_2', {}) |
| 3135 | |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 3136 | call StopVimInTerminal(buf) |
| 3137 | endfunc |
| 3138 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 3139 | func Test_prop_with_text_below_after_empty() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3140 | CheckScreendump |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 3141 | CheckRunVimInTerminal |
| 3142 | |
| 3143 | let lines =<< trim END |
| 3144 | vim9script |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3145 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 3146 | setline(1, ['vim9script', '', 'three', '']) |
| 3147 | |
| 3148 | # Add text prop below empty line 2 with padding. |
| 3149 | prop_type_add('test', {highlight: 'ErrorMsg'}) |
| 3150 | prop_add(2, 0, { |
| 3151 | type: 'test', |
| 3152 | text: 'The quick brown fox jumps over the lazy dog', |
| 3153 | text_align: 'below', |
| 3154 | text_padding_left: 1, |
| 3155 | }) |
| 3156 | |
| 3157 | # Add text prop below empty line 4 without padding. |
| 3158 | prop_type_add('other', {highlight: 'DiffChange'}) |
| 3159 | prop_add(4, 0, { |
| 3160 | type: 'other', |
| 3161 | text: 'The slow fox bumps into the lazy dog', |
| 3162 | text_align: 'below', |
| 3163 | text_padding_left: 0, |
| 3164 | }) |
| 3165 | END |
| 3166 | call writefile(lines, 'XscriptPropBelowAfterEmpty', 'D') |
| 3167 | let buf = RunVimInTerminal('-S XscriptPropBelowAfterEmpty', #{rows: 8, cols: 60}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3168 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_1', {}) |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 3169 | |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 3170 | call term_sendkeys(buf, ":set number\<CR>") |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3171 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {}) |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 3172 | |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 3173 | call term_sendkeys(buf, ":set nowrap\<CR>") |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3174 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {}) |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 3175 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 3176 | call StopVimInTerminal(buf) |
| 3177 | endfunc |
| 3178 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3179 | func Test_prop_with_text_above_below_empty() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3180 | CheckScreendump |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3181 | CheckRunVimInTerminal |
| 3182 | |
| 3183 | let lines =<< trim END |
| 3184 | setlocal number |
| 3185 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 3186 | |
| 3187 | let vt = 'test' |
| 3188 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 3189 | for ln in range(1, line('$')) |
Dylan Thacker-Smith | da0c913 | 2024-02-27 20:25:10 +0100 | [diff] [blame] | 3190 | " use 1 character text to test for off-by-one regressions |
| 3191 | call prop_add(ln, 0, {'type': vt, 'text': '-', 'text_align': 'above'}) |
| 3192 | call prop_add(ln, 0, {'type': vt, 'text': '+', 'text_align': 'below'}) |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3193 | endfor |
| 3194 | normal G |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 3195 | |
| 3196 | func AddMore() |
| 3197 | call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'}) |
| 3198 | call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'}) |
| 3199 | call prop_add(5, 0, {'type': g:vt, 'text': '!', 'text_align': 'above'}) |
| 3200 | endfunc |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3201 | END |
| 3202 | call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D') |
| 3203 | let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60}) |
| 3204 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_1', {}) |
| 3205 | |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 3206 | call term_sendkeys(buf, ":set list\<CR>") |
| 3207 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_2', {}) |
| 3208 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3209 | call term_sendkeys(buf, ":set nolist\<CR>") |
| 3210 | call term_sendkeys(buf, ":set colorcolumn=10\<CR>") |
| 3211 | call term_sendkeys(buf, ":\<CR>") |
| 3212 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_3', {}) |
| 3213 | |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 3214 | call term_sendkeys(buf, ":set colorcolumn=\<CR>") |
| 3215 | call term_sendkeys(buf, ":set relativenumber\<CR>") |
| 3216 | call term_sendkeys(buf, ":\<CR>") |
| 3217 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_4', {}) |
| 3218 | |
| 3219 | call term_sendkeys(buf, "kk") |
| 3220 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {}) |
| 3221 | |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 3222 | " This was drawing line number over cmdline and leaking memory. |
| 3223 | call term_sendkeys(buf, ":call AddMore()\<CR>") |
| 3224 | call term_sendkeys(buf, "gg") |
| 3225 | call term_sendkeys(buf, "j") |
| 3226 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_6', {}) |
| 3227 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3228 | call StopVimInTerminal(buf) |
| 3229 | endfunc |
| 3230 | |
Matthias | 2c9f49b | 2025-03-16 19:27:51 +0100 | [diff] [blame] | 3231 | func Test_prop_multiple_lines_above() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3232 | CheckScreendump |
Matthias | 2c9f49b | 2025-03-16 19:27:51 +0100 | [diff] [blame] | 3233 | CheckRunVimInTerminal |
| 3234 | |
| 3235 | let lines =<< trim END |
| 3236 | setlocal number colorcolumn=10 |
| 3237 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 3238 | |
| 3239 | let vt = 'test' |
| 3240 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 3241 | for ln in range(1, line('$')) |
| 3242 | call prop_add(ln, 0, {'type': vt, 'text': 'above1', 'text_align': 'above'}) |
| 3243 | call prop_add(ln, 0, {'type': vt, 'text': 'above2', 'text_align': 'above'}) |
| 3244 | endfor |
| 3245 | normal G |
| 3246 | END |
| 3247 | call writefile(lines, 'XscriptPropMultipleLinesAbove', 'D') |
| 3248 | let buf = RunVimInTerminal('-S XscriptPropMultipleLinesAbove', #{rows: 16, cols: 60}) |
| 3249 | call VerifyScreenDump(buf, 'Test_prop_multiple_lines_above_1', {}) |
| 3250 | |
| 3251 | call StopVimInTerminal(buf) |
| 3252 | endfunc |
| 3253 | |
zeertzjq | 91d26aa | 2024-10-27 19:23:34 +0100 | [diff] [blame] | 3254 | func Test_prop_with_multibyte_above() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3255 | CheckScreendump |
zeertzjq | 91d26aa | 2024-10-27 19:23:34 +0100 | [diff] [blame] | 3256 | CheckRunVimInTerminal |
| 3257 | |
| 3258 | let lines =<< trim END |
| 3259 | setlocal number colorcolumn=10 |
| 3260 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 3261 | |
| 3262 | let vt = 'test' |
| 3263 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 3264 | for ln in range(1, line('$')) |
| 3265 | call prop_add(ln, 0, {'type': vt, 'text': 'β¦', 'text_align': 'above'}) |
| 3266 | endfor |
| 3267 | normal G |
| 3268 | END |
| 3269 | call writefile(lines, 'XscriptPropMultibyteAbove', 'D') |
| 3270 | let buf = RunVimInTerminal('-S XscriptPropMultibyteAbove', #{rows: 16, cols: 60}) |
| 3271 | call VerifyScreenDump(buf, 'Test_prop_multibyte_above_1', {}) |
| 3272 | |
| 3273 | call StopVimInTerminal(buf) |
| 3274 | endfunc |
| 3275 | |
Bram Moolenaar | ea62cee | 2023-02-19 18:36:41 +0000 | [diff] [blame] | 3276 | func Test_prop_with_multibyte_below() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3277 | CheckScreendump |
Bram Moolenaar | ea62cee | 2023-02-19 18:36:41 +0000 | [diff] [blame] | 3278 | CheckRunVimInTerminal |
| 3279 | |
| 3280 | let lines =<< trim END |
| 3281 | setlocal number |
| 3282 | call setline(1, ['Β©', 'Β©', 'Β©']) |
| 3283 | |
| 3284 | let vt = 'test' |
| 3285 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 3286 | for ln in range(1, line('$')) |
| 3287 | call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'}) |
| 3288 | endfor |
| 3289 | normal G |
| 3290 | END |
| 3291 | call writefile(lines, 'XscriptPropMultibyteBelow', 'D') |
| 3292 | let buf = RunVimInTerminal('-S XscriptPropMultibyteBelow', #{rows: 10, cols: 60}) |
| 3293 | call VerifyScreenDump(buf, 'Test_prop_multibyte_below_1', {}) |
| 3294 | |
| 3295 | call StopVimInTerminal(buf) |
| 3296 | endfunc |
| 3297 | |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 3298 | func Test_prop_with_text_below_rightleft() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3299 | CheckScreendump |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 3300 | CheckRunVimInTerminal |
| 3301 | CheckFeature rightleft |
| 3302 | |
| 3303 | let lines =<< trim END |
| 3304 | setlocal number rightleft |
| 3305 | call setline(1, 'abcde') |
| 3306 | call prop_type_add('theprop', #{highlight: 'Special'}) |
| 3307 | call prop_add(1, 0, #{type: 'theprop', text: '12345', text_align: 'below'}) |
| 3308 | END |
| 3309 | call writefile(lines, 'XscriptPropBelowRightleft', 'D') |
| 3310 | let buf = RunVimInTerminal('-S XscriptPropBelowRightleft', #{rows: 6, cols: 60}) |
| 3311 | call VerifyScreenDump(buf, 'Test_prop_below_rightleft_1', {}) |
| 3312 | |
| 3313 | call StopVimInTerminal(buf) |
| 3314 | endfunc |
| 3315 | |
Bram Moolenaar | 5ceb815 | 2023-02-12 18:11:21 +0000 | [diff] [blame] | 3316 | func Test_prop_with_text_above_empty() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3317 | CheckScreendump |
Bram Moolenaar | 5ceb815 | 2023-02-12 18:11:21 +0000 | [diff] [blame] | 3318 | CheckRunVimInTerminal |
| 3319 | |
| 3320 | " check the cursor is in the correct line |
| 3321 | let lines =<< trim END |
| 3322 | setlocal number |
| 3323 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 3324 | |
| 3325 | let vt = 'test' |
| 3326 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 3327 | for ln in range(1, line('$')) |
| 3328 | call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'}) |
| 3329 | endfor |
| 3330 | normal G |
| 3331 | END |
| 3332 | call writefile(lines, 'XscriptPropAboveEmpty', 'D') |
| 3333 | let buf = RunVimInTerminal('-S XscriptPropAboveEmpty', #{rows: 16, cols: 60}) |
| 3334 | call VerifyScreenDump(buf, 'Test_prop_above_empty_1', {}) |
| 3335 | |
| 3336 | call term_sendkeys(buf, ":set list\<CR>") |
| 3337 | call VerifyScreenDump(buf, 'Test_prop_above_empty_2', {}) |
| 3338 | |
| 3339 | call StopVimInTerminal(buf) |
| 3340 | endfunc |
| 3341 | |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3342 | func Test_prop_with_text_below_after_match() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3343 | CheckScreendump |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3344 | CheckRunVimInTerminal |
| 3345 | |
| 3346 | let lines =<< trim END |
| 3347 | vim9script |
| 3348 | |
| 3349 | setline(1, ['vim9script', 'some text']) |
| 3350 | set signcolumn=yes |
| 3351 | matchaddpos('Search', [[1, 10]]) |
| 3352 | prop_type_add('test', {highlight: 'Error'}) |
| 3353 | prop_add(1, 0, { |
| 3354 | type: 'test', |
| 3355 | text: 'The quick brown fox', |
| 3356 | text_align: 'below' |
| 3357 | }) |
| 3358 | END |
| 3359 | call writefile(lines, 'XscriptPropsBelow', 'D') |
| 3360 | let buf = RunVimInTerminal('-S XscriptPropsBelow', #{rows: 8, cols: 60}) |
| 3361 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_after_match_1', {}) |
| 3362 | |
| 3363 | call StopVimInTerminal(buf) |
| 3364 | endfunc |
| 3365 | |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 3366 | func Test_props_with_text_after_joined() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3367 | CheckScreendump |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 3368 | CheckRunVimInTerminal |
| 3369 | |
| 3370 | let lines =<< trim END |
| 3371 | call setline(1, ['one', 'two', 'three', 'four']) |
| 3372 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3373 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'}) |
| 3374 | call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'}) |
| 3375 | normal ggJ |
| 3376 | normal GkJ |
| 3377 | |
| 3378 | call setline(3, ['a', 'b', 'c', 'd', 'e', 'f']) |
| 3379 | call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'}) |
| 3380 | call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'}) |
| 3381 | call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'}) |
| 3382 | call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'}) |
| 3383 | normal 3G6J |
| 3384 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3385 | call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D') |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 3386 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60}) |
| 3387 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {}) |
| 3388 | |
| 3389 | call StopVimInTerminal(buf) |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 3390 | endfunc |
| 3391 | |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3392 | func Test_props_with_text_after_truncated() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3393 | CheckScreendump |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3394 | CheckRunVimInTerminal |
| 3395 | |
| 3396 | let lines =<< trim END |
| 3397 | call setline(1, ['one two three four five six seven']) |
| 3398 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3399 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'}) |
| 3400 | |
| 3401 | call setline(2, ['one two three four five six seven']) |
| 3402 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'}) |
| 3403 | |
| 3404 | call setline(3, ['one two three four five six seven']) |
| 3405 | call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'}) |
| 3406 | |
| 3407 | call setline(4, ['cursor here']) |
| 3408 | normal 4Gfh |
| 3409 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3410 | call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D') |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3411 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60}) |
| 3412 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {}) |
| 3413 | |
| 3414 | call term_sendkeys(buf, ":37vsp\<CR>gg") |
| 3415 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {}) |
| 3416 | |
| 3417 | call term_sendkeys(buf, ":36wincmd |\<CR>") |
| 3418 | call term_sendkeys(buf, "2G$") |
| 3419 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {}) |
| 3420 | |
| 3421 | call term_sendkeys(buf, ":33wincmd |\<CR>") |
| 3422 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {}) |
| 3423 | |
| 3424 | call term_sendkeys(buf, ":18wincmd |\<CR>") |
| 3425 | call term_sendkeys(buf, "0fx") |
| 3426 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {}) |
| 3427 | |
| 3428 | call StopVimInTerminal(buf) |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3429 | endfunc |
| 3430 | |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 3431 | func Test_props_with_text_after_truncated_and_ambiwidth_is_double() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3432 | CheckScreendump |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 3433 | CheckRunVimInTerminal |
| 3434 | |
| 3435 | let lines =<< trim END |
| 3436 | set ambiwidth=double |
| 3437 | call setline(1, ['one two three four five six seven']) |
| 3438 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3439 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'}) |
| 3440 | |
| 3441 | call setline(2, ['one two three four five six seven']) |
| 3442 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'}) |
| 3443 | |
| 3444 | call setline(3, ['one two three four five six seven']) |
| 3445 | call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'}) |
| 3446 | |
| 3447 | call setline(4, ['cursor here']) |
| 3448 | normal 4Gfh |
| 3449 | END |
| 3450 | call writefile(lines, 'XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', 'D') |
| 3451 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-and-ambiwidth-is-double', #{rows: 9, cols: 60}) |
| 3452 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_ambiw_d_1', {}) |
| 3453 | |
| 3454 | call StopVimInTerminal(buf) |
| 3455 | endfunc |
| 3456 | |
| 3457 | |
| 3458 | func Test_props_with_text_after_truncated_not_utf8() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3459 | CheckScreendump |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 3460 | CheckRunVimInTerminal |
| 3461 | |
| 3462 | let lines =<< trim END |
| 3463 | set enc=cp932 tenc=utf-8 |
| 3464 | call setline(1, ['one two three four five six seven']) |
| 3465 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3466 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'}) |
| 3467 | |
| 3468 | call setline(2, ['one two three four five six seven']) |
| 3469 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'}) |
| 3470 | |
| 3471 | call setline(3, ['one two three four five six seven']) |
| 3472 | call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below'}) |
| 3473 | |
| 3474 | call setline(4, ['cursor here']) |
| 3475 | normal 4Gfh |
| 3476 | END |
| 3477 | call writefile(lines, 'XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', 'D') |
| 3478 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc-enc-is-not-utf8', #{rows: 9, cols: 60}) |
| 3479 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_not_utf8', {}) |
| 3480 | |
| 3481 | call StopVimInTerminal(buf) |
| 3482 | endfunc |
| 3483 | |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3484 | func Test_props_with_text_empty_line() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3485 | CheckScreendump |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3486 | CheckRunVimInTerminal |
| 3487 | |
| 3488 | let lines =<< trim END |
| 3489 | call setline(1, ['', 'aaa', '', 'bbbbbb']) |
| 3490 | call prop_type_add('prop1', #{highlight: 'Search'}) |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 3491 | call prop_add(1, 1, #{type: 'prop1', text: repeat('X', &columns)}) |
| 3492 | call prop_add(3, 1, #{type: 'prop1', text: repeat('X', &columns + 1)}) |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3493 | normal gg0 |
| 3494 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3495 | call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D') |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3496 | let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60}) |
| 3497 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {}) |
| 3498 | call term_sendkeys(buf, "$") |
| 3499 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {}) |
| 3500 | call term_sendkeys(buf, "j") |
| 3501 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {}) |
| 3502 | call term_sendkeys(buf, "j") |
| 3503 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {}) |
| 3504 | call term_sendkeys(buf, "j") |
| 3505 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {}) |
zeertzjq | e3daa06 | 2023-08-27 19:11:46 +0200 | [diff] [blame] | 3506 | call term_sendkeys(buf, "0\<C-V>2l2k") |
| 3507 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_6', {}) |
| 3508 | call term_sendkeys(buf, "\<Esc>/aaa\\n\\%V\<CR>") |
| 3509 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_7', {}) |
| 3510 | call term_sendkeys(buf, "3ggic") |
| 3511 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_8', {}) |
| 3512 | call term_sendkeys(buf, "\<Esc>/aaa\\nc\\%V\<CR>") |
| 3513 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_9', {}) |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3514 | |
| 3515 | call StopVimInTerminal(buf) |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 3516 | endfunc |
| 3517 | |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3518 | func Test_props_with_text_after_wraps() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3519 | CheckScreendump |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3520 | CheckRunVimInTerminal |
| 3521 | |
| 3522 | let lines =<< trim END |
| 3523 | call setline(1, ['one two three four five six seven']) |
| 3524 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 3525 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'}) |
| 3526 | |
| 3527 | call setline(2, ['one two three four five six seven']) |
| 3528 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'}) |
| 3529 | |
| 3530 | call setline(3, ['one two three four five six seven']) |
| 3531 | call prop_add(3, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five lets wrap after some more text', text_align: 'below', text_wrap: 'wrap'}) |
| 3532 | |
| 3533 | call setline(4, ['cursor here']) |
| 3534 | normal 4Gfh |
| 3535 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3536 | call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D') |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3537 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60}) |
| 3538 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {}) |
| 3539 | |
| 3540 | call StopVimInTerminal(buf) |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 3541 | endfunc |
| 3542 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3543 | func Test_props_with_text_after_nowrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3544 | CheckScreendump |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3545 | CheckRunVimInTerminal |
| 3546 | |
| 3547 | let lines =<< trim END |
| 3548 | set nowrap |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3549 | call setline(1, ['one', 'two', 'three', 'four']) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3550 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 3551 | call prop_type_add('anotherprop', #{highlight: 'Search'}) |
Bram Moolenaar | db9b96d | 2022-08-06 17:38:53 +0100 | [diff] [blame] | 3552 | call prop_type_add('someprop', #{highlight: 'DiffChange'}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3553 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 3554 | call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'}) |
| 3555 | call prop_add(2, 0, #{type: 'belowprop', text: 'One More Here', text_align: 'below'}) |
Bram Moolenaar | db9b96d | 2022-08-06 17:38:53 +0100 | [diff] [blame] | 3556 | call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'}) |
| 3557 | call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'}) |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3558 | normal 3G$ |
| 3559 | |
| 3560 | call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'}) |
| 3561 | call prop_add(3, 0, #{type: 'anotherprop', text: 'also right aligned', text_align: 'right'}) |
Bram Moolenaar | 9113c2c | 2022-08-13 20:17:34 +0100 | [diff] [blame] | 3562 | hi CursorLine ctermbg=lightgrey |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3563 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3564 | call writefile(lines, 'XscriptPropsAfterNowrap', 'D') |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3565 | let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3566 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {}) |
| 3567 | |
Bram Moolenaar | 9113c2c | 2022-08-13 20:17:34 +0100 | [diff] [blame] | 3568 | call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>") |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3569 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {}) |
| 3570 | |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3571 | call term_sendkeys(buf, "j") |
| 3572 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {}) |
| 3573 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3574 | call StopVimInTerminal(buf) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3575 | endfunc |
| 3576 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3577 | func Test_prop_with_text_below_cul() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3578 | CheckScreendump |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3579 | CheckRunVimInTerminal |
| 3580 | |
| 3581 | let lines =<< trim END |
| 3582 | vim9script |
| 3583 | |
| 3584 | setline(1, ['some text', 'last line']) |
| 3585 | set cursorline nowrap |
| 3586 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3587 | prop_add(1, 0, { |
| 3588 | type: 'test', |
| 3589 | text: 'The quick brown fox jumps over the lazy dog', |
| 3590 | text_align: 'below', |
| 3591 | text_padding_left: 4, |
| 3592 | }) |
| 3593 | END |
| 3594 | call writefile(lines, 'XscriptPropsBelowCurline', 'D') |
| 3595 | let buf = RunVimInTerminal('-S XscriptPropsBelowCurline', #{rows: 6, cols: 60}) |
| 3596 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_cul_1', {}) |
| 3597 | |
| 3598 | call StopVimInTerminal(buf) |
| 3599 | endfunc |
| 3600 | |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3601 | func Test_props_with_text_below_nowrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3602 | CheckScreendump |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3603 | CheckRunVimInTerminal |
| 3604 | |
| 3605 | let lines =<< trim END |
| 3606 | vim9script |
| 3607 | edit foobar |
| 3608 | set nowrap |
| 3609 | set showbreak=+++\ |
| 3610 | setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two']) |
| 3611 | prop_type_add('test', {highlight: 'Special'}) |
| 3612 | prop_add(1, 0, { |
| 3613 | type: 'test', |
| 3614 | text: 'the quick brown fox jumps over the lazy dog', |
| 3615 | text_align: 'after' |
| 3616 | }) |
| 3617 | prop_add(1, 0, { |
| 3618 | type: 'test', |
| 3619 | text: 'the quick brown fox jumps over the lazy dog', |
| 3620 | text_align: 'below' |
| 3621 | }) |
| 3622 | normal G$ |
| 3623 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3624 | call writefile(lines, 'XscriptPropsBelowNowrap', 'D') |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3625 | let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60}) |
| 3626 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {}) |
| 3627 | |
| 3628 | call term_sendkeys(buf, "gg$") |
| 3629 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {}) |
| 3630 | |
| 3631 | call StopVimInTerminal(buf) |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3632 | endfunc |
| 3633 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3634 | func Test_props_with_text_above() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3635 | CheckScreendump |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3636 | CheckRunVimInTerminal |
| 3637 | |
| 3638 | let lines =<< trim END |
| 3639 | call setline(1, ['one two', 'three four', 'five six']) |
| 3640 | call prop_type_add('above1', #{highlight: 'Search'}) |
| 3641 | call prop_type_add('above2', #{highlight: 'DiffChange'}) |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3642 | call prop_type_add('below', #{highlight: 'DiffAdd'}) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3643 | call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'}) |
| 3644 | call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'}) |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 3645 | call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3}) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3646 | |
| 3647 | normal gglllj |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3648 | func AddPropBelow() |
| 3649 | call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'}) |
| 3650 | endfunc |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 3651 | func AddLongPropAbove() |
| 3652 | 3,4delete |
| 3653 | set wrap |
| 3654 | call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2}) |
| 3655 | endfunc |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3656 | END |
| 3657 | call writefile(lines, 'XscriptPropsWithTextAbove', 'D') |
| 3658 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60}) |
| 3659 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {}) |
| 3660 | |
Bram Moolenaar | e24b4ab | 2022-09-16 20:51:14 +0100 | [diff] [blame] | 3661 | call term_sendkeys(buf, "ggg$") |
| 3662 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {}) |
| 3663 | call term_sendkeys(buf, "g0") |
| 3664 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {}) |
| 3665 | |
Bram Moolenaar | 4c7fd4d | 2022-09-17 17:15:33 +0100 | [diff] [blame] | 3666 | call term_sendkeys(buf, ":set showbreak=>>\<CR>") |
| 3667 | call term_sendkeys(buf, "ggll") |
| 3668 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {}) |
| 3669 | call term_sendkeys(buf, ":set showbreak=\<CR>") |
| 3670 | |
Bram Moolenaar | 88b79cb | 2022-09-10 22:32:14 +0100 | [diff] [blame] | 3671 | call term_sendkeys(buf, "ggI") |
| 3672 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {}) |
| 3673 | call term_sendkeys(buf, "inserted \<Esc>") |
| 3674 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {}) |
| 3675 | |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 3676 | call term_sendkeys(buf, ":set number signcolumn=yes\<CR>") |
| 3677 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {}) |
| 3678 | |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 3679 | call term_sendkeys(buf, ":set nowrap\<CR>gg$j") |
| 3680 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {}) |
| 3681 | |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3682 | call term_sendkeys(buf, ":call AddPropBelow()\<CR>") |
| 3683 | call term_sendkeys(buf, "ggve") |
| 3684 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {}) |
| 3685 | call term_sendkeys(buf, "V") |
| 3686 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {}) |
| 3687 | |
Bram Moolenaar | 3b93cf2 | 2022-09-13 18:34:18 +0100 | [diff] [blame] | 3688 | call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>") |
| 3689 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {}) |
| 3690 | |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 3691 | call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>") |
| 3692 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {}) |
| 3693 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3694 | call StopVimInTerminal(buf) |
| 3695 | endfunc |
| 3696 | |
Bram Moolenaar | 2354b66 | 2023-04-23 21:42:25 +0100 | [diff] [blame] | 3697 | func Test_prop_with_text_above_padding() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3698 | CheckScreendump |
Bram Moolenaar | 2354b66 | 2023-04-23 21:42:25 +0100 | [diff] [blame] | 3699 | CheckRunVimInTerminal |
| 3700 | |
| 3701 | let lines =<< trim END |
| 3702 | vim9script |
| 3703 | |
| 3704 | setlocal tabstop=8 noexpandtab |
| 3705 | setline(1, ['', 'sky is blue', 'ocean is blue']) |
| 3706 | prop_type_add('DiagVirtualText', {highlight: 'Search', override: true}) |
| 3707 | prop_add(3, 0, {text: "ββ start", text_align: "above", |
| 3708 | type: 'DiagVirtualText', |
| 3709 | text_padding_left: 200}) |
| 3710 | END |
| 3711 | call writefile(lines, 'XscriptAbovePadding', 'D') |
| 3712 | let buf = RunVimInTerminal('-S XscriptAbovePadding', #{rows: 8}) |
| 3713 | call VerifyScreenDump(buf, 'Test_prop_above_padding_1', {}) |
| 3714 | |
| 3715 | call StopVimInTerminal(buf) |
| 3716 | endfunc |
| 3717 | |
Bram Moolenaar | 702bd6c | 2022-09-14 16:09:57 +0100 | [diff] [blame] | 3718 | func Test_prop_above_with_indent() |
| 3719 | new |
| 3720 | call setline(1, ['first line', ' second line', ' line below']) |
| 3721 | setlocal cindent |
| 3722 | call prop_type_add('indented', #{highlight: 'Search'}) |
| 3723 | call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4}) |
| 3724 | call assert_equal(' line below', getline(3)) |
| 3725 | |
| 3726 | exe "normal 3G2|a\<CR>" |
| 3727 | call assert_equal(' ', getline(3)) |
| 3728 | call assert_equal(' line below', getline(4)) |
| 3729 | |
| 3730 | bwipe! |
| 3731 | call prop_type_delete('indented') |
| 3732 | endfunc |
| 3733 | |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 3734 | func Test_prop_above_with_number() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3735 | CheckScreendump |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 3736 | CheckRunVimInTerminal |
| 3737 | |
| 3738 | let lines =<< trim END |
| 3739 | vim9script |
| 3740 | setline(1, ['one one one', 'two two two', 'three three three']) |
| 3741 | set number cpo+=n |
| 3742 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3743 | prop_add(2, 0, { |
| 3744 | text: 'above the text', |
| 3745 | type: 'test', |
| 3746 | text_align: 'above', |
| 3747 | }) |
| 3748 | def g:OneMore() |
| 3749 | prop_add(2, 0, { |
| 3750 | text: 'also above the text', |
| 3751 | type: 'test', |
| 3752 | text_align: 'above', |
| 3753 | }) |
| 3754 | enddef |
| 3755 | END |
| 3756 | call writefile(lines, 'XscriptPropAboveNr', 'D') |
| 3757 | let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8}) |
| 3758 | call VerifyScreenDump(buf, 'Test_prop_above_number_1', {}) |
| 3759 | |
| 3760 | call term_sendkeys(buf, ":call OneMore()\<CR>") |
| 3761 | call VerifyScreenDump(buf, 'Test_prop_above_number_2', {}) |
| 3762 | |
zeertzjq | 62f1954 | 2025-03-08 16:27:37 +0100 | [diff] [blame] | 3763 | call term_sendkeys(buf, ":setlocal cursorline cursorlineopt=number\<CR>") |
| 3764 | call term_sendkeys(buf, 'j') |
| 3765 | call VerifyScreenDump(buf, 'Test_prop_above_number_3', {}) |
| 3766 | |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 3767 | call StopVimInTerminal(buf) |
| 3768 | endfunc |
| 3769 | |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 3770 | func Test_prop_above_with_linebreak() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3771 | CheckScreendump |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 3772 | CheckRunVimInTerminal |
| 3773 | |
| 3774 | let lines =<< trim END |
| 3775 | setlocal linebreak breakindent breakindentopt=shift:4 |
| 3776 | call setline(1, ["a b", "c d"]) |
| 3777 | call prop_type_add('theprop' , #{highlight: 'Special'}) |
| 3778 | call prop_add(1, 0, #{type: 'theprop', text: '123', text_align: 'above'}) |
| 3779 | normal! 2gg$ |
| 3780 | END |
| 3781 | call writefile(lines, 'XscriptPropAboveLinebreak', 'D') |
| 3782 | let buf = RunVimInTerminal('-S XscriptPropAboveLinebreak', #{rows: 6}) |
| 3783 | call VerifyScreenDump(buf, 'Test_prop_above_linebreak_1', {}) |
| 3784 | call term_sendkeys(buf, 'k') |
| 3785 | call VerifyScreenDump(buf, 'Test_prop_above_linebreak_2', {}) |
| 3786 | |
| 3787 | call StopVimInTerminal(buf) |
| 3788 | endfunc |
| 3789 | |
| 3790 | func Test_prop_above_and_before() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3791 | CheckScreendump |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 3792 | CheckRunVimInTerminal |
| 3793 | |
| 3794 | let lines =<< trim END |
| 3795 | setlocal linebreak breakindent breakindentopt=shift:2 |
| 3796 | call setline(1, ["a", " b c"]) |
| 3797 | call prop_type_add('theprop' , #{highlight: 'Special'}) |
| 3798 | call prop_add(2, 0, #{type: 'theprop', text: ' 123', text_align: 'above'}) |
| 3799 | call prop_add(2, 4, #{type: 'theprop', text: ': 456'} ) |
| 3800 | normal! 2gg$ |
| 3801 | END |
| 3802 | call writefile(lines, 'XscriptPropAboveAndBefore', 'D') |
| 3803 | let buf = RunVimInTerminal('-S XscriptPropAboveAndBefore', #{rows: 6}) |
| 3804 | call VerifyScreenDump(buf, 'Test_prop_above_and_before_1', {}) |
| 3805 | call term_sendkeys(buf, 'h') |
| 3806 | call VerifyScreenDump(buf, 'Test_prop_above_and_before_2', {}) |
| 3807 | call term_sendkeys(buf, 'h') |
| 3808 | call VerifyScreenDump(buf, 'Test_prop_above_and_before_3', {}) |
| 3809 | call term_sendkeys(buf, 'h') |
| 3810 | call VerifyScreenDump(buf, 'Test_prop_above_and_before_4', {}) |
| 3811 | call term_sendkeys(buf, 'h') |
| 3812 | call VerifyScreenDump(buf, 'Test_prop_above_and_before_5', {}) |
| 3813 | |
| 3814 | call StopVimInTerminal(buf) |
| 3815 | endfunc |
| 3816 | |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3817 | func Test_prop_below_split_line() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3818 | CheckScreendump |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3819 | CheckRunVimInTerminal |
| 3820 | |
| 3821 | let lines =<< trim END |
| 3822 | vim9script |
| 3823 | setline(1, ['one one one', 'two two two', 'three three three']) |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3824 | prop_type_add('test', {highlight: 'Search'}) |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3825 | prop_add(2, 0, { |
| 3826 | text: 'ββ Virtual text below the 2nd line', |
| 3827 | type: 'test', |
| 3828 | text_align: 'below', |
| 3829 | text_padding_left: 3 |
| 3830 | }) |
| 3831 | END |
| 3832 | call writefile(lines, 'XscriptPropBelowSpitLine', 'D') |
| 3833 | let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8}) |
| 3834 | call term_sendkeys(buf, "2GA\<CR>xx") |
| 3835 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {}) |
| 3836 | |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3837 | call term_sendkeys(buf, "\<Esc>:set number\<CR>") |
| 3838 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {}) |
| 3839 | |
Bram Moolenaar | b84d565 | 2022-09-20 17:57:53 +0100 | [diff] [blame] | 3840 | call term_sendkeys(buf, ":set nowrap\<CR>") |
| 3841 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {}) |
| 3842 | |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3843 | call StopVimInTerminal(buf) |
| 3844 | endfunc |
| 3845 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 3846 | func Test_prop_above_below_smoothscroll() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3847 | CheckScreendump |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 3848 | CheckRunVimInTerminal |
| 3849 | |
| 3850 | let lines =<< trim END |
| 3851 | vim9script |
| 3852 | setline(1, range(1, 10)->mapnew((_, v) => '" line ' .. v)) |
| 3853 | |
| 3854 | set smoothscroll wrap |
| 3855 | call prop_type_add('mytype', {highlight: 'DiffChange'}) |
| 3856 | call prop_add(3, 0, {text: "insert above", type: "mytype", text_align: 'above'}) |
| 3857 | call prop_add(5, 0, {text: "insert above 1", type: "mytype", text_align: 'above'}) |
| 3858 | call prop_add(5, 0, {text: "insert above 2", type: "mytype", text_align: 'above'}) |
| 3859 | call prop_add(7, 0, {text: "insert below", type: "mytype", text_align: 'below'}) |
| 3860 | call prop_add(9, 0, {text: "insert below 1", type: "mytype", text_align: 'below'}) |
| 3861 | call prop_add(9, 0, {text: "insert below 2", type: "mytype", text_align: 'below'}) |
| 3862 | END |
| 3863 | call writefile(lines, 'XscriptPropsSmoothscroll', 'D') |
| 3864 | let buf = RunVimInTerminal('-S XscriptPropsSmoothscroll', #{rows: 8, cols: 60}) |
| 3865 | call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_1', {}) |
| 3866 | |
| 3867 | for nr in range(2, 16) |
| 3868 | call term_sendkeys(buf, "\<C-E>") |
| 3869 | call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_' .. nr, {}) |
| 3870 | endfor |
| 3871 | |
| 3872 | call StopVimInTerminal(buf) |
| 3873 | endfunc |
| 3874 | |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3875 | func Test_props_with_text_override() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3876 | CheckScreendump |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3877 | CheckRunVimInTerminal |
| 3878 | |
| 3879 | let lines =<< trim END |
| 3880 | vim9script |
| 3881 | setline(1, 'some text here') |
| 3882 | hi Likethis ctermfg=blue ctermbg=cyan |
| 3883 | prop_type_add('prop', {highlight: 'Likethis', override: true}) |
| 3884 | prop_add(1, 6, {type: 'prop', text: ' inserted '}) |
| 3885 | hi CursorLine cterm=underline ctermbg=lightgrey |
| 3886 | set cursorline |
| 3887 | END |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3888 | call writefile(lines, 'XscriptPropsOverride', 'D') |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3889 | let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60}) |
| 3890 | call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {}) |
| 3891 | |
| 3892 | call term_sendkeys(buf, ":set nocursorline\<CR>") |
| 3893 | call term_sendkeys(buf, "0llvfr") |
| 3894 | call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {}) |
| 3895 | |
| 3896 | call StopVimInTerminal(buf) |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3897 | endfunc |
| 3898 | |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3899 | func Test_props_with_text_CursorMoved() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3900 | CheckScreendump |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3901 | CheckRunVimInTerminal |
| 3902 | |
| 3903 | let lines =<< trim END |
| 3904 | call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five']) |
| 3905 | |
| 3906 | call prop_type_add('prop', #{highlight: 'Error'}) |
| 3907 | let g:long_text = repeat('x', &columns * 2) |
| 3908 | |
| 3909 | let g:prop_id = v:null |
| 3910 | func! Update() |
| 3911 | if line('.') == 1 |
| 3912 | if g:prop_id == v:null |
| 3913 | let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text}) |
| 3914 | endif |
| 3915 | elseif g:prop_id != v:null |
| 3916 | call prop_remove(#{id: g:prop_id}) |
| 3917 | let g:prop_id = v:null |
| 3918 | endif |
| 3919 | endfunc |
| 3920 | |
| 3921 | autocmd CursorMoved * call Update() |
| 3922 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3923 | call writefile(lines, 'XscriptPropsCursorMovec', 'D') |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3924 | let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60}) |
| 3925 | call term_sendkeys(buf, "gg0w") |
| 3926 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {}) |
| 3927 | |
| 3928 | call term_sendkeys(buf, "j") |
| 3929 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {}) |
| 3930 | |
| 3931 | " back to the first state |
| 3932 | call term_sendkeys(buf, "k") |
| 3933 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {}) |
| 3934 | |
| 3935 | call StopVimInTerminal(buf) |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3936 | endfunc |
| 3937 | |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3938 | func Test_props_with_text_after_split_join() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 3939 | CheckScreendump |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3940 | CheckRunVimInTerminal |
| 3941 | |
| 3942 | let lines =<< trim END |
| 3943 | call setline(1, ['1122']) |
| 3944 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 3945 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 3946 | exe "normal f2i\<CR>\<Esc>" |
| 3947 | |
| 3948 | func AddMore() |
| 3949 | call prop_type_add('another', #{highlight: 'Search'}) |
| 3950 | call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'}) |
| 3951 | call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'}) |
| 3952 | endfunc |
| 3953 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3954 | call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D') |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3955 | let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60}) |
| 3956 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {}) |
| 3957 | |
| 3958 | call term_sendkeys(buf, "ggJ") |
| 3959 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {}) |
| 3960 | |
| 3961 | call term_sendkeys(buf, ":call AddMore()\<CR>") |
| 3962 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {}) |
| 3963 | |
| 3964 | call term_sendkeys(buf, "ggf s\<CR>\<Esc>") |
| 3965 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {}) |
| 3966 | |
| 3967 | call term_sendkeys(buf, "ggJ") |
| 3968 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {}) |
| 3969 | |
| 3970 | call StopVimInTerminal(buf) |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3971 | endfunc |
| 3972 | |
Bram Moolenaar | 3a4cd39 | 2022-07-30 22:17:18 +0100 | [diff] [blame] | 3973 | func Test_removed_prop_with_text_cleans_up_array() |
| 3974 | new |
| 3975 | call setline(1, 'some text here') |
| 3976 | call prop_type_add('some', #{highlight: 'ErrorMsg'}) |
| 3977 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 3978 | call assert_equal(-1, id1) |
| 3979 | let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"}) |
| 3980 | call assert_equal(-2, id2) |
| 3981 | |
| 3982 | " removing the props resets the index |
| 3983 | call prop_remove(#{id: id1}) |
| 3984 | call prop_remove(#{id: id2}) |
| 3985 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 3986 | call assert_equal(-1, id1) |
| 3987 | |
| 3988 | call prop_type_delete('some') |
| 3989 | bwipe! |
| 3990 | endfunc |
| 3991 | |
Bram Moolenaar | 1f4ee19 | 2022-08-01 15:52:55 +0100 | [diff] [blame] | 3992 | def Test_insert_text_before_virtual_text() |
| 3993 | new foobar |
| 3994 | setline(1, '12345678') |
| 3995 | prop_type_add('test', {highlight: 'Search'}) |
| 3996 | prop_add(1, 5, { |
| 3997 | type: 'test', |
| 3998 | text: ' virtual text ' |
| 3999 | }) |
| 4000 | normal! f4axyz |
| 4001 | normal! f5iXYZ |
| 4002 | assert_equal('1234xyzXYZ5678', getline(1)) |
| 4003 | |
| 4004 | prop_type_delete('test') |
| 4005 | bwipe! |
| 4006 | enddef |
| 4007 | |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4008 | func Test_insert_text_start_incl() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4009 | CheckScreendump |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4010 | CheckRunVimInTerminal |
| 4011 | |
| 4012 | let lines =<< trim END |
| 4013 | vim9script |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 4014 | setline(1, ['text one text two', '', 'function(arg)']) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4015 | |
| 4016 | prop_type_add('propincl', {highlight: 'NonText', start_incl: true}) |
| 4017 | prop_add(1, 6, {type: 'propincl', text: 'after '}) |
| 4018 | cursor(1, 6) |
| 4019 | prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false}) |
| 4020 | prop_add(1, 15, {type: 'propnotincl', text: 'before '}) |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 4021 | |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 4022 | set cindent sw=4 |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 4023 | prop_type_add('argname', {highlight: 'DiffChange', start_incl: true}) |
| 4024 | prop_add(3, 10, {type: 'argname', text: 'arg: '}) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4025 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 4026 | call writefile(lines, 'XscriptPropsStartIncl', 'D') |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4027 | let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60}) |
| 4028 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {}) |
| 4029 | |
| 4030 | call term_sendkeys(buf, "i") |
| 4031 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {}) |
| 4032 | call term_sendkeys(buf, "xx\<Esc>") |
| 4033 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {}) |
| 4034 | |
| 4035 | call term_sendkeys(buf, "2wi") |
| 4036 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {}) |
| 4037 | call term_sendkeys(buf, "yy\<Esc>") |
| 4038 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {}) |
| 4039 | |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 4040 | call term_sendkeys(buf, "3Gfai\<CR>\<Esc>") |
| 4041 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {}) |
| 4042 | call term_sendkeys(buf, ">>") |
| 4043 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {}) |
| 4044 | call term_sendkeys(buf, "<<<<") |
| 4045 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {}) |
| 4046 | |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4047 | call StopVimInTerminal(buf) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 4048 | endfunc |
| 4049 | |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 4050 | func Test_insert_text_list_mode() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4051 | CheckScreendump |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 4052 | CheckRunVimInTerminal |
| 4053 | |
| 4054 | let lines =<< trim END |
| 4055 | vim9script |
| 4056 | setline(1, ['This is a line with quite a bit of text here.', |
| 4057 | 'second line', 'third line']) |
| 4058 | set list listchars+=extends:Β» |
| 4059 | prop_type_add('Prop1', {highlight: 'Error'}) |
| 4060 | prop_add(1, 0, { |
| 4061 | type: 'Prop1', |
| 4062 | text: 'The quick brown fox jumps over the lazy dog', |
| 4063 | text_align: 'right' |
| 4064 | }) |
| 4065 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 4066 | call writefile(lines, 'XscriptPropsListMode', 'D') |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 4067 | let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60}) |
| 4068 | call term_sendkeys(buf, "ggj") |
| 4069 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {}) |
| 4070 | |
| 4071 | call term_sendkeys(buf, ":set nowrap\<CR>") |
| 4072 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {}) |
| 4073 | |
| 4074 | call term_sendkeys(buf, "ggd32l") |
| 4075 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {}) |
| 4076 | |
| 4077 | call StopVimInTerminal(buf) |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 4078 | endfunc |
| 4079 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 4080 | func Test_insert_text_with_padding() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4081 | CheckScreendump |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 4082 | CheckRunVimInTerminal |
| 4083 | |
| 4084 | let lines =<< trim END |
| 4085 | vim9script |
| 4086 | setline(1, ['Some text to add virtual text to.', |
| 4087 | 'second line', |
| 4088 | 'Another line with some text to make the wrap.']) |
| 4089 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 4090 | prop_add(1, 0, { |
| 4091 | type: 'theprop', |
| 4092 | text: 'after', |
| 4093 | text_align: 'after', |
| 4094 | text_padding_left: 3, |
| 4095 | }) |
| 4096 | prop_add(1, 0, { |
| 4097 | type: 'theprop', |
| 4098 | text: 'right aligned', |
| 4099 | text_align: 'right', |
| 4100 | text_padding_left: 5, |
| 4101 | }) |
| 4102 | prop_add(1, 0, { |
| 4103 | type: 'theprop', |
| 4104 | text: 'below the line', |
| 4105 | text_align: 'below', |
| 4106 | text_padding_left: 4, |
| 4107 | }) |
| 4108 | prop_add(3, 0, { |
| 4109 | type: 'theprop', |
| 4110 | text: 'rightmost', |
| 4111 | text_align: 'right', |
| 4112 | text_padding_left: 6, |
| 4113 | text_wrap: 'wrap', |
| 4114 | }) |
| 4115 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 4116 | call writefile(lines, 'XscriptPropsPadded', 'D') |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 4117 | let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60}) |
| 4118 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {}) |
| 4119 | |
| 4120 | call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>") |
| 4121 | call term_sendkeys(buf, "3Gix\<Esc>") |
| 4122 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {}) |
| 4123 | |
| 4124 | call term_sendkeys(buf, "ggix\<Esc>") |
| 4125 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {}) |
| 4126 | |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 4127 | call term_sendkeys(buf, ":set list\<CR>") |
| 4128 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {}) |
| 4129 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 4130 | call StopVimInTerminal(buf) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 4131 | endfunc |
| 4132 | |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 4133 | func Test_long_text_below_with_padding() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4134 | CheckScreendump |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 4135 | CheckRunVimInTerminal |
| 4136 | |
| 4137 | let lines =<< trim END |
| 4138 | vim9script |
| 4139 | setline(1, ['first line', 'second line']) |
| 4140 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 4141 | prop_add(1, 0, { |
| 4142 | type: 'theprop', |
| 4143 | text: 'after '->repeat(20), |
| 4144 | text_align: 'below', |
| 4145 | text_padding_left: 3, |
| 4146 | }) |
| 4147 | prop_add(1, 0, { |
| 4148 | type: 'theprop', |
| 4149 | text: 'more '->repeat(20), |
| 4150 | text_align: 'below', |
| 4151 | text_padding_left: 30, |
| 4152 | }) |
| 4153 | normal 2Gw |
| 4154 | END |
| 4155 | call writefile(lines, 'XlongTextBelowWithPadding', 'D') |
| 4156 | let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60}) |
| 4157 | call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {}) |
| 4158 | |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 4159 | call term_sendkeys(buf, ":set list\<CR>") |
| 4160 | call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {}) |
| 4161 | |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 4162 | call StopVimInTerminal(buf) |
| 4163 | endfunc |
| 4164 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4165 | func Test_text_after_nowrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4166 | CheckScreendump |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4167 | CheckRunVimInTerminal |
| 4168 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4169 | let lines =<< trim END |
| 4170 | vim9script |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 4171 | setline(1, ['first line', range(80)->join(' '), 'third', 'fourth']) |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4172 | set nowrap |
| 4173 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 4174 | prop_add(1, 0, { |
| 4175 | type: 'theprop', |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 4176 | text: 'right after the text '->repeat(3), |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4177 | text_align: 'after', |
| 4178 | text_padding_left: 2, |
| 4179 | }) |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 4180 | prop_add(1, 0, { |
| 4181 | type: 'theprop', |
| 4182 | text: 'in the middle '->repeat(4), |
| 4183 | text_align: 'after', |
| 4184 | text_padding_left: 3, |
| 4185 | }) |
| 4186 | prop_add(1, 0, { |
| 4187 | type: 'theprop', |
| 4188 | text: 'the last one '->repeat(3), |
| 4189 | text_align: 'after', |
| 4190 | text_padding_left: 1, |
| 4191 | }) |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4192 | normal 2Gw |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 4193 | def g:ChangeText() |
| 4194 | prop_clear(1) |
| 4195 | set list |
| 4196 | prop_add(1, 0, { |
| 4197 | type: 'theprop', |
| 4198 | text: 'just after txt '->repeat(3), |
| 4199 | text_align: 'after', |
| 4200 | text_padding_left: 2, |
| 4201 | }) |
| 4202 | prop_add(1, 0, { |
| 4203 | type: 'theprop', |
| 4204 | text: 'in the middle '->repeat(4), |
| 4205 | text_align: 'after', |
| 4206 | text_padding_left: 1, |
| 4207 | }) |
| 4208 | enddef |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4209 | END |
| 4210 | call writefile(lines, 'XTextAfterNowrap', 'D') |
| 4211 | let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60}) |
| 4212 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {}) |
| 4213 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 4214 | call term_sendkeys(buf, "30w") |
| 4215 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {}) |
| 4216 | |
| 4217 | call term_sendkeys(buf, "22w") |
| 4218 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {}) |
| 4219 | |
| 4220 | call term_sendkeys(buf, "$") |
| 4221 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {}) |
| 4222 | |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 4223 | call term_sendkeys(buf, "0") |
| 4224 | call term_sendkeys(buf, ":call ChangeText()\<CR>") |
| 4225 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {}) |
| 4226 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 4227 | call StopVimInTerminal(buf) |
| 4228 | endfunc |
| 4229 | |
Bram Moolenaar | 02edfaa | 2022-11-18 23:13:47 +0000 | [diff] [blame] | 4230 | func Test_text_after_nowrap_list() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4231 | CheckScreendump |
Bram Moolenaar | 02edfaa | 2022-11-18 23:13:47 +0000 | [diff] [blame] | 4232 | CheckRunVimInTerminal |
| 4233 | |
| 4234 | let lines =<< trim END |
| 4235 | vim9script |
| 4236 | |
| 4237 | set nowrap |
| 4238 | set listchars+=extends:> |
| 4239 | set list |
| 4240 | setline(1, ['some text here', '', 'last line']) |
| 4241 | |
| 4242 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 4243 | prop_add(1, 0, { |
| 4244 | type: 'test', |
| 4245 | text: 'The quick brown fox jumps.', |
| 4246 | text_padding_left: 2, |
| 4247 | }) |
| 4248 | prop_add(1, 0, { |
| 4249 | type: 'test', |
| 4250 | text: 'β The fox jumps over the lazy dog.', |
| 4251 | text_padding_left: 2, |
| 4252 | }) |
| 4253 | prop_add(1, 0, { |
| 4254 | type: 'test', |
| 4255 | text: 'β The lazy dog.', |
| 4256 | text_padding_left: 2, |
| 4257 | }) |
| 4258 | normal 3G$ |
| 4259 | END |
| 4260 | call writefile(lines, 'XTextAfterNowrapList', 'D') |
| 4261 | let buf = RunVimInTerminal('-S XTextAfterNowrapList', #{rows: 6, cols: 60}) |
| 4262 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_list_1', {}) |
| 4263 | |
| 4264 | call StopVimInTerminal(buf) |
| 4265 | endfunc |
| 4266 | |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 4267 | func Test_text_below_nowrap() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4268 | CheckScreendump |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 4269 | CheckRunVimInTerminal |
| 4270 | |
| 4271 | let lines =<< trim END |
| 4272 | vim9script |
| 4273 | setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth']) |
| 4274 | set nowrap number |
| 4275 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 4276 | prop_add(1, 0, { |
| 4277 | type: 'theprop', |
| 4278 | text: 'one below the text '->repeat(5), |
| 4279 | text_align: 'below', |
| 4280 | text_padding_left: 2, |
| 4281 | }) |
| 4282 | prop_add(1, 0, { |
| 4283 | type: 'theprop', |
| 4284 | text: 'two below the text '->repeat(5), |
| 4285 | text_align: 'below', |
| 4286 | text_padding_left: 2, |
| 4287 | }) |
| 4288 | normal 2Gw |
| 4289 | END |
| 4290 | call writefile(lines, 'XTextBelowNowrap', 'D') |
| 4291 | let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60}) |
| 4292 | call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {}) |
| 4293 | |
| 4294 | call StopVimInTerminal(buf) |
| 4295 | endfunc |
| 4296 | |
Dylan Thacker-Smith | 8055721 | 2024-02-21 21:00:59 +0100 | [diff] [blame] | 4297 | func Test_virtual_text_overlap_with_highlight() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4298 | CheckScreendump |
Dylan Thacker-Smith | 8055721 | 2024-02-21 21:00:59 +0100 | [diff] [blame] | 4299 | CheckRunVimInTerminal |
| 4300 | |
| 4301 | let lines =<< trim END |
| 4302 | vim9script |
| 4303 | setline(1, ['one', 'two', 'three', 'four', 'five']) |
| 4304 | set number |
| 4305 | |
| 4306 | prop_type_add('demo_highlight_warning', {highlight: 'WarningMsg'}) |
| 4307 | prop_type_add('demo_virtual_text_error', {highlight: 'Error'}) |
| 4308 | |
| 4309 | prop_add(2, 4, { |
| 4310 | type: 'demo_highlight_warning', |
| 4311 | end_col: 4, |
| 4312 | }) |
| 4313 | prop_add(2, 0, { |
| 4314 | type: 'demo_virtual_text_error', |
| 4315 | text: 'syntax error', |
| 4316 | text_align: 'below', |
| 4317 | }) |
| 4318 | normal 2j |
| 4319 | |
| 4320 | prop_add(4, 4, { |
| 4321 | type: 'demo_highlight_warning', |
| 4322 | end_lnum: 5, |
| 4323 | end_col: 1, |
| 4324 | }) |
| 4325 | prop_add(4, 0, { |
| 4326 | type: 'demo_virtual_text_error', |
| 4327 | text: 'other error', |
| 4328 | text_align: 'right', |
| 4329 | }) |
| 4330 | END |
| 4331 | call writefile(lines, 'XVirtualTextOverlapWithHighlight', 'D') |
| 4332 | let buf = RunVimInTerminal('-S XVirtualTextOverlapWithHighlight', #{rows: 8, cols: 60}) |
| 4333 | call VerifyScreenDump(buf, 'Test_virtual_text_overlap_with_highlight_1', {}) |
| 4334 | |
| 4335 | call StopVimInTerminal(buf) |
| 4336 | endfunc |
| 4337 | |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 4338 | func Test_virtual_text_in_popup_highlight() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4339 | CheckScreendump |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 4340 | CheckRunVimInTerminal |
| 4341 | |
| 4342 | let lines =<< trim END |
| 4343 | vim9script |
| 4344 | |
| 4345 | # foreground highlight only, popup background is used |
| 4346 | prop_type_add('Prop1', {'highlight': 'SpecialKey'}) |
| 4347 | # foreground and background highlight, popup background is not used |
| 4348 | prop_type_add('Prop2', {'highlight': 'DiffDelete'}) |
| 4349 | |
| 4350 | var popupText = [{ |
| 4351 | text: 'Some text', |
| 4352 | props: [ |
| 4353 | { |
| 4354 | col: 1, |
| 4355 | type: 'Prop1', |
| 4356 | text: ' + ' |
| 4357 | }, |
| 4358 | { |
| 4359 | col: 6, |
| 4360 | type: 'Prop2', |
| 4361 | text: ' x ' |
| 4362 | }, |
| 4363 | ] |
| 4364 | }] |
| 4365 | var popupArgs = { |
| 4366 | line: 3, |
| 4367 | col: 20, |
| 4368 | maxwidth: 80, |
| 4369 | highlight: 'PMenu', |
| 4370 | border: [], |
| 4371 | borderchars: [' '], |
| 4372 | } |
| 4373 | |
| 4374 | popup_create(popupText, popupArgs) |
| 4375 | END |
| 4376 | call writefile(lines, 'XscriptVirtualHighlight', 'D') |
| 4377 | let buf = RunVimInTerminal('-S XscriptVirtualHighlight', #{rows: 8}) |
| 4378 | call VerifyScreenDump(buf, 'Test_virtual_text_in_popup_highlight_1', {}) |
| 4379 | |
| 4380 | call StopVimInTerminal(buf) |
| 4381 | endfunc |
| 4382 | |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 4383 | func Test_insert_text_change_arg() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4384 | CheckScreendump |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 4385 | CheckRunVimInTerminal |
| 4386 | |
| 4387 | let lines =<< trim END |
| 4388 | vim9script |
| 4389 | setline(1, ['SetErrorCode( 10, 20 )', 'second line']) |
| 4390 | prop_type_add('param', {highlight: 'DiffChange', start_incl: 1}) |
| 4391 | prop_type_add('padd', {highlight: 'NonText', start_incl: 1}) |
| 4392 | prop_add(1, 15, { |
| 4393 | type: 'param', |
| 4394 | text: 'id:', |
| 4395 | }) |
| 4396 | prop_add(1, 15, { |
| 4397 | type: 'padd', |
| 4398 | text: '-', |
| 4399 | }) |
| 4400 | prop_add(1, 19, { |
| 4401 | type: 'param', |
| 4402 | text: 'id:', |
| 4403 | }) |
| 4404 | prop_add(1, 19, { |
| 4405 | type: 'padd', |
| 4406 | text: '-', |
| 4407 | }) |
| 4408 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 4409 | call writefile(lines, 'XscriptPropsChange', 'D') |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 4410 | let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60}) |
| 4411 | call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {}) |
| 4412 | |
| 4413 | call term_sendkeys(buf, "ggf1cw1234\<Esc>") |
| 4414 | call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {}) |
| 4415 | |
| 4416 | call StopVimInTerminal(buf) |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 4417 | endfunc |
| 4418 | |
Bram Moolenaar | 2f7bfe6 | 2022-11-13 12:54:50 +0000 | [diff] [blame] | 4419 | def Test_textprop_in_quickfix_window() |
| 4420 | enew! |
| 4421 | var prop_type = 'my_prop' |
| 4422 | prop_type_add(prop_type, {}) |
| 4423 | |
| 4424 | for lnum in range(1, 10) |
| 4425 | setline(lnum, 'hello world') |
| 4426 | endfor |
| 4427 | |
| 4428 | cgetbuffer |
| 4429 | copen |
| 4430 | |
| 4431 | var bufnr = bufnr() |
| 4432 | for lnum in range(1, line('$', bufnr->bufwinid())) |
| 4433 | prop_add(lnum, 1, { |
| 4434 | id: 1000 + lnum, |
| 4435 | type: prop_type, |
| 4436 | bufnr: bufnr, |
| 4437 | }) |
| 4438 | endfor |
| 4439 | |
| 4440 | prop_type_delete(prop_type) |
| 4441 | cclose |
| 4442 | bwipe! |
| 4443 | enddef |
| 4444 | |
Bram Moolenaar | 89469d1 | 2022-12-02 20:46:26 +0000 | [diff] [blame] | 4445 | func Test_text_prop_delete_updates() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4446 | CheckScreendump |
Bram Moolenaar | 89469d1 | 2022-12-02 20:46:26 +0000 | [diff] [blame] | 4447 | CheckRunVimInTerminal |
| 4448 | |
| 4449 | let lines =<< trim END |
| 4450 | vim9script |
| 4451 | |
| 4452 | setline(1, ['some text', 'more text', 'the end']) |
| 4453 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 4454 | prop_add(1, 0, { |
| 4455 | type: 'test', |
| 4456 | text: 'The quick brown fox jumps over the lazy dog', |
| 4457 | text_align: 'below', |
| 4458 | text_padding_left: 3, |
| 4459 | }) |
| 4460 | prop_add(1, 0, { |
| 4461 | type: 'test', |
| 4462 | text: 'The quick brown fox jumps over the lazy dog', |
| 4463 | text_align: 'below', |
| 4464 | text_padding_left: 5, |
| 4465 | }) |
| 4466 | |
| 4467 | normal! G |
| 4468 | END |
| 4469 | call writefile(lines, 'XtextPropDelete', 'D') |
| 4470 | let buf = RunVimInTerminal('-S XtextPropDelete', #{rows: 10, cols: 60}) |
| 4471 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_1', {}) |
| 4472 | |
| 4473 | " Check that after deleting the text prop type the text properties using |
| 4474 | " this type no longer show and are not counted for cursor positioning. |
| 4475 | call term_sendkeys(buf, ":call prop_type_delete('test')\<CR>") |
| 4476 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_2', {}) |
| 4477 | |
| 4478 | call term_sendkeys(buf, "ggj") |
| 4479 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_3', {}) |
| 4480 | |
| 4481 | call StopVimInTerminal(buf) |
| 4482 | endfunc |
| 4483 | |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 4484 | func Test_text_prop_diff_mode() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4485 | CheckScreendump |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 4486 | CheckRunVimInTerminal |
| 4487 | |
| 4488 | let lines =<< trim END |
| 4489 | call setline(1, ['9000', '0009', '0009', '9000', '0009']) |
| 4490 | |
| 4491 | let type = 'test' |
| 4492 | call prop_type_add(type, {}) |
| 4493 | let text = '<text>' |
| 4494 | call prop_add(1, 1, {'type': type, 'text': text}) |
| 4495 | call prop_add(2, 0, {'type': type, 'text': text, 'text_align': 'after'}) |
| 4496 | call prop_add(3, 0, {'type': type, 'text': text, 'text_align': 'right'}) |
| 4497 | call prop_add(4, 0, {'type': type, 'text': text, 'text_align': 'above'}) |
| 4498 | call prop_add(5, 0, {'type': type, 'text': text, 'text_align': 'below'}) |
| 4499 | set diff |
| 4500 | |
| 4501 | vnew |
| 4502 | call setline(1, ['000', '000', '000', '000', '000']) |
| 4503 | set diff |
| 4504 | END |
| 4505 | call writefile(lines, 'XtextPropDiff', 'D') |
| 4506 | let buf = RunVimInTerminal('-S XtextPropDiff', #{rows: 10, cols: 60}) |
| 4507 | call VerifyScreenDump(buf, 'Test_prop_diff_mode_1', {}) |
| 4508 | |
| 4509 | call term_sendkeys(buf, ":windo set number\<CR>") |
| 4510 | call VerifyScreenDump(buf, 'Test_prop_diff_mode_2', {}) |
| 4511 | |
| 4512 | call StopVimInTerminal(buf) |
| 4513 | endfunc |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 4514 | |
Bram Moolenaar | 4ce1f99 | 2022-12-19 13:31:06 +0000 | [diff] [blame] | 4515 | func Test_error_when_using_negative_id() |
| 4516 | call prop_type_add('test1', #{highlight: 'ErrorMsg'}) |
| 4517 | call prop_add(1, 1, #{type: 'test1', text: 'virtual'}) |
| 4518 | call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:') |
| 4519 | |
| 4520 | call prop_type_delete('test1') |
| 4521 | endfunc |
| 4522 | |
| 4523 | func Test_error_after_using_negative_id() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4524 | CheckScreendump |
Bram Moolenaar | 4ce1f99 | 2022-12-19 13:31:06 +0000 | [diff] [blame] | 4525 | " This needs to run a separate Vim instance because the |
| 4526 | " "did_use_negative_pop_id" will be set. |
| 4527 | CheckRunVimInTerminal |
| 4528 | |
| 4529 | let lines =<< trim END |
| 4530 | vim9script |
| 4531 | |
| 4532 | setline(1, ['one', 'two', 'three']) |
| 4533 | prop_type_add('test_1', {highlight: 'Error'}) |
| 4534 | prop_type_add('test_2', {highlight: 'WildMenu'}) |
| 4535 | |
| 4536 | prop_add(3, 1, { |
| 4537 | type: 'test_1', |
| 4538 | length: 5, |
| 4539 | id: -1 |
| 4540 | }) |
| 4541 | |
| 4542 | def g:AddTextprop() |
| 4543 | prop_add(1, 0, { |
| 4544 | type: 'test_2', |
| 4545 | text: 'The quick fox', |
| 4546 | text_padding_left: 2 |
| 4547 | }) |
| 4548 | enddef |
| 4549 | END |
| 4550 | call writefile(lines, 'XtextPropError', 'D') |
| 4551 | let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60}) |
| 4552 | call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {}) |
| 4553 | |
| 4554 | call term_sendkeys(buf, ":call AddTextprop()\<CR>") |
| 4555 | call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {}) |
| 4556 | |
| 4557 | call StopVimInTerminal(buf) |
| 4558 | endfunc |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 4559 | |
Ibby | a6ab5e6 | 2023-08-20 20:24:18 +0200 | [diff] [blame] | 4560 | func Test_modify_text_before_prop() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4561 | CheckScreendump |
Ibby | a6ab5e6 | 2023-08-20 20:24:18 +0200 | [diff] [blame] | 4562 | CheckRunVimInTerminal |
| 4563 | |
| 4564 | let lines =<< trim END |
| 4565 | vim9script |
| 4566 | setline(1, ['test_words', 'second line', 'third line', 'fourth line']) |
| 4567 | set number |
| 4568 | prop_type_add('text', {highlight: 'DiffChange'}) |
| 4569 | prop_type_add('below', {highlight: 'NonText'}) |
| 4570 | prop_add(1, 11, {type: 'text', text: repeat('a', 65)}) |
| 4571 | prop_add(1, 0, {type: 'below', text: repeat('a', 65), text_align: 'below'}) |
| 4572 | END |
| 4573 | call writefile(lines, 'XtextPropModifyBefore', 'D') |
| 4574 | let buf = RunVimInTerminal('-S XtextPropModifyBefore', #{rows: 5, cols: 60}) |
| 4575 | call VerifyScreenDump(buf, 'Test_modify_text_before_prop_1', {}) |
| 4576 | |
| 4577 | call term_sendkeys(buf, "xxia\<Esc>") |
| 4578 | call VerifyScreenDump(buf, 'Test_modify_text_before_prop_2', {}) |
| 4579 | |
| 4580 | call StopVimInTerminal(buf) |
| 4581 | endfunc |
| 4582 | |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 4583 | func Test_overlong_textprop_above_crash() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4584 | CheckScreendump |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 4585 | CheckRunVimInTerminal |
Bram Moolenaar | 2f7bfe6 | 2022-11-13 12:54:50 +0000 | [diff] [blame] | 4586 | |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 4587 | let lines =<< trim END |
| 4588 | vim9script |
| 4589 | prop_type_add('PropType', {highlight: 'Error'}) |
| 4590 | setline(1, ['xxx ', 'yyy']) |
| 4591 | prop_add(1, 0, { |
| 4592 | type: 'PropType', |
| 4593 | text: 'the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.', |
| 4594 | text_align: 'above', |
| 4595 | text_wrap: 'wrap', |
| 4596 | }) |
| 4597 | END |
| 4598 | call writefile(lines, 'XtextPropLongAbove', 'D') |
| 4599 | let buf = RunVimInTerminal('-S XtextPropLongAbove', #{rows: 8, cols: 60}) |
| 4600 | call VerifyScreenDump(buf, 'Test_prop_long_above_1', {}) |
| 4601 | |
| 4602 | call StopVimInTerminal(buf) |
| 4603 | endfunc |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 4604 | |
| 4605 | func Test_text_prop_list_hl_and_sign_highlight() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4606 | CheckScreendump |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 4607 | CheckRunVimInTerminal |
| 4608 | |
| 4609 | let lines =<< trim END |
| 4610 | func Test() |
| 4611 | split Xbuffer |
| 4612 | call setline(1, ['one', "\ttab", ' space', 'three', 'four', 'five']) |
| 4613 | call prop_type_add('Prop1', #{highlight: 'Search', override: v:true}) |
| 4614 | sign define sign1 text=>> linehl=DiffAdd |
| 4615 | sign place 10 line=2 name=sign1 |
| 4616 | sign place 20 line=3 name=sign1 |
| 4617 | call prop_add(1, 1, #{end_lnum: 4, end_col: 5, type: 'Prop1'}) |
| 4618 | sign place 30 line=5 name=sign1 |
| 4619 | endfunc |
| 4620 | call Test() |
| 4621 | END |
| 4622 | call writefile(lines, 'XtextPropSignTab', 'D') |
| 4623 | let buf = RunVimInTerminal('-S XtextPropSignTab', #{rows: 8, cols: 60}) |
| 4624 | call VerifyScreenDump(buf, 'Test_prop_sign_tab_1', {}) |
| 4625 | |
| 4626 | call term_sendkeys(buf, ":setl list listchars=eol:ΒΆ,tab:>-\<CR>") |
| 4627 | call VerifyScreenDump(buf, 'Test_prop_sign_tab_2', {}) |
| 4628 | |
| 4629 | call StopVimInTerminal(buf) |
| 4630 | endfunc |
Yegappan Lakshmanan | f9037f1 | 2023-08-20 18:27:45 +0200 | [diff] [blame] | 4631 | |
| 4632 | " Test for getting the virtual text properties |
| 4633 | func Test_virtual_text_get() |
| 4634 | new foobar |
| 4635 | call setline(1, '12345678') |
| 4636 | call prop_type_add('test', #{highlight: 'Search'}) |
| 4637 | call prop_add(1, 2, #{type: 'test', text: ' virtual text1 '}) |
| 4638 | call prop_add(1, 3, #{type: 'test'}) |
| 4639 | call prop_add(1, 0, #{type: 'test', text: ' virtual text2 ', |
| 4640 | \ text_align: 'right'}) |
| 4641 | call prop_add(1, 5, #{type: 'test'}) |
| 4642 | call prop_add(1, 6, #{type: 'test', text: ' virtual text3 ', |
| 4643 | \ text_wrap: 'wrap'}) |
| 4644 | |
| 4645 | let p = prop_list(1, #{end_lnum: -1}) |
| 4646 | call assert_equal( |
Yegappan Lakshmanan | 171c5b9 | 2023-08-22 21:48:50 +0200 | [diff] [blame] | 4647 | \ #{lnum: 1, col: 2, type_bufnr: 0, end: 1, |
| 4648 | \ type: 'test', start: 1, |
Yegappan Lakshmanan | f9037f1 | 2023-08-20 18:27:45 +0200 | [diff] [blame] | 4649 | \ text: ' virtual text1 '}, p[0]) |
| 4650 | call assert_equal( |
| 4651 | \ #{lnum: 1, id: 0, col: 3, type_bufnr: 0, end: 1, |
| 4652 | \ type: 'test', length: 0, start: 1}, p[1]) |
| 4653 | call assert_equal( |
| 4654 | \ #{lnum: 1, id: 0, col: 5, type_bufnr: 0, end: 1, |
| 4655 | \ type: 'test', length: 0, start: 1}, p[2]) |
| 4656 | call assert_equal( |
Yegappan Lakshmanan | 171c5b9 | 2023-08-22 21:48:50 +0200 | [diff] [blame] | 4657 | \ #{lnum: 1, col: 6, type_bufnr: 0, end: 1, type: 'test', |
| 4658 | \ text_wrap: 'wrap', start: 1, text: ' virtual text3 '}, |
Yegappan Lakshmanan | f9037f1 | 2023-08-20 18:27:45 +0200 | [diff] [blame] | 4659 | \ p[3]) |
| 4660 | call assert_equal('right', p[4].text_align) |
| 4661 | |
| 4662 | call prop_type_delete('test') |
| 4663 | bwipe! |
| 4664 | endfunc |
| 4665 | |
Christian Brabandt | 0d0b3b1 | 2023-12-03 17:56:43 +0100 | [diff] [blame] | 4666 | " This used to throw: E967 |
| 4667 | func Test_textprop_notype_join() |
| 4668 | new Xtextprop_no_type_join |
| 4669 | call setline(1, range(1, 3)) |
| 4670 | call cursor(1, 1) |
| 4671 | let name = 'a' |
| 4672 | call prop_type_add(name, {}) |
| 4673 | call prop_add(line('.'), col('.'), { 'type': name }) |
| 4674 | call prop_type_delete(name, {}) |
| 4675 | join |
| 4676 | call assert_equal(["1 2", "3"], getline(1, '$')) |
| 4677 | |
| 4678 | bwipe! |
| 4679 | endfunc |
| 4680 | |
zeertzjq | 7ac1145 | 2024-03-06 20:54:22 +0100 | [diff] [blame] | 4681 | " This was causing text property corruption. |
| 4682 | func Test_textprop_backspace_fo_aw() |
| 4683 | new |
| 4684 | call setline(1, 'foobar') |
| 4685 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 4686 | call prop_add(1, 1, {'type': 'test', 'length': 3}) |
| 4687 | set backspace=indent,eol,start |
| 4688 | setlocal formatoptions+=aw |
| 4689 | call feedkeys("A \<CR>\<BS>\<Esc>", 'tx') |
| 4690 | call assert_equal('foobar', getline(1)) |
| 4691 | call assert_equal([ |
| 4692 | \ #{id: 0, col: 1, start: 1, end: 1, type_bufnr: 0, |
| 4693 | \ type: 'test', length: 3}], prop_list(1)) |
| 4694 | |
| 4695 | bwipe! |
| 4696 | set backspace& |
| 4697 | call prop_type_delete('test') |
| 4698 | endfunc |
| 4699 | |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 4700 | func Test_textprop_with_wincolor() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 4701 | CheckScreendump |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 4702 | CheckRunVimInTerminal |
| 4703 | |
| 4704 | let lines =<< trim END |
| 4705 | call setline(1, 'some text here') |
| 4706 | call setline(2, 'some much longer text here') |
| 4707 | call setline(3, 'more text here') |
| 4708 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 4709 | call prop_type_add('belowprop', #{highlight: 'DiffAdd'}) |
| 4710 | call prop_add(3, 0, #{type: 'afterprop', text: 'AFTER', |
| 4711 | \ text_align: 'after', text_padding_left: 3}) |
| 4712 | call prop_add(1, 0, #{type: 'belowprop', text: 'BELOW', |
| 4713 | \ text_align: 'below', text_padding_left: 3}) |
| 4714 | set wincolor=DiffChange wrap |
| 4715 | END |
| 4716 | call writefile(lines, 'XtextPropWincolor', 'D') |
| 4717 | let buf = RunVimInTerminal('-S XtextPropWincolor', #{rows: 8, cols: 60}) |
| 4718 | |
| 4719 | call term_sendkeys(buf, ":\<CR>") |
| 4720 | call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {}) |
| 4721 | |
| 4722 | call term_sendkeys(buf, ":set cursorline\<CR>:\<CR>") |
| 4723 | call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {}) |
| 4724 | |
| 4725 | call term_sendkeys(buf, ":set nowrap\<CR>:\<CR>") |
| 4726 | call VerifyScreenDump(buf, 'Test_prop_wincolor_2', {}) |
| 4727 | |
| 4728 | call term_sendkeys(buf, ":set nocursorline\<CR>:\<CR>") |
| 4729 | call VerifyScreenDump(buf, 'Test_prop_wincolor_1', {}) |
| 4730 | |
| 4731 | call term_sendkeys(buf, ":set cursorline colorcolumn=30\<CR>:\<CR>") |
| 4732 | call VerifyScreenDump(buf, 'Test_prop_wincolor_3', {}) |
| 4733 | |
| 4734 | call term_sendkeys(buf, ":hi CursorLine ctermbg=Brown\<CR>:\<CR>") |
| 4735 | call VerifyScreenDump(buf, 'Test_prop_wincolor_4', {}) |
| 4736 | |
| 4737 | call term_sendkeys(buf, ":set cursorcolumn\<CR>:\<CR>") |
| 4738 | call term_sendkeys(buf, '$') |
| 4739 | call VerifyScreenDump(buf, 'Test_prop_wincolor_5', {}) |
| 4740 | |
| 4741 | call term_sendkeys(buf, 'j') |
| 4742 | call VerifyScreenDump(buf, 'Test_prop_wincolor_6', {}) |
| 4743 | |
| 4744 | call term_sendkeys(buf, ":set virtualedit=all\<CR>:\<CR>") |
| 4745 | call term_sendkeys(buf, 'l') |
| 4746 | call VerifyScreenDump(buf, 'Test_prop_wincolor_7', {}) |
| 4747 | |
| 4748 | call term_sendkeys(buf, 'k') |
| 4749 | call VerifyScreenDump(buf, 'Test_prop_wincolor_8', {}) |
| 4750 | |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 4751 | if has('rightleft') |
| 4752 | call term_sendkeys(buf, ":set rightleft\<CR>:\<CR>") |
| 4753 | call VerifyScreenDump(buf, 'Test_prop_wincolor_9', {}) |
| 4754 | endif |
| 4755 | |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 4756 | call StopVimInTerminal(buf) |
| 4757 | endfunc |
| 4758 | |
Christian Brabandt | 56b1207 | 2025-05-21 21:01:40 +0200 | [diff] [blame] | 4759 | func Test_textprop_materialize_list() |
| 4760 | let ids = range(3) |
| 4761 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4762 | |
| 4763 | let ids = range(3) + [] |
| 4764 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4765 | |
| 4766 | let ids = range(3) |
| 4767 | let ids[0] = ids[0] |
| 4768 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4769 | |
| 4770 | let ids = range(3) |
| 4771 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4772 | |
| 4773 | call assert_equal([], prop_list(1, #{ids: range(3) + [] })) |
| 4774 | |
| 4775 | let ids = range(3) |
| 4776 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4777 | |
| 4778 | let ids = range(0, 3) |
| 4779 | call assert_equal([], prop_list(1, #{ids: ids})) |
| 4780 | |
| 4781 | call assert_equal([], prop_list(1, #{ids: 3->range()})) |
| 4782 | endfunc |
| 4783 | |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 4784 | " vim: shiftwidth=2 sts=2 expandtab |