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