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:') |
Bram Moolenaar | 4997f2a | 2022-10-13 14:00:45 +0100 | [diff] [blame] | 396 | |
| 397 | " only one error for multiple wrong values |
| 398 | 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] | 399 | call DeletePropTypes() |
| 400 | bw! |
| 401 | endfunc |
| 402 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 403 | func Test_prop_remove() |
| 404 | new |
| 405 | call AddPropTypes() |
| 406 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 407 | let props = Get_expected_props() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 408 | call assert_equal(props, prop_list(1)) |
| 409 | |
| 410 | " remove by id |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 411 | call assert_equal(1, {'id': 12}->prop_remove(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 412 | unlet props[2] |
| 413 | call assert_equal(props, prop_list(1)) |
| 414 | |
| 415 | " remove by type |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 416 | call assert_equal(1, prop_remove({'type': 'one'}, 1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 417 | unlet props[1] |
| 418 | call assert_equal(props, prop_list(1)) |
| 419 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 420 | " remove from unknown buffer |
| 421 | call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:') |
| 422 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 423 | call DeletePropTypes() |
| 424 | bwipe! |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 425 | |
| 426 | new |
| 427 | call AddPropTypes() |
| 428 | call SetupPropsInFirstLine() |
| 429 | call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) |
| 430 | let props = Get_expected_props() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 431 | 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] | 432 | call assert_equal(props, prop_list(1)) |
| 433 | call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) |
| 434 | unlet props[3] |
| 435 | call assert_equal(props, prop_list(1)) |
| 436 | |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 437 | call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:') |
| 438 | call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:') |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 439 | |
| 440 | call DeletePropTypes() |
| 441 | bwipe! |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 442 | |
| 443 | new |
| 444 | call AddPropTypes() |
| 445 | call SetupPropsInFirstLine() |
| 446 | let props = Get_expected_props() " [whole, one, two, three] |
| 447 | call assert_equal(props, prop_list(1)) |
| 448 | |
| 449 | " remove one by types |
| 450 | call assert_equal(1, prop_remove({'types': ['one', 'two', 'three']}, 1)) |
| 451 | unlet props[1] " [whole, two, three] |
| 452 | call assert_equal(props, prop_list(1)) |
| 453 | |
| 454 | " remove 'all' by types |
| 455 | call assert_equal(2, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1)) |
| 456 | unlet props[0] " [two, three] |
| 457 | unlet props[1] " [three] |
| 458 | call assert_equal(props, prop_list(1)) |
| 459 | |
| 460 | " remove none by types |
| 461 | call assert_equal(0, prop_remove({'types': ['three', 'whole'], 'all': 1}, 1)) |
| 462 | call assert_equal(props, prop_list(1)) |
| 463 | |
| 464 | " no types |
| 465 | call assert_fails("call prop_remove({'types': []}, 1)", 'E968:') |
| 466 | call assert_fails("call prop_remove({'types': ['not_a_real_type']}, 1)", 'E971:') |
| 467 | |
| 468 | " only one of types and type can be supplied |
| 469 | call assert_fails("call prop_remove({'type': 'one', 'types': ['three'], 'all': 1}, 1)", 'E1295:') |
| 470 | |
| 471 | call DeletePropTypes() |
| 472 | bwipe! |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 473 | endfunc |
| 474 | |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 475 | def Test_prop_add_vim9() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 476 | prop_type_add('comment', { |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 477 | highlight: 'Directory', |
| 478 | priority: 123, |
| 479 | start_incl: true, |
| 480 | end_incl: true, |
| 481 | combine: false, |
| 482 | }) |
| 483 | prop_type_delete('comment') |
| 484 | enddef |
| 485 | |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 486 | def Test_prop_remove_vim9() |
| 487 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 488 | g:AddPropTypes() |
| 489 | g:SetupPropsInFirstLine() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 490 | 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] | 491 | g:DeletePropTypes() |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 492 | bwipe! |
| 493 | enddef |
| 494 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 495 | func SetupOneLine() |
| 496 | call setline(1, 'xonex xtwoxx') |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 497 | normal gg0 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 498 | call AddPropTypes() |
| 499 | call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) |
| 500 | call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) |
| 501 | let expected = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 502 | \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 503 | \ #{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] | 504 | \] |
| 505 | call assert_equal(expected, prop_list(1)) |
| 506 | return expected |
| 507 | endfunc |
| 508 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 509 | func Test_prop_add_remove_buf() |
| 510 | new |
| 511 | let bufnr = bufnr('') |
| 512 | call AddPropTypes() |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 513 | for lnum in range(1, 4) |
| 514 | call setline(lnum, 'one two three') |
| 515 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 516 | wincmd w |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 517 | for lnum in range(1, 4) |
| 518 | call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) |
| 519 | call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) |
| 520 | call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) |
| 521 | endfor |
| 522 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 523 | let props = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 524 | \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 525 | \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
| 526 | \ #{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] | 527 | \] |
| 528 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 529 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 530 | " remove by id |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 531 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 532 | unlet props[1] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 533 | |
| 534 | call prop_remove({'id': 12, 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 535 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 536 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 537 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 538 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 539 | |
| 540 | call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4) |
| 541 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 542 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 543 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 544 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 545 | |
| 546 | call prop_remove({'id': 12, 'bufnr': bufnr}) |
| 547 | for lnum in range(1, 4) |
| 548 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 549 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 550 | |
| 551 | " remove by type |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 552 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 553 | unlet props[0] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 554 | |
| 555 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 556 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 557 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 558 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 559 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 560 | |
| 561 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4) |
| 562 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 563 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 564 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 565 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 566 | |
| 567 | call prop_remove({'type': 'one', 'bufnr': bufnr}) |
| 568 | for lnum in range(1, 4) |
| 569 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 570 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 571 | |
| 572 | call DeletePropTypes() |
| 573 | wincmd w |
| 574 | bwipe! |
| 575 | endfunc |
| 576 | |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 577 | func Test_prop_backspace() |
| 578 | new |
| 579 | set bs=2 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 580 | let expected = SetupOneLine() " 'xonex xtwoxx' |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 581 | |
| 582 | exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" |
| 583 | call assert_equal('one xtwoxx', getline(1)) |
| 584 | let expected[0].col = 1 |
| 585 | let expected[1].col = 6 |
| 586 | call assert_equal(expected, prop_list(1)) |
| 587 | |
| 588 | call DeletePropTypes() |
| 589 | bwipe! |
| 590 | set bs& |
| 591 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 592 | |
LemonBoy | d0b1a09 | 2022-05-12 18:45:18 +0100 | [diff] [blame] | 593 | func Test_prop_change() |
| 594 | new |
| 595 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 596 | |
| 597 | " Characterwise. |
| 598 | exe "normal 7|c$\<Esc>" |
| 599 | call assert_equal('xonex ', getline(1)) |
| 600 | call assert_equal(expected[:0], prop_list(1)) |
| 601 | " Linewise. |
| 602 | exe "normal cc\<Esc>" |
| 603 | call assert_equal('', getline(1)) |
| 604 | call assert_equal([], prop_list(1)) |
| 605 | |
| 606 | call DeletePropTypes() |
| 607 | bwipe! |
| 608 | set bs& |
| 609 | endfunc |
| 610 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 611 | func Test_prop_replace() |
| 612 | new |
| 613 | set bs=2 |
| 614 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 615 | |
| 616 | exe "normal 0Ryyy\<Esc>" |
| 617 | call assert_equal('yyyex xtwoxx', getline(1)) |
| 618 | call assert_equal(expected, prop_list(1)) |
| 619 | |
| 620 | exe "normal ftRyy\<BS>" |
| 621 | call assert_equal('yyyex xywoxx', getline(1)) |
| 622 | call assert_equal(expected, prop_list(1)) |
| 623 | |
| 624 | exe "normal 0fwRyy\<BS>" |
| 625 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 626 | call assert_equal(expected, prop_list(1)) |
| 627 | |
| 628 | exe "normal 0foRyy\<BS>\<BS>" |
| 629 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 630 | call assert_equal(expected, prop_list(1)) |
| 631 | |
LemonBoy | 0d534d9 | 2022-05-21 11:20:42 +0100 | [diff] [blame] | 632 | " Replace three 1-byte chars with three 2-byte ones. |
| 633 | exe "normal 0l3rø" |
| 634 | call assert_equal('yøøøx xyyoxx', getline(1)) |
| 635 | let expected[0].length += 3 |
| 636 | let expected[1].col += 3 |
| 637 | call assert_equal(expected, prop_list(1)) |
| 638 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 639 | call DeletePropTypes() |
| 640 | bwipe! |
| 641 | set bs& |
| 642 | endfunc |
| 643 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 644 | func Test_prop_open_line() |
| 645 | new |
| 646 | |
| 647 | " open new line, props stay in top line |
| 648 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 649 | exe "normal o\<Esc>" |
| 650 | call assert_equal('xonex xtwoxx', getline(1)) |
| 651 | call assert_equal('', getline(2)) |
| 652 | call assert_equal(expected, prop_list(1)) |
| 653 | call DeletePropTypes() |
| 654 | |
| 655 | " move all props to next line |
| 656 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 657 | exe "normal 0i\<CR>\<Esc>" |
| 658 | call assert_equal('', getline(1)) |
| 659 | call assert_equal('xonex xtwoxx', getline(2)) |
| 660 | call assert_equal(expected, prop_list(2)) |
| 661 | call DeletePropTypes() |
| 662 | |
| 663 | " split just before prop, move all props to next line |
| 664 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 665 | exe "normal 0li\<CR>\<Esc>" |
| 666 | call assert_equal('x', getline(1)) |
| 667 | call assert_equal('onex xtwoxx', getline(2)) |
| 668 | let expected[0].col -= 1 |
| 669 | let expected[1].col -= 1 |
| 670 | call assert_equal(expected, prop_list(2)) |
| 671 | call DeletePropTypes() |
| 672 | |
| 673 | " split inside prop, split first prop |
| 674 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 675 | exe "normal 0lli\<CR>\<Esc>" |
| 676 | call assert_equal('xo', getline(1)) |
| 677 | call assert_equal('nex xtwoxx', getline(2)) |
| 678 | let exp_first = [deepcopy(expected[0])] |
| 679 | let exp_first[0].length = 1 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 680 | let exp_first[0].end = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 681 | call assert_equal(exp_first, prop_list(1)) |
| 682 | let expected[0].col = 1 |
| 683 | let expected[0].length = 2 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 684 | let expected[0].start = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 685 | let expected[1].col -= 2 |
| 686 | call assert_equal(expected, prop_list(2)) |
| 687 | call DeletePropTypes() |
| 688 | |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 689 | " split just after first prop, second prop move to next line |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 690 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 691 | exe "normal 0fea\<CR>\<Esc>" |
| 692 | call assert_equal('xone', getline(1)) |
| 693 | call assert_equal('x xtwoxx', getline(2)) |
| 694 | let exp_first = expected[0:0] |
| 695 | call assert_equal(exp_first, prop_list(1)) |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 696 | let expected = expected[1:1] |
| 697 | let expected[0].col -= 4 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 698 | call assert_equal(expected, prop_list(2)) |
| 699 | call DeletePropTypes() |
| 700 | |
LemonBoy | 788c06a | 2022-05-14 18:48:05 +0100 | [diff] [blame] | 701 | " split at the space character with 'ai' active, the leading space is removed |
| 702 | " in the second line and the prop is shifted accordingly. |
| 703 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 704 | set ai |
| 705 | exe "normal 6|i\<CR>\<Esc>" |
| 706 | call assert_equal('xonex', getline(1)) |
| 707 | call assert_equal('xtwoxx', getline(2)) |
| 708 | let expected[1].col -= 6 |
| 709 | call assert_equal(expected, prop_list(1) + prop_list(2)) |
| 710 | set ai& |
| 711 | call DeletePropTypes() |
| 712 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 713 | bwipe! |
| 714 | set bs& |
| 715 | endfunc |
| 716 | |
Bram Moolenaar | ecb00c7 | 2022-08-07 14:55:14 +0100 | [diff] [blame] | 717 | func Test_prop_put() |
| 718 | new |
| 719 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 720 | |
| 721 | let @a = 'new' |
| 722 | " insert just after the prop |
| 723 | normal 03l"ap |
| 724 | " insert inside the prop |
| 725 | normal 02l"ap |
| 726 | " insert just before the prop |
| 727 | normal 0"ap |
| 728 | |
| 729 | call assert_equal('xnewonnewenewx xtwoxx', getline(1)) |
| 730 | let expected[0].col += 3 |
| 731 | let expected[0].length += 3 |
| 732 | let expected[1].col += 9 |
| 733 | call assert_equal(expected, prop_list(1)) |
| 734 | |
| 735 | " Visually select 4 chars in the prop and put "AB" to replace them |
| 736 | let @a = 'AB' |
| 737 | normal 05lv3l"ap |
| 738 | call assert_equal('xnewoABenewx xtwoxx', getline(1)) |
| 739 | let expected[0].length -= 2 |
| 740 | let expected[1].col -= 2 |
| 741 | call assert_equal(expected, prop_list(1)) |
| 742 | |
| 743 | call DeletePropTypes() |
| 744 | bwipe! |
| 745 | endfunc |
| 746 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 747 | func Test_prop_clear() |
| 748 | new |
| 749 | call AddPropTypes() |
| 750 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 751 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 752 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 753 | eval 1->prop_clear() |
| 754 | call assert_equal([], 1->prop_list()) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 755 | |
| 756 | call DeletePropTypes() |
| 757 | bwipe! |
| 758 | endfunc |
| 759 | |
| 760 | func Test_prop_clear_buf() |
| 761 | new |
| 762 | call AddPropTypes() |
| 763 | call SetupPropsInFirstLine() |
| 764 | let bufnr = bufnr('') |
| 765 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 766 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 767 | |
| 768 | call prop_clear(1, 1, {'bufnr': bufnr}) |
| 769 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 770 | |
| 771 | wincmd w |
| 772 | call DeletePropTypes() |
| 773 | bwipe! |
| 774 | endfunc |
| 775 | |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 776 | func Test_prop_setline() |
| 777 | new |
| 778 | call AddPropTypes() |
| 779 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 780 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 781 | |
| 782 | call setline(1, 'foobar') |
| 783 | call assert_equal([], prop_list(1)) |
| 784 | |
| 785 | call DeletePropTypes() |
| 786 | bwipe! |
| 787 | endfunc |
| 788 | |
| 789 | func Test_prop_setbufline() |
| 790 | new |
| 791 | call AddPropTypes() |
| 792 | call SetupPropsInFirstLine() |
| 793 | let bufnr = bufnr('') |
| 794 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 795 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 796 | |
| 797 | call setbufline(bufnr, 1, 'foobar') |
| 798 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 799 | |
| 800 | wincmd w |
| 801 | call DeletePropTypes() |
| 802 | bwipe! |
| 803 | endfunc |
| 804 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 805 | func Test_prop_substitute() |
| 806 | new |
| 807 | " Set first line to 'one two three' |
| 808 | call AddPropTypes() |
| 809 | call SetupPropsInFirstLine() |
| 810 | let expected_props = Get_expected_props() |
| 811 | call assert_equal(expected_props, prop_list(1)) |
| 812 | |
| 813 | " Change "n" in "one" to XX: 'oXXe two three' |
| 814 | s/n/XX/ |
| 815 | let expected_props[0].length += 1 |
| 816 | let expected_props[1].length += 1 |
| 817 | let expected_props[2].col += 1 |
| 818 | let expected_props[3].col += 1 |
| 819 | call assert_equal(expected_props, prop_list(1)) |
| 820 | |
| 821 | " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' |
| 822 | s/t//g |
| 823 | let expected_props[0].length -= 2 |
| 824 | let expected_props[2].length -= 1 |
| 825 | let expected_props[3].length -= 1 |
| 826 | let expected_props[3].col -= 1 |
| 827 | call assert_equal(expected_props, prop_list(1)) |
| 828 | |
| 829 | " Split the line by changing w to line break: 'oXXe ', 'o hree' |
| 830 | " The long prop is split and spans both lines. |
| 831 | " The props on "two" and "three" move to the next line. |
| 832 | s/w/\r/ |
| 833 | let new_props = [ |
| 834 | \ copy(expected_props[0]), |
| 835 | \ copy(expected_props[2]), |
| 836 | \ copy(expected_props[3]), |
| 837 | \ ] |
| 838 | let expected_props[0].length = 5 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 839 | let expected_props[0].end = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 840 | unlet expected_props[3] |
| 841 | unlet expected_props[2] |
| 842 | call assert_equal(expected_props, prop_list(1)) |
| 843 | |
| 844 | let new_props[0].length = 6 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 845 | let new_props[0].start = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 846 | let new_props[1].col = 1 |
| 847 | let new_props[1].length = 1 |
| 848 | let new_props[2].col = 3 |
| 849 | call assert_equal(new_props, prop_list(2)) |
| 850 | |
| 851 | call DeletePropTypes() |
| 852 | bwipe! |
| 853 | endfunc |
| 854 | |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 855 | func Test_prop_change_indent() |
| 856 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 857 | new |
| 858 | call setline(1, [' xxx', 'yyyyy']) |
| 859 | call prop_add(2, 2, {'length': 2, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 860 | 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] | 861 | call assert_equal([expect], prop_list(2)) |
| 862 | |
| 863 | set shiftwidth=3 |
| 864 | normal 2G>> |
| 865 | call assert_equal(' yyyyy', getline(2)) |
| 866 | let expect.col += 3 |
| 867 | call assert_equal([expect], prop_list(2)) |
| 868 | |
| 869 | normal 2G== |
| 870 | call assert_equal(' yyyyy', getline(2)) |
| 871 | let expect.col = 6 |
| 872 | call assert_equal([expect], prop_list(2)) |
| 873 | |
| 874 | call prop_clear(2) |
| 875 | call prop_add(2, 2, {'length': 5, 'type': 'comment'}) |
| 876 | let expect.col = 2 |
| 877 | let expect.length = 5 |
| 878 | call assert_equal([expect], prop_list(2)) |
| 879 | |
| 880 | normal 2G<< |
| 881 | call assert_equal(' yyyyy', getline(2)) |
| 882 | let expect.length = 2 |
| 883 | call assert_equal([expect], prop_list(2)) |
| 884 | |
| 885 | set shiftwidth& |
| 886 | call prop_type_delete('comment') |
| 887 | endfunc |
| 888 | |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 889 | " Setup a three line prop in lines 2 - 4. |
| 890 | " Add short props in line 1 and 5. |
| 891 | func Setup_three_line_prop() |
| 892 | new |
| 893 | call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) |
| 894 | call prop_add(1, 2, {'length': 1, 'type': 'comment'}) |
| 895 | call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) |
| 896 | call prop_add(5, 2, {'length': 1, 'type': 'comment'}) |
| 897 | endfunc |
| 898 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 899 | func Test_prop_multiline() |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 900 | eval 'comment'->prop_type_add({'highlight': 'Directory'}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 901 | new |
| 902 | call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) |
| 903 | |
| 904 | " start halfway line 1, end halfway line 3 |
| 905 | 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] | 906 | 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] | 907 | call assert_equal([expect1], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 908 | 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] | 909 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 910 | 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] | 911 | call assert_equal([expect3], prop_list(3)) |
| 912 | call prop_clear(1, 3) |
| 913 | |
| 914 | " include all three lines |
| 915 | call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) |
| 916 | let expect1.col = 1 |
| 917 | let expect1.length = 8 |
| 918 | call assert_equal([expect1], prop_list(1)) |
| 919 | call assert_equal([expect2], prop_list(2)) |
| 920 | let expect3.length = 9 |
| 921 | call assert_equal([expect3], prop_list(3)) |
| 922 | call prop_clear(1, 3) |
| 923 | |
| 924 | bwipe! |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 925 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 926 | " Test deleting the first line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 927 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 928 | 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] | 929 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 930 | 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] | 931 | call assert_equal([expect2], prop_list(2)) |
| 932 | 2del |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 933 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 934 | 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] | 935 | call assert_equal([expect2], prop_list(2)) |
| 936 | bwipe! |
| 937 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 938 | " Test deleting the last line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 939 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 940 | 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] | 941 | call assert_equal([expect3], prop_list(3)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 942 | 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] | 943 | call assert_equal([expect4], prop_list(4)) |
| 944 | 4del |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 945 | let expect3.end = 1 |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 946 | call assert_equal([expect3], prop_list(3)) |
| 947 | call assert_equal([expect_short], prop_list(4)) |
| 948 | bwipe! |
| 949 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 950 | " Test appending a line below the multi-line text prop start. |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 951 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 952 | 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] | 953 | call assert_equal([expect2], prop_list(2)) |
| 954 | call append(2, "new line") |
| 955 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 956 | 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] | 957 | call assert_equal([expect3], prop_list(3)) |
| 958 | bwipe! |
| 959 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 960 | call prop_type_delete('comment') |
| 961 | endfunc |
| 962 | |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 963 | func Run_test_with_line2byte(add_props) |
| 964 | new |
| 965 | setlocal ff=unix |
| 966 | if a:add_props |
| 967 | call prop_type_add('textprop', #{highlight: 'Search'}) |
| 968 | endif |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 969 | " Add a text prop to every fourth line and then change every fifth line so |
| 970 | " that it causes a data block split a few times. |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 971 | for nr in range(1, 1000) |
| 972 | call setline(nr, 'some longer text here') |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 973 | if a:add_props && nr % 4 == 0 |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 974 | call prop_add(nr, 13, #{type: 'textprop', length: 4}) |
| 975 | endif |
| 976 | endfor |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 977 | let expected = 22 * 997 + 1 |
| 978 | call assert_equal(expected, line2byte(998)) |
| 979 | |
| 980 | for nr in range(1, 1000, 5) |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 981 | exe nr .. "s/longer/much more/" |
Bram Moolenaar | e5a0e8c | 2022-08-09 21:37:55 +0100 | [diff] [blame] | 982 | let expected += 3 |
| 983 | call assert_equal(expected, line2byte(998), 'line ' .. nr) |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 984 | endfor |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 985 | |
| 986 | if a:add_props |
| 987 | call prop_type_delete('textprop') |
| 988 | endif |
| 989 | bwipe! |
| 990 | endfunc |
| 991 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 992 | func Test_prop_line2byte() |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 993 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 994 | new |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 995 | call setline(1, ['line1', 'second line', '']) |
Bram Moolenaar | 8cf734e | 2018-12-26 01:09:00 +0100 | [diff] [blame] | 996 | set ff=unix |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 997 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 998 | call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) |
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 | bwipe! |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 1001 | |
| 1002 | new |
Bram Moolenaar | a401bba | 2021-08-15 15:04:41 +0200 | [diff] [blame] | 1003 | setlocal ff=unix |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 1004 | call setline(1, range(500)) |
| 1005 | call assert_equal(1491, line2byte(401)) |
| 1006 | call prop_add(2, 1, {'type': 'comment'}) |
| 1007 | call prop_add(222, 1, {'type': 'comment'}) |
| 1008 | call assert_equal(1491, line2byte(401)) |
| 1009 | call prop_remove({'type': 'comment'}) |
| 1010 | call assert_equal(1491, line2byte(401)) |
| 1011 | bwipe! |
| 1012 | |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 1013 | new |
Bram Moolenaar | 49b9304 | 2021-08-25 17:02:00 +0200 | [diff] [blame] | 1014 | setlocal ff=unix |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 1015 | call setline(1, range(520)) |
| 1016 | call assert_equal(1491, line2byte(401)) |
| 1017 | call prop_add(2, 1, {'type': 'comment'}) |
| 1018 | call assert_equal(1491, line2byte(401)) |
| 1019 | 2delete |
| 1020 | call assert_equal(1489, line2byte(400)) |
| 1021 | bwipe! |
| 1022 | |
Bram Moolenaar | cf85d97 | 2022-08-08 14:59:47 +0100 | [diff] [blame] | 1023 | " Add many lines so that the data block is split. |
| 1024 | " With and without props should give the same result. |
| 1025 | call Run_test_with_line2byte(0) |
| 1026 | call Run_test_with_line2byte(1) |
| 1027 | |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 1028 | call prop_type_delete('comment') |
| 1029 | endfunc |
| 1030 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 1031 | func Test_prop_byte2line() |
| 1032 | new |
| 1033 | set ff=unix |
| 1034 | call setline(1, ['one one', 'two two', 'three three', 'four four', 'five']) |
| 1035 | call assert_equal(4, byte2line(line2byte(4))) |
| 1036 | call assert_equal(5, byte2line(line2byte(5))) |
| 1037 | |
| 1038 | call prop_type_add('prop', {'highlight': 'Directory'}) |
| 1039 | call prop_add(3, 1, {'length': 5, 'type': 'prop'}) |
| 1040 | call assert_equal(4, byte2line(line2byte(4))) |
| 1041 | call assert_equal(5, byte2line(line2byte(5))) |
| 1042 | |
| 1043 | bwipe! |
| 1044 | call prop_type_delete('prop') |
| 1045 | endfunc |
| 1046 | |
Bram Moolenaar | 59ff640 | 2021-01-30 17:16:28 +0100 | [diff] [blame] | 1047 | func Test_prop_goto_byte() |
| 1048 | new |
| 1049 | call setline(1, '') |
| 1050 | call setline(2, 'two three') |
| 1051 | call setline(3, '') |
| 1052 | call setline(4, 'four five') |
| 1053 | |
| 1054 | call prop_type_add('testprop', {'highlight': 'Directory'}) |
| 1055 | call search('^two') |
| 1056 | call prop_add(line('.'), col('.'), { |
| 1057 | \ 'length': len('two'), |
| 1058 | \ 'type': 'testprop' |
| 1059 | \ }) |
| 1060 | |
| 1061 | call search('two \zsthree') |
| 1062 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 1063 | exe expected_pos .. 'goto' |
| 1064 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 1065 | eval actual_pos->assert_equal(expected_pos) |
| 1066 | |
| 1067 | call search('four \zsfive') |
| 1068 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 1069 | exe expected_pos .. 'goto' |
| 1070 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 1071 | eval actual_pos->assert_equal(expected_pos) |
| 1072 | |
| 1073 | call prop_type_delete('testprop') |
| 1074 | bwipe! |
| 1075 | endfunc |
| 1076 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1077 | func Test_prop_undo() |
| 1078 | new |
| 1079 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 1080 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 1081 | " Set 'undolevels' to break changes into undo-able pieces. |
| 1082 | set ul& |
| 1083 | |
| 1084 | call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1085 | 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] | 1086 | call assert_equal(expected, prop_list(1)) |
| 1087 | |
| 1088 | " Insert a character, then undo. |
| 1089 | exe "normal 0lllix\<Esc>" |
| 1090 | set ul& |
| 1091 | let expected[0].length = 3 |
| 1092 | call assert_equal(expected, prop_list(1)) |
| 1093 | undo |
| 1094 | let expected[0].length = 2 |
| 1095 | call assert_equal(expected, prop_list(1)) |
| 1096 | |
| 1097 | " Delete a character, then undo |
| 1098 | exe "normal 0lllx" |
| 1099 | set ul& |
| 1100 | let expected[0].length = 1 |
| 1101 | call assert_equal(expected, prop_list(1)) |
| 1102 | undo |
| 1103 | let expected[0].length = 2 |
| 1104 | call assert_equal(expected, prop_list(1)) |
| 1105 | |
| 1106 | " Delete the line, then undo |
| 1107 | 1d |
| 1108 | set ul& |
| 1109 | call assert_equal([], prop_list(1)) |
| 1110 | undo |
| 1111 | call assert_equal(expected, prop_list(1)) |
| 1112 | |
| 1113 | " Insert a character, delete two characters, then undo with "U" |
| 1114 | exe "normal 0lllix\<Esc>" |
| 1115 | set ul& |
| 1116 | let expected[0].length = 3 |
| 1117 | call assert_equal(expected, prop_list(1)) |
| 1118 | exe "normal 0lllxx" |
| 1119 | set ul& |
| 1120 | let expected[0].length = 1 |
| 1121 | call assert_equal(expected, prop_list(1)) |
| 1122 | normal U |
| 1123 | let expected[0].length = 2 |
| 1124 | call assert_equal(expected, prop_list(1)) |
| 1125 | |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1126 | " substitute a word, then undo |
| 1127 | call setline(1, 'the number 123 is highlighted.') |
| 1128 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1129 | 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] | 1130 | call assert_equal(expected, prop_list(1)) |
| 1131 | set ul& |
| 1132 | 1s/number/foo |
| 1133 | let expected[0].col = 9 |
| 1134 | call assert_equal(expected, prop_list(1)) |
| 1135 | undo |
| 1136 | let expected[0].col = 12 |
| 1137 | call assert_equal(expected, prop_list(1)) |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 1138 | call prop_clear(1) |
| 1139 | |
| 1140 | " substitute with backslash |
| 1141 | call setline(1, 'the number 123 is highlighted.') |
| 1142 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1143 | 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] | 1144 | call assert_equal(expected, prop_list(1)) |
| 1145 | 1s/the/\The |
| 1146 | call assert_equal(expected, prop_list(1)) |
| 1147 | 1s/^/\\ |
| 1148 | let expected[0].col += 1 |
| 1149 | call assert_equal(expected, prop_list(1)) |
| 1150 | 1s/^/\~ |
| 1151 | let expected[0].col += 1 |
| 1152 | call assert_equal(expected, prop_list(1)) |
| 1153 | 1s/123/12\\3 |
| 1154 | let expected[0].length += 1 |
| 1155 | call assert_equal(expected, prop_list(1)) |
| 1156 | call prop_clear(1) |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1157 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1158 | bwipe! |
| 1159 | call prop_type_delete('comment') |
| 1160 | endfunc |
| 1161 | |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1162 | func Test_prop_delete_text() |
| 1163 | new |
| 1164 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 1165 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 1166 | |
| 1167 | " zero length property |
| 1168 | call prop_add(1, 3, {'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1169 | 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] | 1170 | call assert_equal(expected, prop_list(1)) |
| 1171 | |
| 1172 | " delete one char moves the property |
| 1173 | normal! x |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1174 | 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] | 1175 | call assert_equal(expected, prop_list(1)) |
| 1176 | |
| 1177 | " delete char of the property has no effect |
| 1178 | normal! lx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1179 | 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] | 1180 | call assert_equal(expected, prop_list(1)) |
| 1181 | |
| 1182 | " delete more chars moves property to first column, is not deleted |
| 1183 | normal! 0xxxx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1184 | 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] | 1185 | call assert_equal(expected, prop_list(1)) |
| 1186 | |
| 1187 | bwipe! |
| 1188 | call prop_type_delete('comment') |
| 1189 | endfunc |
| 1190 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1191 | " screenshot test with textprop highlighting |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1192 | func Test_textprop_screenshot_various() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1193 | CheckScreendump |
Bram Moolenaar | ed79d1e | 2019-02-22 14:38:58 +0100 | [diff] [blame] | 1194 | " The Vim running in the terminal needs to use utf-8. |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1195 | if g:orig_encoding != 'utf-8' |
| 1196 | throw 'Skipped: not using utf-8' |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1197 | endif |
| 1198 | call writefile([ |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1199 | \ "call setline(1, [" |
| 1200 | \ .. "'One two'," |
| 1201 | \ .. "'Numbér 123 änd thœn 4¾7.'," |
| 1202 | \ .. "'--aa--bb--cc--dd--'," |
| 1203 | \ .. "'// comment with error in it'," |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1204 | \ .. "'first line'," |
| 1205 | \ .. "' second line '," |
| 1206 | \ .. "'third line'," |
| 1207 | \ .. "' fourth line'," |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1208 | \ .. "])", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1209 | \ "hi NumberProp ctermfg=blue", |
| 1210 | \ "hi LongProp ctermbg=yellow", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1211 | \ "hi BackgroundProp ctermbg=lightgrey", |
| 1212 | \ "hi UnderlineProp cterm=underline", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1213 | \ "call prop_type_add('number', {'highlight': 'NumberProp'})", |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 1214 | \ "call prop_type_add('long', {'highlight': 'NumberProp'})", |
| 1215 | \ "call prop_type_change('long', {'highlight': 'LongProp'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1216 | \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", |
| 1217 | \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", |
| 1218 | \ "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] | 1219 | \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})", |
| 1220 | \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})", |
| 1221 | \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})", |
Bram Moolenaar | 58e32ab | 2019-11-12 22:44:22 +0100 | [diff] [blame] | 1222 | \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1223 | \ "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] | 1224 | \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", |
| 1225 | \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1226 | \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", |
| 1227 | \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", |
| 1228 | \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", |
| 1229 | \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1230 | \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})", |
| 1231 | \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1232 | \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1233 | \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})", |
| 1234 | \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})", |
| 1235 | \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})", |
| 1236 | \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})", |
Bram Moolenaar | bfd4512 | 2019-05-17 13:05:07 +0200 | [diff] [blame] | 1237 | \ "set number cursorline", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 1238 | \ "hi clear SpellBad", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1239 | \ "set spell", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1240 | \ "syn match Comment '//.*'", |
| 1241 | \ "hi Comment ctermfg=green", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1242 | \ "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] | 1243 | \ "normal 3G0lli\<BS>\<Esc>", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1244 | \ "normal 6G0i\<BS>\<Esc>", |
| 1245 | \ "normal 3J", |
| 1246 | \ "normal 3G", |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1247 | \], 'XtestProp', 'D') |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1248 | let buf = RunVimInTerminal('-S XtestProp', {'rows': 8}) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1249 | call VerifyScreenDump(buf, 'Test_textprop_01', {}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 1250 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1251 | " clean up |
| 1252 | call StopVimInTerminal(buf) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1253 | endfunc |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1254 | |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1255 | func Test_textprop_hl_override() |
| 1256 | CheckScreendump |
| 1257 | |
| 1258 | let lines =<< trim END |
| 1259 | call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three']) |
| 1260 | hi OverProp ctermfg=blue ctermbg=yellow |
| 1261 | hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green |
| 1262 | hi Vsual ctermfg=cyan ctermbg=grey |
| 1263 | call prop_type_add('under', #{highlight: 'OverProp'}) |
| 1264 | call prop_type_add('over', #{highlight: 'OverProp', override: 1}) |
| 1265 | call prop_add(1, 5, #{type: 'under', length: 4}) |
| 1266 | call prop_add(1, 13, #{type: 'over', length: 4}) |
| 1267 | call prop_add(2, 5, #{type: 'under', length: 4}) |
| 1268 | call prop_add(2, 13, #{type: 'over', length: 4}) |
| 1269 | call prop_add(3, 5, #{type: 'under', length: 4}) |
| 1270 | call prop_add(3, 13, #{type: 'over', length: 4}) |
| 1271 | set cursorline |
| 1272 | 2 |
| 1273 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1274 | call writefile(lines, 'XtestOverProp', 'D') |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1275 | let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8}) |
| 1276 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {}) |
| 1277 | |
| 1278 | call term_sendkeys(buf, "3Gllv$hh") |
| 1279 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {}) |
| 1280 | call term_sendkeys(buf, "\<Esc>") |
| 1281 | |
| 1282 | " clean up |
| 1283 | call StopVimInTerminal(buf) |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1284 | endfunc |
| 1285 | |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1286 | func RunTestVisualBlock(width, dump) |
| 1287 | call writefile([ |
| 1288 | \ "call setline(1, [" |
| 1289 | \ .. "'xxxxxxxxx 123 x'," |
| 1290 | \ .. "'xxxxxxxx 123 x'," |
| 1291 | \ .. "'xxxxxxx 123 x'," |
| 1292 | \ .. "'xxxxxx 123 x'," |
| 1293 | \ .. "'xxxxx 123 x'," |
| 1294 | \ .. "'xxxx 123 xx'," |
| 1295 | \ .. "'xxx 123 xxx'," |
| 1296 | \ .. "'xx 123 xxxx'," |
| 1297 | \ .. "'x 123 xxxxx'," |
| 1298 | \ .. "' 123 xxxxxx'," |
| 1299 | \ .. "])", |
| 1300 | \ "hi SearchProp ctermbg=yellow", |
| 1301 | \ "call prop_type_add('search', {'highlight': 'SearchProp'})", |
| 1302 | \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", |
| 1303 | \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", |
| 1304 | \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", |
| 1305 | \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", |
| 1306 | \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", |
| 1307 | \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", |
| 1308 | \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", |
| 1309 | \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", |
| 1310 | \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", |
| 1311 | \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", |
| 1312 | \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1313 | \], 'XtestPropVis', 'D') |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1314 | let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) |
| 1315 | call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) |
| 1316 | |
| 1317 | " clean up |
| 1318 | call StopVimInTerminal(buf) |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1319 | endfunc |
| 1320 | |
| 1321 | " screenshot test with Visual block mode operations |
| 1322 | func Test_textprop_screenshot_visual() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1323 | CheckScreendump |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1324 | |
| 1325 | " Delete two columns while text props are three chars wide. |
| 1326 | call RunTestVisualBlock(2, '01') |
| 1327 | |
| 1328 | " Same, but delete four columns |
| 1329 | call RunTestVisualBlock(4, '02') |
| 1330 | endfunc |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1331 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1332 | func Test_textprop_after_tab() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1333 | CheckScreendump |
Bram Moolenaar | 37e66cf | 2019-06-19 18:16:10 +0200 | [diff] [blame] | 1334 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1335 | let lines =<< trim END |
| 1336 | call setline(1, [ |
| 1337 | \ "\txxx", |
| 1338 | \ "x\txxx", |
| 1339 | \ ]) |
| 1340 | hi SearchProp ctermbg=yellow |
| 1341 | call prop_type_add('search', {'highlight': 'SearchProp'}) |
| 1342 | call prop_add(1, 2, {'length': 3, 'type': 'search'}) |
| 1343 | call prop_add(2, 3, {'length': 3, 'type': 'search'}) |
| 1344 | END |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 1345 | call writefile(lines, 'XtextPropTab', 'D') |
| 1346 | let buf = RunVimInTerminal('-S XtextPropTab', {'rows': 6}) |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1347 | call VerifyScreenDump(buf, 'Test_textprop_tab', {}) |
| 1348 | |
| 1349 | " clean up |
| 1350 | call StopVimInTerminal(buf) |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1351 | endfunc |
| 1352 | |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 1353 | func Test_textprop_nesting() |
| 1354 | CheckScreendump |
| 1355 | |
| 1356 | let lines =<< trim END |
| 1357 | vim9script |
| 1358 | var lines =<< trim LINESEND |
| 1359 | |
| 1360 | const func: func.IFunction = ({ |
| 1361 | setLoading |
| 1362 | }) => { |
| 1363 | LINESEND |
| 1364 | setline(1, lines) |
| 1365 | prop_type_add('prop_add_test', {highlight: "ErrorMsg"}) |
| 1366 | prop_add(2, 31, {type: 'prop_add_test', end_lnum: 4, end_col: 2}) |
| 1367 | var text = 'text long enough to wrap line, text long enough to wrap line, text long enough to wrap line...' |
| 1368 | prop_add(2, 0, {type: 'prop_add_test', text_wrap: 'truncate', text_align: 'after', text: text}) |
| 1369 | END |
| 1370 | call writefile(lines, 'XtextpropNesting', 'D') |
| 1371 | let buf = RunVimInTerminal('-S XtextpropNesting', {'rows': 8}) |
| 1372 | call VerifyScreenDump(buf, 'Test_textprop_nesting', {}) |
| 1373 | |
| 1374 | " clean up |
| 1375 | call StopVimInTerminal(buf) |
| 1376 | endfunc |
| 1377 | |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1378 | func Test_textprop_nowrap_scrolled() |
| 1379 | CheckScreendump |
| 1380 | |
| 1381 | let lines =<< trim END |
| 1382 | vim9script |
| 1383 | set nowrap |
| 1384 | setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns)) |
| 1385 | prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1386 | prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1387 | prop_add(1, 32, {'length': 4, 'type': 'number'}) |
| 1388 | feedkeys('gg20zl', 'nxt') |
| 1389 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1390 | call writefile(lines, 'XtestNowrap', 'D') |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1391 | let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6}) |
| 1392 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {}) |
| 1393 | |
| 1394 | call term_sendkeys(buf, "$") |
| 1395 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {}) |
| 1396 | |
| 1397 | " clean up |
| 1398 | call StopVimInTerminal(buf) |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1399 | endfunc |
| 1400 | |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1401 | func Test_textprop_text_priority() |
| 1402 | CheckScreendump |
| 1403 | |
| 1404 | let lines =<< trim END |
| 1405 | call setline(1, "function( call, argument, here )") |
| 1406 | |
| 1407 | call prop_type_add('one', #{highlight: 'Error'}) |
| 1408 | call prop_type_add('two', #{highlight: 'Function'}) |
| 1409 | call prop_type_add('three', #{highlight: 'DiffChange'}) |
| 1410 | call prop_type_add('arg', #{highlight: 'Search'}) |
| 1411 | |
| 1412 | call prop_add(1, 27, #{type: 'arg', length: len('here')}) |
| 1413 | call prop_add(1, 27, #{type: 'three', text: 'three: '}) |
| 1414 | call prop_add(1, 11, #{type: 'one', text: 'one: '}) |
| 1415 | call prop_add(1, 11, #{type: 'arg', length: len('call')}) |
| 1416 | call prop_add(1, 17, #{type: 'two', text: 'two: '}) |
| 1417 | call prop_add(1, 17, #{type: 'arg', length: len('argument')}) |
| 1418 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1419 | call writefile(lines, 'XtestPropPrio', 'D') |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1420 | let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5}) |
| 1421 | call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {}) |
| 1422 | |
| 1423 | " clean up |
| 1424 | call StopVimInTerminal(buf) |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 1425 | endfunc |
| 1426 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1427 | func Test_textprop_with_syntax() |
| 1428 | CheckScreendump |
| 1429 | |
| 1430 | let lines =<< trim END |
| 1431 | call setline(1, [ |
| 1432 | \ "(abc)", |
| 1433 | \ ]) |
| 1434 | syn match csParens "[()]" display |
| 1435 | hi! link csParens MatchParen |
| 1436 | |
| 1437 | call prop_type_add('TPTitle', #{ highlight: 'Title' }) |
| 1438 | call prop_add(1, 2, #{type: 'TPTitle', end_col: 5}) |
| 1439 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1440 | call writefile(lines, 'XtestPropSyn', 'D') |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1441 | let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6}) |
| 1442 | call VerifyScreenDump(buf, 'Test_textprop_syn_1', {}) |
| 1443 | |
| 1444 | " clean up |
| 1445 | call StopVimInTerminal(buf) |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1446 | endfunc |
| 1447 | |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1448 | " Adding a text property to a new buffer should not fail |
| 1449 | func Test_textprop_empty_buffer() |
| 1450 | call prop_type_add('comment', {'highlight': 'Search'}) |
| 1451 | new |
| 1452 | call prop_add(1, 1, {'type': 'comment'}) |
| 1453 | close |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1454 | call prop_type_delete('comment') |
| 1455 | endfunc |
| 1456 | |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 1457 | " Adding a text property with invalid highlight should be ignored. |
| 1458 | func Test_textprop_invalid_highlight() |
| 1459 | call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:') |
| 1460 | new |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 1461 | call setline(1, ['asdf', 'asdf']) |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 1462 | call prop_add(1, 1, {'length': 4, 'type': 'dni'}) |
| 1463 | redraw |
| 1464 | bwipe! |
| 1465 | call prop_type_delete('dni') |
| 1466 | endfunc |
| 1467 | |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1468 | " Adding a text property to an empty buffer and then editing another |
| 1469 | func Test_textprop_empty_buffer_next() |
| 1470 | call prop_type_add("xxx", {}) |
| 1471 | call prop_add(1, 1, {"type": "xxx"}) |
| 1472 | next X |
| 1473 | call prop_type_delete('xxx') |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1474 | endfunc |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 1475 | |
| 1476 | func Test_textprop_remove_from_buf() |
| 1477 | new |
| 1478 | let buf = bufnr('') |
| 1479 | call prop_type_add('one', {'bufnr': buf}) |
| 1480 | call prop_add(1, 1, {'type': 'one', 'id': 234}) |
| 1481 | file x |
| 1482 | edit y |
| 1483 | call prop_remove({'id': 234, 'bufnr': buf}, 1) |
| 1484 | call prop_type_delete('one', {'bufnr': buf}) |
| 1485 | bwipe! x |
| 1486 | close |
| 1487 | endfunc |
Bram Moolenaar | 45311b5 | 2019-08-13 22:27:32 +0200 | [diff] [blame] | 1488 | |
| 1489 | func Test_textprop_in_unloaded_buf() |
| 1490 | edit Xaaa |
| 1491 | call setline(1, 'aaa') |
| 1492 | write |
| 1493 | edit Xbbb |
| 1494 | call setline(1, 'bbb') |
| 1495 | write |
| 1496 | let bnr = bufnr('') |
| 1497 | edit Xaaa |
| 1498 | |
| 1499 | call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'}) |
| 1500 | call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:') |
| 1501 | exe 'buf ' .. bnr |
| 1502 | call assert_equal('bbb', getline(1)) |
| 1503 | call assert_equal(0, prop_list(1)->len()) |
| 1504 | |
| 1505 | bwipe! Xaaa |
| 1506 | bwipe! Xbbb |
| 1507 | cal delete('Xaaa') |
| 1508 | cal delete('Xbbb') |
| 1509 | endfunc |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1510 | |
| 1511 | func Test_proptype_substitute2() |
| 1512 | new |
| 1513 | " text_prop.vim |
| 1514 | call setline(1, [ |
| 1515 | \ 'The num 123 is smaller than 4567.', |
| 1516 | \ '123 The number 123 is smaller than 4567.', |
| 1517 | \ '123 The number 123 is smaller than 4567.']) |
| 1518 | |
| 1519 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1520 | |
| 1521 | call prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1522 | call prop_add(2, 1, {'length': 3, 'type': 'number'}) |
| 1523 | call prop_add(3, 36, {'length': 4, 'type': 'number'}) |
| 1524 | set ul& |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1525 | let expected = [ |
| 1526 | \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1}, |
| 1527 | \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1}, |
| 1528 | \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}] |
| 1529 | |
| 1530 | " TODO |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1531 | if 0 |
| 1532 | " Add some text in between |
| 1533 | %s/\s\+/ /g |
| 1534 | 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] | 1535 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1536 | " remove some text |
| 1537 | :1s/[a-z]\{3\}//g |
| 1538 | let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] |
| 1539 | call assert_equal(expected, prop_list(1)) |
| 1540 | endif |
| 1541 | |
| 1542 | call prop_type_delete('number') |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1543 | bwipe! |
| 1544 | endfunc |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1545 | |
Bram Moolenaar | 8902b31 | 2020-09-20 21:04:35 +0200 | [diff] [blame] | 1546 | " This was causing property corruption. |
| 1547 | func Test_proptype_substitute3() |
| 1548 | new |
| 1549 | call setline(1, ['abcxxx', 'def']) |
| 1550 | call prop_type_add("test", {"highlight": "Search"}) |
| 1551 | call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"}) |
| 1552 | %s/x\+$// |
| 1553 | redraw |
| 1554 | |
| 1555 | call prop_type_delete('test') |
| 1556 | bwipe! |
| 1557 | endfunc |
| 1558 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1559 | func Test_proptype_substitute_join() |
| 1560 | new |
| 1561 | call setline(1, [ |
| 1562 | \ 'This is some end', |
| 1563 | \ 'start is highlighted end', |
| 1564 | \ 'some is highlighted', |
| 1565 | \ 'start is also highlighted']) |
| 1566 | |
| 1567 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1568 | |
| 1569 | call prop_add(1, 6, {'length': 2, 'type': 'number'}) |
| 1570 | call prop_add(2, 7, {'length': 2, 'type': 'number'}) |
| 1571 | call prop_add(3, 6, {'length': 2, 'type': 'number'}) |
| 1572 | call prop_add(4, 7, {'length': 2, 'type': 'number'}) |
Dominique Pelle | b49dfd0 | 2023-04-14 21:54:25 +0100 | [diff] [blame] | 1573 | " 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] | 1574 | " The highlighted "is" in line 3 is deleted. |
| 1575 | let expected = [ |
| 1576 | \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1}, |
| 1577 | \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1}, |
| 1578 | \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}] |
| 1579 | |
| 1580 | s/end\nstart/joined/ |
| 1581 | s/end\n.*\nstart/joined/ |
| 1582 | call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1)) |
| 1583 | call assert_equal(expected, prop_list(1)) |
| 1584 | |
| 1585 | call prop_type_delete('number') |
| 1586 | bwipe! |
| 1587 | endfunc |
| 1588 | |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1589 | func SaveOptions() |
| 1590 | let d = #{tabstop: &tabstop, |
| 1591 | \ softtabstop: &softtabstop, |
| 1592 | \ shiftwidth: &shiftwidth, |
| 1593 | \ expandtab: &expandtab, |
| 1594 | \ foldmethod: '"' .. &foldmethod .. '"', |
| 1595 | \ } |
| 1596 | return d |
| 1597 | endfunc |
| 1598 | |
| 1599 | func RestoreOptions(dict) |
| 1600 | for name in keys(a:dict) |
| 1601 | exe 'let &' .. name .. ' = ' .. a:dict[name] |
| 1602 | endfor |
| 1603 | endfunc |
| 1604 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1605 | func Test_textprop_noexpandtab() |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1606 | new |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1607 | let save_dict = SaveOptions() |
| 1608 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1609 | set tabstop=8 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1610 | set softtabstop=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1611 | set shiftwidth=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1612 | set noexpandtab |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1613 | set foldmethod=marker |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1614 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1615 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx") |
| 1616 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1617 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1618 | call feedkeys("0i\<tab>", "tx") |
| 1619 | call prop_remove({'type': 'test'}) |
| 1620 | call prop_add(1, 2, {'end_col': 3, 'type': 'test'}) |
| 1621 | call feedkeys("A\<left>\<tab>", "tx") |
| 1622 | call prop_remove({'type': 'test'}) |
| 1623 | try |
| 1624 | " It is correct that this does not pass |
| 1625 | call prop_add(1, 6, {'end_col': 7, 'type': 'test'}) |
| 1626 | " Has already collapsed here, start_col:6 does not result in an error |
| 1627 | call feedkeys("A\<left>\<tab>", "tx") |
| 1628 | catch /^Vim\%((\a\+)\)\=:E964/ |
| 1629 | endtry |
| 1630 | call prop_remove({'type': 'test'}) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1631 | call prop_type_delete('test') |
| 1632 | |
| 1633 | call RestoreOptions(save_dict) |
| 1634 | bwipe! |
| 1635 | endfunc |
| 1636 | |
| 1637 | func Test_textprop_noexpandtab_redraw() |
| 1638 | new |
| 1639 | let save_dict = SaveOptions() |
| 1640 | |
| 1641 | set tabstop=8 |
| 1642 | set softtabstop=4 |
| 1643 | set shiftwidth=4 |
| 1644 | set noexpandtab |
| 1645 | set foldmethod=marker |
| 1646 | |
| 1647 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx") |
| 1648 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1649 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1650 | call feedkeys("0i\<tab>", "tx") |
| 1651 | " Internally broken at the next line |
| 1652 | call feedkeys("A\<left>\<tab>", "tx") |
| 1653 | redraw |
| 1654 | " Index calculation failed internally on next line |
| 1655 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1656 | call prop_remove({'type': 'test', 'all': v:true}) |
| 1657 | call prop_type_delete('test') |
| 1658 | call prop_type_delete('test') |
| 1659 | |
| 1660 | call RestoreOptions(save_dict) |
| 1661 | bwipe! |
| 1662 | endfunc |
| 1663 | |
| 1664 | func Test_textprop_ins_str() |
| 1665 | new |
| 1666 | call setline(1, 'just some text') |
| 1667 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1668 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1669 | 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] | 1670 | |
| 1671 | call feedkeys("foi\<F8>\<Esc>", "tx") |
| 1672 | call assert_equal('just s<F8>ome text', getline(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1673 | 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] | 1674 | |
| 1675 | bwipe! |
| 1676 | call prop_remove({'type': 'test'}) |
| 1677 | call prop_type_delete('test') |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1678 | endfunc |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1679 | |
| 1680 | func Test_find_prop_later_in_line() |
| 1681 | new |
| 1682 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1683 | call setline(1, 'just some text') |
| 1684 | call prop_add(1, 1, {'length': 4, 'type': 'test'}) |
| 1685 | call prop_add(1, 10, {'length': 3, 'type': 'test'}) |
| 1686 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1687 | call assert_equal( |
| 1688 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1}, |
| 1689 | \ prop_find(#{type: 'test', lnum: 1, col: 6})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1690 | |
| 1691 | bwipe! |
| 1692 | call prop_type_delete('test') |
| 1693 | endfunc |
| 1694 | |
| 1695 | func Test_find_zerowidth_prop_sol() |
| 1696 | new |
| 1697 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1698 | call setline(1, 'just some text') |
| 1699 | call prop_add(1, 1, {'length': 0, 'type': 'test'}) |
| 1700 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1701 | call assert_equal( |
| 1702 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1}, |
| 1703 | \ prop_find(#{type: 'test', lnum: 1})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1704 | |
| 1705 | bwipe! |
| 1706 | call prop_type_delete('test') |
| 1707 | endfunc |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1708 | |
| 1709 | " Test for passing invalid arguments to prop_xxx() functions |
| 1710 | func Test_prop_func_invalid_args() |
| 1711 | call assert_fails('call prop_clear(1, 2, [])', 'E715:') |
| 1712 | call assert_fails('call prop_clear(-1, 2)', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1713 | call assert_fails('call prop_find(test_null_dict())', 'E1297:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1714 | call assert_fails('call prop_find({"bufnr" : []})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1715 | call assert_fails('call prop_find({})', 'E968:') |
| 1716 | call assert_fails('call prop_find({}, "x")', 'E474:') |
| 1717 | call assert_fails('call prop_find({"lnum" : -2})', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1718 | call assert_fails('call prop_list(1, [])', 'E1206:') |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 1719 | call assert_fails('call prop_list(-1, {})', 'E16:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1720 | call assert_fails('call prop_remove([])', 'E1206:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1721 | call assert_fails('call prop_remove({}, -2)', 'E16:') |
| 1722 | call assert_fails('call prop_remove({})', 'E968:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1723 | call assert_fails('call prop_type_add([], {})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1724 | call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1725 | call assert_fails("call prop_type_delete([])", 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1726 | call assert_fails("call prop_type_delete('xyz', [])", 'E715:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1727 | call assert_fails("call prop_type_get([])", 'E730:') |
Bram Moolenaar | 89469d1 | 2022-12-02 20:46:26 +0000 | [diff] [blame] | 1728 | call assert_fails("call prop_type_get('', [])", 'E475:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1729 | call assert_fails("call prop_type_list([])", 'E715:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1730 | call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:') |
| 1731 | call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:') |
| 1732 | call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:') |
Yegappan Lakshmanan | 04c4c57 | 2022-08-30 19:48:24 +0100 | [diff] [blame] | 1733 | call assert_fails('call prop_add(1, 1, 0)', 'E1206:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1734 | |
| 1735 | new |
| 1736 | call setline(1, ['first', 'second']) |
| 1737 | call prop_type_add('xxx', {}) |
| 1738 | |
| 1739 | call assert_fails("call prop_type_add('xxx', {})", 'E969:') |
| 1740 | call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:') |
| 1741 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:') |
| 1742 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:') |
| 1743 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:') |
| 1744 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:') |
| 1745 | call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:') |
| 1746 | |
| 1747 | call prop_type_delete('xxx') |
| 1748 | bwipe! |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1749 | endfunc |
| 1750 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1751 | func Test_prop_split_join() |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1752 | new |
| 1753 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1754 | call setline(1, 'just some text') |
| 1755 | call prop_add(1, 6, {'length': 4, 'type': 'test'}) |
| 1756 | |
| 1757 | " Split in middle of "some" |
| 1758 | execute "normal! 8|i\<CR>" |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1759 | call assert_equal( |
| 1760 | \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}], |
| 1761 | \ prop_list(1)) |
| 1762 | call assert_equal( |
| 1763 | \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}], |
| 1764 | \ prop_list(2)) |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1765 | |
| 1766 | " Join the two lines back together |
| 1767 | normal! 1GJ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1768 | 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] | 1769 | |
| 1770 | bwipe! |
| 1771 | call prop_type_delete('test') |
| 1772 | endfunc |
| 1773 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1774 | func Test_prop_increment_decrement() |
| 1775 | new |
| 1776 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1777 | call setline(1, 'its 998 times') |
| 1778 | call prop_add(1, 5, {'length': 3, 'type': 'test'}) |
| 1779 | |
| 1780 | exe "normal! 0f9\<C-A>" |
| 1781 | eval getline(1)->assert_equal('its 999 times') |
| 1782 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1783 | \ #{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] | 1784 | |
| 1785 | exe "normal! 0f9\<C-A>" |
| 1786 | eval getline(1)->assert_equal('its 1000 times') |
| 1787 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1788 | \ #{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] | 1789 | |
| 1790 | bwipe! |
| 1791 | call prop_type_delete('test') |
| 1792 | endfunc |
| 1793 | |
Bram Moolenaar | 8b51b7f | 2020-09-15 21:34:18 +0200 | [diff] [blame] | 1794 | func Test_prop_block_insert() |
| 1795 | new |
| 1796 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1797 | call setline(1, ['one ', 'two ']) |
| 1798 | call prop_add(1, 1, {'length': 3, 'type': 'test'}) |
| 1799 | call prop_add(2, 1, {'length': 3, 'type': 'test'}) |
| 1800 | |
| 1801 | " insert "xx" in the first column of both lines |
| 1802 | exe "normal! gg0\<C-V>jIxx\<Esc>" |
| 1803 | eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1804 | 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] | 1805 | eval prop_list(1)->assert_equal(expected) |
| 1806 | eval prop_list(2)->assert_equal(expected) |
| 1807 | |
| 1808 | " insert "yy" inside the text props to make them longer |
| 1809 | exe "normal! gg03l\<C-V>jIyy\<Esc>" |
| 1810 | eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo ']) |
| 1811 | let expected[0].length = 5 |
| 1812 | eval prop_list(1)->assert_equal(expected) |
| 1813 | eval prop_list(2)->assert_equal(expected) |
| 1814 | |
| 1815 | " insert "zz" after the text props, text props don't change |
| 1816 | exe "normal! gg07l\<C-V>jIzz\<Esc>" |
| 1817 | eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz ']) |
| 1818 | eval prop_list(1)->assert_equal(expected) |
| 1819 | eval prop_list(2)->assert_equal(expected) |
| 1820 | |
| 1821 | bwipe! |
| 1822 | call prop_type_delete('test') |
| 1823 | endfunc |
| 1824 | |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 1825 | " this was causing an ml_get error because w_botline was wrong |
| 1826 | func Test_prop_one_line_window() |
| 1827 | enew |
| 1828 | call range(2)->setline(1) |
| 1829 | call prop_type_add('testprop', {}) |
| 1830 | call prop_add(1, 1, {'type': 'testprop'}) |
| 1831 | call popup_create('popup', {'textprop': 'testprop'}) |
| 1832 | $ |
| 1833 | new |
| 1834 | wincmd _ |
| 1835 | call feedkeys("\r", 'xt') |
| 1836 | redraw |
| 1837 | |
| 1838 | call popup_clear() |
| 1839 | call prop_type_delete('testprop') |
| 1840 | close |
| 1841 | bwipe! |
| 1842 | endfunc |
| 1843 | |
Bram Moolenaar | f05a1e5 | 2022-08-02 11:48:53 +0100 | [diff] [blame] | 1844 | def Test_prop_column_zero_error() |
| 1845 | prop_type_add('proptype', {highlight: 'Search'}) |
| 1846 | var caught = false |
| 1847 | try |
| 1848 | popup_create([{ |
| 1849 | text: 'a', |
| 1850 | props: [{col: 0, length: 1, type: 'type'}], |
| 1851 | }], {}) |
| 1852 | catch /E964:/ |
| 1853 | caught = true |
| 1854 | endtry |
| 1855 | assert_true(caught) |
| 1856 | |
| 1857 | popup_clear() |
| 1858 | prop_type_delete('proptype') |
| 1859 | enddef |
| 1860 | |
Bram Moolenaar | 840f91f | 2021-05-26 22:32:10 +0200 | [diff] [blame] | 1861 | " This was calling ml_append_int() and copy a text property from a previous |
| 1862 | " line at the wrong moment. Exact text length matters. |
| 1863 | def Test_prop_splits_data_block() |
| 1864 | new |
| 1865 | var lines: list<string> = [repeat('x', 35)]->repeat(41) |
| 1866 | + [repeat('!', 35)] |
| 1867 | + [repeat('x', 35)]->repeat(56) |
| 1868 | lines->setline(1) |
| 1869 | prop_type_add('someprop', {highlight: 'ErrorMsg'}) |
| 1870 | prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'}) |
| 1871 | prop_remove({type: 'someprop'}, 1) |
| 1872 | prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'}) |
| 1873 | prop_remove({type: 'someprop'}, 35, 43) |
| 1874 | assert_equal([], prop_list(42)) |
| 1875 | |
| 1876 | bwipe! |
| 1877 | prop_type_delete('someprop') |
| 1878 | enddef |
| 1879 | |
Bram Moolenaar | 4cd5c52 | 2021-06-27 13:04:00 +0200 | [diff] [blame] | 1880 | " This was calling ml_delete_int() and try to change text properties. |
| 1881 | def Test_prop_add_delete_line() |
| 1882 | new |
| 1883 | var a = 10 |
| 1884 | var b = 20 |
| 1885 | repeat([''], a)->append('$') |
| 1886 | prop_type_add('Test', {highlight: 'ErrorMsg'}) |
| 1887 | for lnum in range(1, a) |
| 1888 | for col in range(1, b) |
| 1889 | prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'}) |
| 1890 | endfor |
| 1891 | endfor |
| 1892 | |
| 1893 | # check deleting lines is OK |
| 1894 | :5del |
| 1895 | :1del |
| 1896 | :$del |
| 1897 | |
| 1898 | prop_type_delete('Test') |
| 1899 | bwipe! |
| 1900 | enddef |
| 1901 | |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1902 | " This test is to detect a regression related to #10430. It is not an attempt |
| 1903 | " fully cover deleting lines in the presence of multi-line properties. |
| 1904 | def Test_delete_line_within_multiline_prop() |
| 1905 | new |
| 1906 | setline(1, '# Top.') |
| 1907 | append(1, ['some_text = """', 'A string.', '"""', '# Bottom.']) |
| 1908 | prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1909 | prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1910 | prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9}) |
| 1911 | prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4}) |
| 1912 | |
| 1913 | # The property for line 3 should extend into the previous and next lines. |
| 1914 | var props = prop_list(3) |
| 1915 | var prop = props[0] |
| 1916 | assert_equal(1, len(props)) |
| 1917 | assert_equal(0, prop['start']) |
| 1918 | assert_equal(0, prop['end']) |
| 1919 | |
| 1920 | # This deletion should run without raising an exception. |
| 1921 | try |
| 1922 | :2 del |
| 1923 | catch |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1924 | assert_report('Line delete should have worked, but it raised an error.') |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1925 | endtry |
| 1926 | |
| 1927 | # The property for line 2 (was 3) should no longer extend into the previous |
| 1928 | # line. |
| 1929 | props = prop_list(2) |
| 1930 | prop = props[0] |
| 1931 | assert_equal(1, len(props)) |
| 1932 | assert_equal(1, prop['start'], 'Property was not changed to start within the line.') |
| 1933 | |
| 1934 | # This deletion should run without raising an exception. |
| 1935 | try |
| 1936 | :3 del |
| 1937 | catch |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 1938 | assert_report('Line delete should have worked, but it raised an error.') |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1939 | endtry |
| 1940 | |
| 1941 | # The property for line 2 (originally 3) should no longer extend into the next |
| 1942 | # line. |
| 1943 | props = prop_list(2) |
| 1944 | prop = props[0] |
| 1945 | assert_equal(1, len(props)) |
| 1946 | assert_equal(1, prop['end'], 'Property was not changed to end within the line.') |
| 1947 | |
| 1948 | prop_type_delete('Identifier') |
| 1949 | prop_type_delete('String') |
| 1950 | bwip! |
| 1951 | enddef |
| 1952 | |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1953 | func Test_prop_in_linebreak() |
| 1954 | CheckRunVimInTerminal |
| 1955 | |
| 1956 | let lines =<< trim END |
| 1957 | set breakindent linebreak breakat+=] |
| 1958 | call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 1959 | call prop_type_add('test', #{highlight: 'MatchParen'}) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1960 | call prop_add(1, 51, #{length: 1, type: 'test'}) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 1961 | func AddMatch() |
| 1962 | syntax on |
| 1963 | syntax match xTest /.*/ |
| 1964 | hi link xTest Comment |
| 1965 | set signcolumn=yes |
| 1966 | endfunc |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1967 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1968 | call writefile(lines, 'XscriptPropLinebreak', 'D') |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1969 | let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10}) |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 1970 | call VerifyScreenDump(buf, 'Test_prop_linebreak_1', {}) |
| 1971 | |
| 1972 | call term_sendkeys(buf, ":call AddMatch()\<CR>") |
| 1973 | call VerifyScreenDump(buf, 'Test_prop_linebreak_2', {}) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1974 | |
| 1975 | call StopVimInTerminal(buf) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1976 | endfunc |
| 1977 | |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 1978 | func Test_prop_with_linebreak() |
| 1979 | CheckRunVimInTerminal |
| 1980 | |
| 1981 | let lines =<< trim END |
| 1982 | vim9script |
| 1983 | set linebreak |
| 1984 | setline(1, 'one twoword') |
| 1985 | prop_type_add('test', {highlight: 'Special'}) |
| 1986 | prop_add(1, 4, {text: ': virtual text', type: 'test', text_wrap: 'wrap'}) |
| 1987 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 1988 | call writefile(lines, 'XscriptPropWithLinebreak', 'D') |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 1989 | let buf = RunVimInTerminal('-S XscriptPropWithLinebreak', #{rows: 6, cols: 50}) |
| 1990 | call VerifyScreenDump(buf, 'Test_prop_with_linebreak_1', {}) |
| 1991 | call term_sendkeys(buf, "iasdf asdf asdf asdf asdf as\<Esc>") |
| 1992 | call VerifyScreenDump(buf, 'Test_prop_with_linebreak_2', {}) |
| 1993 | |
| 1994 | call StopVimInTerminal(buf) |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 1995 | endfunc |
| 1996 | |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 1997 | func Test_prop_with_wrap() |
| 1998 | CheckRunVimInTerminal |
| 1999 | |
| 2000 | let lines =<< trim END |
| 2001 | vim9script |
| 2002 | set linebreak |
| 2003 | setline(1, 'asdf '->repeat(15)) |
| 2004 | prop_type_add('test', {highlight: 'Special'}) |
| 2005 | prop_add(1, 43, {text: 'some virtual text', type: 'test'}) |
Bram Moolenaar | 1aeb3eb | 2023-01-01 14:04:51 +0000 | [diff] [blame] | 2006 | normal G$ |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2007 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2008 | call writefile(lines, 'XscriptPropWithWrap', 'D') |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2009 | let buf = RunVimInTerminal('-S XscriptPropWithWrap', #{rows: 6, cols: 50}) |
| 2010 | call VerifyScreenDump(buf, 'Test_prop_with_wrap_1', {}) |
| 2011 | |
| 2012 | call StopVimInTerminal(buf) |
Bram Moolenaar | 1d8844a | 2022-08-10 13:39:35 +0100 | [diff] [blame] | 2013 | endfunc |
| 2014 | |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2015 | func Test_prop_after_tab() |
| 2016 | CheckRunVimInTerminal |
| 2017 | |
| 2018 | let lines =<< trim END |
| 2019 | set breakindent linebreak breakat+=] |
| 2020 | call setline(1, "\t[xxx]") |
| 2021 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 2022 | call prop_add(1, 2, #{length: 1, type: 'test'}) |
| 2023 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2024 | call writefile(lines, 'XscriptPropAfterTab', 'D') |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2025 | let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10}) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2026 | call VerifyScreenDump(buf, 'Test_prop_after_tab', {}) |
| 2027 | |
| 2028 | call StopVimInTerminal(buf) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 2029 | endfunc |
| 2030 | |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2031 | func Test_prop_before_tab() |
| 2032 | CheckRunVimInTerminal |
| 2033 | |
| 2034 | let lines =<< trim END |
| 2035 | call setline(1, ["\tx"]->repeat(6)) |
| 2036 | call prop_type_add('test', #{highlight: 'Search'}) |
| 2037 | call prop_add(1, 1, #{type: 'test', text: '123'}) |
| 2038 | call prop_add(2, 1, #{type: 'test', text: '1234567'}) |
| 2039 | call prop_add(3, 1, #{type: 'test', text: '12345678'}) |
| 2040 | call prop_add(4, 1, #{type: 'test', text: '123456789'}) |
| 2041 | call prop_add(5, 2, #{type: 'test', text: 'ABC'}) |
| 2042 | call prop_add(6, 3, #{type: 'test', text: 'ABC'}) |
| 2043 | normal gg0 |
| 2044 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2045 | call writefile(lines, 'XscriptPropBeforeTab', 'D') |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2046 | let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8}) |
| 2047 | call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {}) |
| 2048 | call term_sendkeys(buf, "$") |
| 2049 | call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {}) |
| 2050 | call term_sendkeys(buf, "j0") |
| 2051 | call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {}) |
| 2052 | call term_sendkeys(buf, "$") |
| 2053 | call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {}) |
| 2054 | call term_sendkeys(buf, "j0") |
| 2055 | call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {}) |
| 2056 | call term_sendkeys(buf, "$") |
| 2057 | call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {}) |
| 2058 | call term_sendkeys(buf, "j0") |
| 2059 | call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {}) |
| 2060 | call term_sendkeys(buf, "$") |
| 2061 | call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {}) |
| 2062 | call term_sendkeys(buf, "j") |
| 2063 | call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {}) |
| 2064 | call term_sendkeys(buf, "j") |
| 2065 | call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {}) |
| 2066 | |
| 2067 | call StopVimInTerminal(buf) |
Bram Moolenaar | e428fa0 | 2022-08-09 16:55:41 +0100 | [diff] [blame] | 2068 | endfunc |
| 2069 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2070 | func Test_prop_after_linebreak() |
| 2071 | CheckRunVimInTerminal |
| 2072 | |
| 2073 | let lines =<< trim END |
| 2074 | set linebreak wrap |
| 2075 | call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1) |
| 2076 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 2077 | call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'}) |
| 2078 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2079 | call writefile(lines, 'XscriptPropAfterLinebreak', 'D') |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2080 | let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10}) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2081 | call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {}) |
| 2082 | |
| 2083 | call StopVimInTerminal(buf) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2084 | endfunc |
| 2085 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 2086 | " Buffer number of 0 should be ignored, as if the parameter wasn't passed. |
| 2087 | def Test_prop_bufnr_zero() |
| 2088 | new |
| 2089 | try |
| 2090 | var bufnr = bufnr('') |
| 2091 | setline(1, 'hello') |
| 2092 | prop_type_add('bufnr-global', {highlight: 'ErrorMsg'}) |
| 2093 | prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr}) |
| 2094 | |
| 2095 | prop_add(1, 1, {type: 'bufnr-global', length: 1}) |
| 2096 | prop_add(1, 2, {type: 'bufnr-buffer', length: 1}) |
| 2097 | |
| 2098 | var list = prop_list(1) |
| 2099 | assert_equal([ |
| 2100 | {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1}, |
| 2101 | {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1}, |
| 2102 | ], list) |
| 2103 | |
| 2104 | assert_equal( |
| 2105 | {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1}, |
| 2106 | prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr})) |
| 2107 | |
| 2108 | assert_equal( |
| 2109 | {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1}, |
| 2110 | prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr})) |
| 2111 | finally |
| 2112 | bwipe! |
| 2113 | prop_type_delete('bufnr-global') |
| 2114 | endtry |
| 2115 | enddef |
| 2116 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2117 | " Tests for the prop_list() function |
| 2118 | func Test_prop_list() |
| 2119 | let lines =<< trim END |
| 2120 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2121 | call g:AddPropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2122 | call setline(1, repeat([repeat('a', 60)], 10)) |
| 2123 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2124 | call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7}) |
| 2125 | call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14}) |
| 2126 | call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15}) |
| 2127 | call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22}) |
| 2128 | call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23}) |
| 2129 | call assert_equal([ |
| 2130 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2131 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2132 | \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2133 | \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1)) |
| 2134 | #" text properties between a few lines |
| 2135 | call assert_equal([ |
| 2136 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2137 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2138 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2139 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2140 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 2141 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2142 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 2143 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2144 | \ prop_list(2, {'end_lnum': 5})) |
| 2145 | #" text properties across all the lines |
| 2146 | call assert_equal([ |
| 2147 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2148 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2149 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2150 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2151 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 2152 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2153 | \ prop_list(1, {'types': ['one'], 'end_lnum': -1})) |
| 2154 | #" text properties with the specified identifier |
| 2155 | call assert_equal([ |
| 2156 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2157 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2158 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 2159 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2160 | \ prop_list(1, {'ids': [20], 'end_lnum': 10})) |
| 2161 | #" text properties of the specified type and id |
| 2162 | call assert_equal([ |
| 2163 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2164 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2165 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2166 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2167 | \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20})) |
| 2168 | call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10})) |
| 2169 | call assert_equal([], prop_list(6, {'end_lnum': 10})) |
| 2170 | call assert_equal([], prop_list(2, {'end_lnum': 2})) |
| 2171 | #" error cases |
| 2172 | call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:') |
| 2173 | call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:') |
| 2174 | call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:') |
| 2175 | call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})", |
| 2176 | \ 'E971:') |
| 2177 | call assert_fails("echo prop_list(1, {'types': ['one', 'blue'], |
| 2178 | \ 'end_lnum': 10})", 'E971:') |
| 2179 | call assert_fails("echo prop_list(1, {'types': ['one', 10], |
| 2180 | \ 'end_lnum': 10})", 'E928:') |
| 2181 | call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:') |
| 2182 | call assert_equal([], prop_list(2, {'types': []})) |
| 2183 | call assert_equal([], prop_list(2, {'types': test_null_list()})) |
| 2184 | call assert_fails("call prop_list(1, {'types': {}})", 'E714:') |
| 2185 | call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:') |
| 2186 | call assert_equal([], prop_list(2, {'types': ['one'], |
| 2187 | \ 'ids': test_null_list()})) |
| 2188 | call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []})) |
| 2189 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})", |
| 2190 | \ 'E714:') |
| 2191 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})", |
| 2192 | \ 'E714:') |
| 2193 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})", |
| 2194 | \ 'E745:') |
| 2195 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})", |
| 2196 | \ 'E745:') |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 2197 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2198 | #" get text properties from a non-current buffer |
| 2199 | wincmd w |
| 2200 | call assert_equal([ |
| 2201 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2202 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2203 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 2204 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2205 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 2206 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2207 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 2208 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2209 | \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4})) |
| 2210 | wincmd w |
| 2211 | |
| 2212 | #" get text properties after clearing all the properties |
| 2213 | call prop_clear(1, line('$')) |
| 2214 | call assert_equal([], prop_list(1, {'end_lnum': 10})) |
| 2215 | |
| 2216 | call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2217 | call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6}) |
| 2218 | call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6}) |
| 2219 | #" get text properties with a list of types |
| 2220 | call assert_equal([ |
| 2221 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2222 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2223 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2224 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2225 | \ prop_list(2, {'types': ['one', 'two']})) |
| 2226 | call assert_equal([ |
| 2227 | \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2228 | \ 'type': 'three', 'length': 2, 'start': 1}, |
| 2229 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2230 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2231 | \ prop_list(2, {'types': ['one', 'three']})) |
| 2232 | #" get text properties with a list of identifiers |
| 2233 | call assert_equal([ |
| 2234 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2235 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 2236 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2237 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 2238 | \ prop_list(2, {'ids': [5, 10, 20]})) |
| 2239 | call prop_clear(1, line('$')) |
| 2240 | call assert_equal([], prop_list(2, {'types': ['one', 'two']})) |
| 2241 | call assert_equal([], prop_list(2, {'ids': [5, 10, 20]})) |
| 2242 | |
| 2243 | #" get text properties from a hidden buffer |
| 2244 | edit! Xaaa |
| 2245 | call setline(1, repeat([repeat('b', 60)], 10)) |
| 2246 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2247 | call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10}) |
| 2248 | VAR bnr = bufnr() |
| 2249 | hide edit Xbbb |
| 2250 | call assert_equal([ |
| 2251 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2252 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2253 | \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1, |
| 2254 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2255 | \ prop_list(1, {'bufnr': bnr, |
| 2256 | \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1})) |
| 2257 | #" get text properties from an unloaded buffer |
| 2258 | bunload! Xaaa |
| 2259 | call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1})) |
| 2260 | |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2261 | call g:DeletePropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2262 | :%bw! |
| 2263 | END |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2264 | call v9.CheckLegacyAndVim9Success(lines) |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2265 | endfunc |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 2266 | |
LemonBoy | 9bd3ce2 | 2022-04-18 21:54:02 +0100 | [diff] [blame] | 2267 | func Test_prop_find_prev_on_same_line() |
| 2268 | new |
| 2269 | |
| 2270 | call setline(1, 'the quikc bronw fox jumsp over the layz dog') |
| 2271 | call prop_type_add('misspell', #{highlight: 'ErrorMsg'}) |
| 2272 | for col in [8, 14, 24, 38] |
| 2273 | call prop_add(1, col, #{type: 'misspell', length: 2}) |
| 2274 | endfor |
| 2275 | |
Ben Jackson | a770422 | 2022-08-20 20:54:51 +0100 | [diff] [blame] | 2276 | call cursor(1, 18) |
LemonBoy | 9bd3ce2 | 2022-04-18 21:54:02 +0100 | [diff] [blame] | 2277 | let expected = [ |
| 2278 | \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}, |
| 2279 | \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1} |
| 2280 | \ ] |
| 2281 | |
| 2282 | let result = prop_find(#{type: 'misspell'}, 'b') |
| 2283 | call assert_equal(expected[0], result) |
| 2284 | let result = prop_find(#{type: 'misspell'}, 'f') |
| 2285 | call assert_equal(expected[1], result) |
| 2286 | |
| 2287 | call prop_type_delete('misspell') |
| 2288 | bwipe! |
| 2289 | endfunc |
| 2290 | |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2291 | func Test_prop_spell() |
| 2292 | new |
| 2293 | set spell |
| 2294 | call AddPropTypes() |
| 2295 | |
| 2296 | call setline(1, ["helo world", "helo helo helo"]) |
| 2297 | call prop_add(1, 1, #{type: 'one', length: 4}) |
| 2298 | call prop_add(1, 6, #{type: 'two', length: 5}) |
| 2299 | call prop_add(2, 1, #{type: 'three', length: 4}) |
| 2300 | call prop_add(2, 6, #{type: 'three', length: 4}) |
| 2301 | call prop_add(2, 11, #{type: 'three', length: 4}) |
| 2302 | |
| 2303 | " The first prop over 'helo' increases its length after the word is corrected |
| 2304 | " to 'Hello', the second one is shifted to the right. |
| 2305 | let expected = [ |
| 2306 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2307 | \ 'length': 5, 'start': 1}, |
| 2308 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2309 | \ 'length': 5, 'start': 1} |
| 2310 | \ ] |
| 2311 | call feedkeys("z=1\<CR>", 'xt') |
| 2312 | |
| 2313 | call assert_equal('Hello world', getline(1)) |
| 2314 | call assert_equal(expected, prop_list(1)) |
| 2315 | |
| 2316 | " Repeat the replacement done by z= |
| 2317 | spellrepall |
| 2318 | |
| 2319 | let expected = [ |
| 2320 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2321 | \ 'length': 5, 'start': 1}, |
| 2322 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2323 | \ 'length': 5, 'start': 1}, |
| 2324 | \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2325 | \ 'length': 5, 'start': 1} |
| 2326 | \ ] |
| 2327 | call assert_equal('Hello Hello Hello', getline(2)) |
| 2328 | call assert_equal(expected, prop_list(2)) |
| 2329 | |
| 2330 | call DeletePropTypes() |
| 2331 | set spell& |
| 2332 | bwipe! |
| 2333 | endfunc |
| 2334 | |
LemonBoy | 4b93674 | 2022-05-13 21:56:28 +0100 | [diff] [blame] | 2335 | func Test_prop_shift_block() |
| 2336 | new |
| 2337 | call AddPropTypes() |
| 2338 | |
| 2339 | call setline(1, ['some highlighted text']->repeat(2)) |
| 2340 | call prop_add(1, 10, #{type: 'one', length: 11}) |
| 2341 | call prop_add(2, 10, #{type: 'two', length: 11}) |
| 2342 | |
| 2343 | call cursor(1, 1) |
| 2344 | call feedkeys("5l\<c-v>>", 'nxt') |
| 2345 | call cursor(2, 1) |
| 2346 | call feedkeys("5l\<c-v><", 'nxt') |
| 2347 | |
| 2348 | let expected = [ |
| 2349 | \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2350 | \ 'length': 11, 'start' : 1}, |
| 2351 | \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2352 | \ 'length': 11, 'start' : 1} |
| 2353 | \ ] |
| 2354 | call assert_equal(expected, prop_list(1, #{end_lnum: 2})) |
| 2355 | |
| 2356 | call DeletePropTypes() |
| 2357 | bwipe! |
| 2358 | endfunc |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2359 | |
LemonBoy | 698cb4c | 2022-05-14 18:10:15 +0100 | [diff] [blame] | 2360 | func Test_prop_insert_multiline() |
| 2361 | new |
| 2362 | call AddPropTypes() |
| 2363 | |
| 2364 | call setline(1, ['foobar', 'barbaz']) |
| 2365 | call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'}) |
| 2366 | |
| 2367 | call feedkeys("1Goquxqux\<Esc>", 'nxt') |
| 2368 | call feedkeys("2GOquxqux\<Esc>", 'nxt') |
| 2369 | |
| 2370 | let lines =<< trim END |
| 2371 | foobar |
| 2372 | quxqux |
| 2373 | quxqux |
| 2374 | barbaz |
| 2375 | END |
| 2376 | call assert_equal(lines, getline(1, '$')) |
| 2377 | let expected = [ |
| 2378 | \ {'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] | 2379 | \ 'length': 4 , 'start': 1}, |
LemonBoy | 698cb4c | 2022-05-14 18:10:15 +0100 | [diff] [blame] | 2380 | \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2381 | \ 'length': 7, 'start': 0}, |
| 2382 | \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2383 | \ 'length': 7, 'start': 0}, |
| 2384 | \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2385 | \ 'length': 3, 'start': 0} |
| 2386 | \ ] |
| 2387 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2388 | |
| 2389 | call DeletePropTypes() |
| 2390 | bwipe! |
| 2391 | endfunc |
| 2392 | |
LemonBoy | b559b30 | 2022-05-15 13:08:02 +0100 | [diff] [blame] | 2393 | func Test_prop_blockwise_change() |
| 2394 | new |
| 2395 | call AddPropTypes() |
| 2396 | |
| 2397 | call setline(1, ['foooooo', 'bar', 'baaaaz']) |
| 2398 | call prop_add(1, 1, #{end_col: 3, type: 'one'}) |
| 2399 | call prop_add(2, 1, #{end_col: 3, type: 'two'}) |
| 2400 | call prop_add(3, 1, #{end_col: 3, type: 'three'}) |
| 2401 | |
| 2402 | " Replace the first two columns with '123', since 'start_incl' is false the |
| 2403 | " prop is not extended. |
| 2404 | call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt') |
| 2405 | |
| 2406 | let lines =<< trim END |
| 2407 | 123oooooo |
| 2408 | 123ar |
| 2409 | 123aaaaz |
| 2410 | END |
| 2411 | call assert_equal(lines, getline(1, '$')) |
| 2412 | let expected = [ |
| 2413 | \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2414 | \ 'length': 1, 'start': 1}, |
| 2415 | \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2416 | \ 'length': 1, 'start': 1}, |
| 2417 | \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 , |
| 2418 | \ 'type': 'three', 'length': 1, 'start': 1} |
| 2419 | \ ] |
| 2420 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2421 | |
| 2422 | call DeletePropTypes() |
| 2423 | bwipe! |
| 2424 | endfunc |
| 2425 | |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2426 | func Do_test_props_do_not_affect_byte_offsets(ff, increment) |
| 2427 | new |
| 2428 | let lcount = 410 |
| 2429 | |
| 2430 | " File format affects byte-offset calculations, so make sure it is known. |
| 2431 | exec 'setlocal fileformat=' . a:ff |
| 2432 | |
| 2433 | " Fill the buffer with varying length lines. We need a suitably large number |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2434 | " to force Vim code through paths where previous error have occurred. This |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2435 | " is more 'art' than 'science'. |
| 2436 | let text = 'a' |
| 2437 | call setline(1, text) |
| 2438 | let offsets = [1] |
| 2439 | for idx in range(lcount) |
| 2440 | call add(offsets, offsets[idx] + len(text) + a:increment) |
| 2441 | if (idx % 6) == 0 |
| 2442 | let text = text . 'a' |
| 2443 | endif |
| 2444 | call append(line('$'), text) |
| 2445 | endfor |
| 2446 | |
| 2447 | " Set a property that spans a few lines to cause Vim's internal buffer code |
| 2448 | " to perform a reasonable amount of rearrangement. |
| 2449 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2450 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2}) |
| 2451 | |
| 2452 | for idx in range(lcount) |
| 2453 | let boff = line2byte(idx + 1) |
| 2454 | call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1)) |
| 2455 | endfor |
| 2456 | |
| 2457 | call prop_type_delete('one') |
| 2458 | bwipe! |
| 2459 | endfunc |
| 2460 | |
| 2461 | func Test_props_do_not_affect_byte_offsets() |
| 2462 | call Do_test_props_do_not_affect_byte_offsets('unix', 1) |
| 2463 | endfunc |
| 2464 | |
| 2465 | func Test_props_do_not_affect_byte_offsets_dos() |
| 2466 | call Do_test_props_do_not_affect_byte_offsets('dos', 2) |
| 2467 | endfunc |
| 2468 | |
| 2469 | func Test_props_do_not_affect_byte_offsets_editline() |
| 2470 | new |
| 2471 | let lcount = 410 |
| 2472 | |
| 2473 | " File format affects byte-offset calculations, so make sure it is known. |
| 2474 | setlocal fileformat=unix |
| 2475 | |
| 2476 | " Fill the buffer with varying length lines. We need a suitably large number |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2477 | " to force Vim code through paths where previous error have occurred. This |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2478 | " is more 'art' than 'science'. |
| 2479 | let text = 'aa' |
| 2480 | call setline(1, text) |
| 2481 | let offsets = [1] |
| 2482 | for idx in range(lcount) |
| 2483 | call add(offsets, offsets[idx] + len(text) + 1) |
| 2484 | if (idx % 6) == 0 |
| 2485 | let text = text . 'a' |
| 2486 | endif |
| 2487 | call append(line('$'), text) |
| 2488 | endfor |
| 2489 | |
| 2490 | " Set a property that just covers the first line. When this test was |
| 2491 | " developed, this did not trigger a byte-offset error. |
| 2492 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2493 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3}) |
| 2494 | |
| 2495 | for idx in range(lcount) |
| 2496 | let boff = line2byte(idx + 1) |
| 2497 | call assert_equal(offsets[idx], boff, |
| 2498 | \ 'Confounding bad byte offset at line ' . (idx + 1)) |
| 2499 | endfor |
| 2500 | |
| 2501 | " Insert text in the middle of the first line, keeping the property |
| 2502 | " unchanged. |
| 2503 | :1 |
| 2504 | normal aHello |
| 2505 | for idx in range(1, lcount) |
| 2506 | let offsets[idx] = offsets[idx] + 5 |
| 2507 | endfor |
| 2508 | |
| 2509 | for idx in range(lcount) |
| 2510 | let boff = line2byte(idx + 1) |
| 2511 | call assert_equal(offsets[idx], boff, |
| 2512 | \ 'Bad byte offset at line ' . (idx + 1)) |
| 2513 | endfor |
| 2514 | |
| 2515 | call prop_type_delete('one') |
| 2516 | bwipe! |
| 2517 | endfunc |
| 2518 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2519 | func Test_prop_inserts_text() |
| 2520 | CheckRunVimInTerminal |
| 2521 | |
| 2522 | " Just a basic check for now |
| 2523 | let lines =<< trim END |
| 2524 | call setline(1, 'insert some text here and other text there and some more text after wrapping') |
| 2525 | call prop_type_add('someprop', #{highlight: 'ErrorMsg'}) |
| 2526 | call prop_type_add('otherprop', #{highlight: 'Search'}) |
| 2527 | call prop_type_add('moreprop', #{highlight: 'DiffAdd'}) |
| 2528 | call prop_add(1, 18, #{type: 'someprop', text: 'SOME '}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 2529 | call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2530 | call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2531 | normal $ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2532 | |
| 2533 | call setline(2, 'prepost') |
| 2534 | call prop_type_add('multibyte', #{highlight: 'Visual'}) |
| 2535 | call prop_add(2, 4, #{type: 'multibyte', text: 'söme和平téxt'}) |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2536 | |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2537 | call setline(3, 'Foo foo = { 1, 2 };') |
Bram Moolenaar | 3331dd0 | 2022-08-10 16:49:02 +0100 | [diff] [blame] | 2538 | call prop_type_add('testprop', #{highlight: 'Comment'}) |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2539 | call prop_add(3, 13, #{type: 'testprop', text: '.x='}) |
| 2540 | call prop_add(3, 16, #{type: 'testprop', text: '.y='}) |
| 2541 | |
| 2542 | call setline(4, '') |
| 2543 | call prop_add(4, 1, #{type: 'someprop', text: 'empty line'}) |
Bram Moolenaar | 3331dd0 | 2022-08-10 16:49:02 +0100 | [diff] [blame] | 2544 | |
| 2545 | call setline(5, 'look highlight') |
| 2546 | call prop_type_add('nohi', #{}) |
| 2547 | call prop_add(5, 6, #{type: 'nohi', text: 'no '}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2548 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2549 | call writefile(lines, 'XscriptPropsWithText', 'D') |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2550 | let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 8, cols: 60}) |
Bram Moolenaar | 711483c | 2022-07-30 21:33:46 +0100 | [diff] [blame] | 2551 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {}) |
| 2552 | |
| 2553 | call term_sendkeys(buf, ":set signcolumn=yes\<CR>") |
| 2554 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2555 | |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2556 | call term_sendkeys(buf, "2G$") |
| 2557 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {}) |
| 2558 | |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2559 | call term_sendkeys(buf, "3Gf1") |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2560 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {}) |
Bram Moolenaar | 2546361 | 2022-08-08 11:07:47 +0100 | [diff] [blame] | 2561 | call term_sendkeys(buf, "f2") |
| 2562 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_5', {}) |
| 2563 | |
| 2564 | call term_sendkeys(buf, "4G") |
| 2565 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_6', {}) |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2566 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2567 | call StopVimInTerminal(buf) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2568 | endfunc |
| 2569 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2570 | func Test_prop_inserts_text_highlight() |
| 2571 | CheckRunVimInTerminal |
| 2572 | |
| 2573 | " Just a basic check for now |
| 2574 | let lines =<< trim END |
| 2575 | call setline(1, 'insert some text (here) and there') |
| 2576 | call prop_type_add('someprop', #{highlight: 'ErrorMsg'}) |
| 2577 | let bef_prop = prop_add(1, 18, #{type: 'someprop', text: 'BEFORE'}) |
| 2578 | set hlsearch |
| 2579 | let thematch = matchaddpos("DiffAdd", [[1, 18]]) |
| 2580 | func DoAfter() |
| 2581 | call prop_remove(#{id: g:bef_prop}) |
| 2582 | call prop_add(1, 19, #{type: 'someprop', text: 'AFTER'}) |
| 2583 | let g:thematch = matchaddpos("DiffAdd", [[1, 18]]) |
| 2584 | let @/ = '' |
| 2585 | endfunc |
| 2586 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2587 | call writefile(lines, 'XscriptPropsWithHighlight', 'D') |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2588 | let buf = RunVimInTerminal('-S XscriptPropsWithHighlight', #{rows: 6, cols: 60}) |
| 2589 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_1', {}) |
| 2590 | call term_sendkeys(buf, "/text (he\<CR>") |
| 2591 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_2', {}) |
| 2592 | call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>") |
| 2593 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_3', {}) |
| 2594 | |
| 2595 | call term_sendkeys(buf, ":call DoAfter()\<CR>") |
| 2596 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_4', {}) |
| 2597 | call term_sendkeys(buf, "/text (he\<CR>") |
| 2598 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_5', {}) |
| 2599 | call term_sendkeys(buf, ":call matchdelete(thematch)\<CR>") |
| 2600 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_hi_6', {}) |
| 2601 | |
| 2602 | call StopVimInTerminal(buf) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2603 | endfunc |
| 2604 | |
Bram Moolenaar | fb593c5 | 2022-09-17 18:57:36 +0100 | [diff] [blame] | 2605 | func Test_prop_add_with_text_fails() |
| 2606 | call prop_type_add('failing', #{highlight: 'ErrorMsg'}) |
| 2607 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_lnum: 1})", 'E1305:') |
| 2608 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', end_col: 1})", 'E1305:') |
| 2609 | call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', length: 1})", 'E1305:') |
| 2610 | |
| 2611 | call prop_type_delete('failing') |
| 2612 | endfunc |
| 2613 | |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2614 | func Test_props_with_text_right_align_twice() |
| 2615 | CheckRunVimInTerminal |
| 2616 | |
| 2617 | let lines =<< trim END |
| 2618 | 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] | 2619 | call prop_type_add('MyErrorText', #{highlight: 'ErrorMsg'}) |
| 2620 | call prop_type_add('MyPadding', #{highlight: 'DiffChange'}) |
Bram Moolenaar | c8bf59e | 2022-08-28 16:39:22 +0100 | [diff] [blame] | 2621 | call prop_add(1, 0, #{type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'}) |
| 2622 | call prop_add(1, 0, #{type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right'}) |
| 2623 | 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] | 2624 | normal G$ |
| 2625 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2626 | call writefile(lines, 'XscriptPropsRightAlign', 'D') |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2627 | let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8}) |
| 2628 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {}) |
| 2629 | |
| 2630 | call term_sendkeys(buf, "ggisome more text\<Esc>G$") |
| 2631 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {}) |
| 2632 | |
Bram Moolenaar | c8bf59e | 2022-08-28 16:39:22 +0100 | [diff] [blame] | 2633 | call term_sendkeys(buf, ":set signcolumn=yes\<CR>") |
| 2634 | call VerifyScreenDump(buf, 'Test_prop_right_align_twice_3', {}) |
| 2635 | |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2636 | call StopVimInTerminal(buf) |
Bram Moolenaar | f0ccfa4 | 2022-08-13 16:41:19 +0100 | [diff] [blame] | 2637 | endfunc |
| 2638 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2639 | func Test_props_with_text_after() |
| 2640 | CheckRunVimInTerminal |
| 2641 | |
| 2642 | let lines =<< trim END |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2643 | set showbreak=+++ |
Bram Moolenaar | 73c3842 | 2022-08-07 11:53:40 +0100 | [diff] [blame] | 2644 | set breakindent |
| 2645 | call setline(1, ' some text here and other text there') |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2646 | call prop_type_add('rightprop', #{highlight: 'ErrorMsg'}) |
| 2647 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2648 | call prop_type_add('belowprop', #{highlight: 'DiffAdd'}) |
| 2649 | call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 2650 | 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] | 2651 | call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'}) |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 2652 | 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] | 2653 | |
| 2654 | call setline(2, 'Last line.') |
| 2655 | call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'}) |
| 2656 | normal G$ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2657 | |
| 2658 | call setline(3, 'right here') |
| 2659 | 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] | 2660 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2661 | call writefile(lines, 'XscriptPropsWithTextAfter', 'D') |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 2662 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60}) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2663 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {}) |
| 2664 | |
| 2665 | call StopVimInTerminal(buf) |
Bram Moolenaar | 82b14c1 | 2022-08-10 19:50:47 +0100 | [diff] [blame] | 2666 | |
| 2667 | 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] | 2668 | endfunc |
| 2669 | |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 2670 | func Test_props_with_text_after_and_list() |
| 2671 | CheckRunVimInTerminal |
| 2672 | |
| 2673 | let lines =<< trim END |
| 2674 | vim9script |
| 2675 | setline(1, ['one', 'two']) |
| 2676 | prop_type_add('test', {highlight: 'Special'}) |
| 2677 | prop_add(1, 0, { |
| 2678 | type: 'test', |
| 2679 | text: range(50)->join(' '), |
| 2680 | text_align: 'after', |
| 2681 | text_padding_left: 3 |
| 2682 | }) |
| 2683 | prop_add(1, 0, { |
| 2684 | type: 'test', |
| 2685 | text: range(50)->join('-'), |
| 2686 | text_align: 'after', |
| 2687 | text_padding_left: 5 |
| 2688 | }) |
| 2689 | prop_add(1, 0, { |
| 2690 | type: 'test', |
| 2691 | text: range(50)->join('.'), |
| 2692 | text_align: 'after', |
| 2693 | text_padding_left: 1 |
| 2694 | }) |
| 2695 | normal G$ |
| 2696 | END |
| 2697 | call writefile(lines, 'XscriptPropsAfter', 'D') |
| 2698 | let buf = RunVimInTerminal('-S XscriptPropsAfter', #{rows: 8, cols: 60}) |
| 2699 | call VerifyScreenDump(buf, 'Test_props_after_1', {}) |
| 2700 | |
| 2701 | call term_sendkeys(buf, ":set list\<CR>") |
| 2702 | call VerifyScreenDump(buf, 'Test_props_after_2', {}) |
| 2703 | |
| 2704 | call StopVimInTerminal(buf) |
| 2705 | endfunc |
| 2706 | |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2707 | func Test_props_with_text_after_below_trunc() |
| 2708 | CheckRunVimInTerminal |
| 2709 | |
| 2710 | let lines =<< trim END |
| 2711 | vim9script |
| 2712 | edit foobar |
| 2713 | set showbreak=+++ |
| 2714 | setline(1, ['onasdf asdf asdf asdf asd fas df', 'two']) |
| 2715 | prop_type_add('test', {highlight: 'Special'}) |
| 2716 | prop_add(1, 0, { |
| 2717 | type: 'test', |
| 2718 | text: 'the quick brown fox jumps over the lazy dog', |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2719 | text_align: 'after', |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2720 | }) |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2721 | prop_type_add('another', {highlight: 'DiffChange'}) |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2722 | prop_add(1, 0, { |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2723 | type: 'another', |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2724 | text: 'the quick brown fox jumps over the lazy dog', |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2725 | text_align: 'below', |
| 2726 | text_padding_left: 4, |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2727 | }) |
| 2728 | normal G$ |
| 2729 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2730 | call writefile(lines, 'XscriptPropsAfterTrunc', 'D') |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2731 | let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60}) |
| 2732 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {}) |
| 2733 | |
Bram Moolenaar | ccf2837 | 2022-10-10 21:10:03 +0100 | [diff] [blame] | 2734 | call term_sendkeys(buf, ":set number\<CR>") |
| 2735 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_2', {}) |
| 2736 | |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2737 | call term_sendkeys(buf, ":set cursorline\<CR>gg") |
| 2738 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_3', {}) |
| 2739 | |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2740 | call StopVimInTerminal(buf) |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2741 | endfunc |
| 2742 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 2743 | func Test_prop_with_text_below_after_empty() |
| 2744 | CheckRunVimInTerminal |
| 2745 | |
| 2746 | let lines =<< trim END |
| 2747 | vim9script |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 2748 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 2749 | setline(1, ['vim9script', '', 'three', '']) |
| 2750 | |
| 2751 | # Add text prop below empty line 2 with padding. |
| 2752 | prop_type_add('test', {highlight: 'ErrorMsg'}) |
| 2753 | prop_add(2, 0, { |
| 2754 | type: 'test', |
| 2755 | text: 'The quick brown fox jumps over the lazy dog', |
| 2756 | text_align: 'below', |
| 2757 | text_padding_left: 1, |
| 2758 | }) |
| 2759 | |
| 2760 | # Add text prop below empty line 4 without padding. |
| 2761 | prop_type_add('other', {highlight: 'DiffChange'}) |
| 2762 | prop_add(4, 0, { |
| 2763 | type: 'other', |
| 2764 | text: 'The slow fox bumps into the lazy dog', |
| 2765 | text_align: 'below', |
| 2766 | text_padding_left: 0, |
| 2767 | }) |
| 2768 | END |
| 2769 | call writefile(lines, 'XscriptPropBelowAfterEmpty', 'D') |
| 2770 | let buf = RunVimInTerminal('-S XscriptPropBelowAfterEmpty', #{rows: 8, cols: 60}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 2771 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_1', {}) |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 2772 | |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 2773 | call term_sendkeys(buf, ":set number\<CR>") |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 2774 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {}) |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 2775 | |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2776 | call term_sendkeys(buf, ":set nowrap\<CR>") |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 2777 | call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {}) |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2778 | |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 2779 | call StopVimInTerminal(buf) |
| 2780 | endfunc |
| 2781 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2782 | func Test_prop_with_text_above_below_empty() |
| 2783 | CheckRunVimInTerminal |
| 2784 | |
| 2785 | let lines =<< trim END |
| 2786 | setlocal number |
| 2787 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 2788 | |
| 2789 | let vt = 'test' |
| 2790 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 2791 | for ln in range(1, line('$')) |
| 2792 | call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'}) |
| 2793 | call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'}) |
| 2794 | endfor |
| 2795 | normal G |
| 2796 | END |
| 2797 | call writefile(lines, 'XscriptPropAboveBelowEmpty', 'D') |
| 2798 | let buf = RunVimInTerminal('-S XscriptPropAboveBelowEmpty', #{rows: 16, cols: 60}) |
| 2799 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_1', {}) |
| 2800 | |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 2801 | call term_sendkeys(buf, ":set list\<CR>") |
| 2802 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_2', {}) |
| 2803 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 2804 | call term_sendkeys(buf, ":set nolist\<CR>") |
| 2805 | call term_sendkeys(buf, ":set colorcolumn=10\<CR>") |
| 2806 | call term_sendkeys(buf, ":\<CR>") |
| 2807 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_3', {}) |
| 2808 | |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 2809 | call term_sendkeys(buf, ":set colorcolumn=\<CR>") |
| 2810 | call term_sendkeys(buf, ":set relativenumber\<CR>") |
| 2811 | call term_sendkeys(buf, ":\<CR>") |
| 2812 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_4', {}) |
| 2813 | |
| 2814 | call term_sendkeys(buf, "kk") |
| 2815 | call VerifyScreenDump(buf, 'Test_prop_above_below_empty_5', {}) |
| 2816 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2817 | call StopVimInTerminal(buf) |
| 2818 | endfunc |
| 2819 | |
Bram Moolenaar | ea62cee | 2023-02-19 18:36:41 +0000 | [diff] [blame] | 2820 | func Test_prop_with_multibyte_below() |
| 2821 | CheckRunVimInTerminal |
| 2822 | |
| 2823 | let lines =<< trim END |
| 2824 | setlocal number |
| 2825 | call setline(1, ['©', '©', '©']) |
| 2826 | |
| 2827 | let vt = 'test' |
| 2828 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 2829 | for ln in range(1, line('$')) |
| 2830 | call prop_add(ln, 0, {'type': vt, 'text': '+++', 'text_align': 'below'}) |
| 2831 | endfor |
| 2832 | normal G |
| 2833 | END |
| 2834 | call writefile(lines, 'XscriptPropMultibyteBelow', 'D') |
| 2835 | let buf = RunVimInTerminal('-S XscriptPropMultibyteBelow', #{rows: 10, cols: 60}) |
| 2836 | call VerifyScreenDump(buf, 'Test_prop_multibyte_below_1', {}) |
| 2837 | |
| 2838 | call StopVimInTerminal(buf) |
| 2839 | endfunc |
| 2840 | |
Bram Moolenaar | 5ceb815 | 2023-02-12 18:11:21 +0000 | [diff] [blame] | 2841 | func Test_prop_with_text_above_empty() |
| 2842 | CheckRunVimInTerminal |
| 2843 | |
| 2844 | " check the cursor is in the correct line |
| 2845 | let lines =<< trim END |
| 2846 | setlocal number |
| 2847 | call setline(1, ['11111111', '', '333333333', '', '55555555555']) |
| 2848 | |
| 2849 | let vt = 'test' |
| 2850 | call prop_type_add(vt, {'highlight': 'ToDo'}) |
| 2851 | for ln in range(1, line('$')) |
| 2852 | call prop_add(ln, 0, {'type': vt, 'text': '---', 'text_align': 'above'}) |
| 2853 | endfor |
| 2854 | normal G |
| 2855 | END |
| 2856 | call writefile(lines, 'XscriptPropAboveEmpty', 'D') |
| 2857 | let buf = RunVimInTerminal('-S XscriptPropAboveEmpty', #{rows: 16, cols: 60}) |
| 2858 | call VerifyScreenDump(buf, 'Test_prop_above_empty_1', {}) |
| 2859 | |
| 2860 | call term_sendkeys(buf, ":set list\<CR>") |
| 2861 | call VerifyScreenDump(buf, 'Test_prop_above_empty_2', {}) |
| 2862 | |
| 2863 | call StopVimInTerminal(buf) |
| 2864 | endfunc |
| 2865 | |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2866 | func Test_prop_with_text_below_after_match() |
| 2867 | CheckRunVimInTerminal |
| 2868 | |
| 2869 | let lines =<< trim END |
| 2870 | vim9script |
| 2871 | |
| 2872 | setline(1, ['vim9script', 'some text']) |
| 2873 | set signcolumn=yes |
| 2874 | matchaddpos('Search', [[1, 10]]) |
| 2875 | prop_type_add('test', {highlight: 'Error'}) |
| 2876 | prop_add(1, 0, { |
| 2877 | type: 'test', |
| 2878 | text: 'The quick brown fox', |
| 2879 | text_align: 'below' |
| 2880 | }) |
| 2881 | END |
| 2882 | call writefile(lines, 'XscriptPropsBelow', 'D') |
| 2883 | let buf = RunVimInTerminal('-S XscriptPropsBelow', #{rows: 8, cols: 60}) |
| 2884 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_after_match_1', {}) |
| 2885 | |
| 2886 | call StopVimInTerminal(buf) |
| 2887 | endfunc |
| 2888 | |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 2889 | func Test_props_with_text_after_joined() |
| 2890 | CheckRunVimInTerminal |
| 2891 | |
| 2892 | let lines =<< trim END |
| 2893 | call setline(1, ['one', 'two', 'three', 'four']) |
| 2894 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2895 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'}) |
| 2896 | call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'}) |
| 2897 | normal ggJ |
| 2898 | normal GkJ |
| 2899 | |
| 2900 | call setline(3, ['a', 'b', 'c', 'd', 'e', 'f']) |
| 2901 | call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'}) |
| 2902 | call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'}) |
| 2903 | call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'}) |
| 2904 | call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'}) |
| 2905 | normal 3G6J |
| 2906 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2907 | call writefile(lines, 'XscriptPropsWithTextAfterJoined', 'D') |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 2908 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60}) |
| 2909 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {}) |
| 2910 | |
| 2911 | call StopVimInTerminal(buf) |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 2912 | endfunc |
| 2913 | |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2914 | func Test_props_with_text_after_truncated() |
| 2915 | CheckRunVimInTerminal |
| 2916 | |
| 2917 | let lines =<< trim END |
| 2918 | call setline(1, ['one two three four five six seven']) |
| 2919 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2920 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'}) |
| 2921 | |
| 2922 | call setline(2, ['one two three four five six seven']) |
| 2923 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'}) |
| 2924 | |
| 2925 | call setline(3, ['one two three four five six seven']) |
| 2926 | 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'}) |
| 2927 | |
| 2928 | call setline(4, ['cursor here']) |
| 2929 | normal 4Gfh |
| 2930 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2931 | call writefile(lines, 'XscriptPropsWithTextAfterTrunc', 'D') |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2932 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60}) |
| 2933 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {}) |
| 2934 | |
| 2935 | call term_sendkeys(buf, ":37vsp\<CR>gg") |
| 2936 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {}) |
| 2937 | |
| 2938 | call term_sendkeys(buf, ":36wincmd |\<CR>") |
| 2939 | call term_sendkeys(buf, "2G$") |
| 2940 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {}) |
| 2941 | |
| 2942 | call term_sendkeys(buf, ":33wincmd |\<CR>") |
| 2943 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {}) |
| 2944 | |
| 2945 | call term_sendkeys(buf, ":18wincmd |\<CR>") |
| 2946 | call term_sendkeys(buf, "0fx") |
| 2947 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {}) |
| 2948 | |
| 2949 | call StopVimInTerminal(buf) |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2950 | endfunc |
| 2951 | |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 2952 | func Test_props_with_text_empty_line() |
| 2953 | CheckRunVimInTerminal |
| 2954 | |
| 2955 | let lines =<< trim END |
| 2956 | call setline(1, ['', 'aaa', '', 'bbbbbb']) |
| 2957 | call prop_type_add('prop1', #{highlight: 'Search'}) |
| 2958 | call prop_add(1, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns)}) |
| 2959 | call prop_add(3, 1, #{type: 'prop1', text_wrap: 'wrap', text: repeat('X', &columns + 1)}) |
| 2960 | normal gg0 |
| 2961 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2962 | call writefile(lines, 'XscriptPropsWithTextEmptyLine', 'D') |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 2963 | let buf = RunVimInTerminal('-S XscriptPropsWithTextEmptyLine', #{rows: 8, cols: 60}) |
| 2964 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_1', {}) |
| 2965 | call term_sendkeys(buf, "$") |
| 2966 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_2', {}) |
| 2967 | call term_sendkeys(buf, "j") |
| 2968 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_3', {}) |
| 2969 | call term_sendkeys(buf, "j") |
| 2970 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_4', {}) |
| 2971 | call term_sendkeys(buf, "j") |
| 2972 | call VerifyScreenDump(buf, 'Test_prop_with_text_empty_line_5', {}) |
| 2973 | |
| 2974 | call StopVimInTerminal(buf) |
Bram Moolenaar | 49a9079 | 2022-08-09 18:25:23 +0100 | [diff] [blame] | 2975 | endfunc |
| 2976 | |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2977 | func Test_props_with_text_after_wraps() |
| 2978 | CheckRunVimInTerminal |
| 2979 | |
| 2980 | let lines =<< trim END |
| 2981 | call setline(1, ['one two three four five six seven']) |
| 2982 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2983 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'}) |
| 2984 | |
| 2985 | call setline(2, ['one two three four five six seven']) |
| 2986 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'}) |
| 2987 | |
| 2988 | call setline(3, ['one two three four five six seven']) |
| 2989 | 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'}) |
| 2990 | |
| 2991 | call setline(4, ['cursor here']) |
| 2992 | normal 4Gfh |
| 2993 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 2994 | call writefile(lines, 'XscriptPropsWithTextAfterWraps', 'D') |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2995 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60}) |
| 2996 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {}) |
| 2997 | |
| 2998 | call StopVimInTerminal(buf) |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2999 | endfunc |
| 3000 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3001 | func Test_props_with_text_after_nowrap() |
| 3002 | CheckRunVimInTerminal |
| 3003 | |
| 3004 | let lines =<< trim END |
| 3005 | set nowrap |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3006 | call setline(1, ['one', 'two', 'three', 'four']) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3007 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 3008 | call prop_type_add('anotherprop', #{highlight: 'Search'}) |
Bram Moolenaar | db9b96d | 2022-08-06 17:38:53 +0100 | [diff] [blame] | 3009 | call prop_type_add('someprop', #{highlight: 'DiffChange'}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3010 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 3011 | call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'}) |
| 3012 | 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] | 3013 | call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'}) |
| 3014 | 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] | 3015 | normal 3G$ |
| 3016 | |
| 3017 | call prop_add(3, 0, #{type: 'anotherprop', text: 'right aligned', text_align: 'right'}) |
| 3018 | 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] | 3019 | hi CursorLine ctermbg=lightgrey |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3020 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3021 | call writefile(lines, 'XscriptPropsAfterNowrap', 'D') |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3022 | let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3023 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {}) |
| 3024 | |
Bram Moolenaar | 9113c2c | 2022-08-13 20:17:34 +0100 | [diff] [blame] | 3025 | call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\<CR>") |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3026 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {}) |
| 3027 | |
Bram Moolenaar | 8f369fb | 2022-08-13 19:35:05 +0100 | [diff] [blame] | 3028 | call term_sendkeys(buf, "j") |
| 3029 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_3', {}) |
| 3030 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3031 | call StopVimInTerminal(buf) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3032 | endfunc |
| 3033 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3034 | func Test_prop_with_text_below_cul() |
| 3035 | CheckRunVimInTerminal |
| 3036 | |
| 3037 | let lines =<< trim END |
| 3038 | vim9script |
| 3039 | |
| 3040 | setline(1, ['some text', 'last line']) |
| 3041 | set cursorline nowrap |
| 3042 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3043 | prop_add(1, 0, { |
| 3044 | type: 'test', |
| 3045 | text: 'The quick brown fox jumps over the lazy dog', |
| 3046 | text_align: 'below', |
| 3047 | text_padding_left: 4, |
| 3048 | }) |
| 3049 | END |
| 3050 | call writefile(lines, 'XscriptPropsBelowCurline', 'D') |
| 3051 | let buf = RunVimInTerminal('-S XscriptPropsBelowCurline', #{rows: 6, cols: 60}) |
| 3052 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_cul_1', {}) |
| 3053 | |
| 3054 | call StopVimInTerminal(buf) |
| 3055 | endfunc |
| 3056 | |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3057 | func Test_props_with_text_below_nowrap() |
| 3058 | CheckRunVimInTerminal |
| 3059 | |
| 3060 | let lines =<< trim END |
| 3061 | vim9script |
| 3062 | edit foobar |
| 3063 | set nowrap |
| 3064 | set showbreak=+++\ |
| 3065 | setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two']) |
| 3066 | prop_type_add('test', {highlight: 'Special'}) |
| 3067 | prop_add(1, 0, { |
| 3068 | type: 'test', |
| 3069 | text: 'the quick brown fox jumps over the lazy dog', |
| 3070 | text_align: 'after' |
| 3071 | }) |
| 3072 | prop_add(1, 0, { |
| 3073 | type: 'test', |
| 3074 | text: 'the quick brown fox jumps over the lazy dog', |
| 3075 | text_align: 'below' |
| 3076 | }) |
| 3077 | normal G$ |
| 3078 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3079 | call writefile(lines, 'XscriptPropsBelowNowrap', 'D') |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3080 | let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60}) |
| 3081 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {}) |
| 3082 | |
| 3083 | call term_sendkeys(buf, "gg$") |
| 3084 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {}) |
| 3085 | |
| 3086 | call StopVimInTerminal(buf) |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 3087 | endfunc |
| 3088 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3089 | func Test_props_with_text_above() |
| 3090 | CheckRunVimInTerminal |
| 3091 | |
| 3092 | let lines =<< trim END |
| 3093 | call setline(1, ['one two', 'three four', 'five six']) |
| 3094 | call prop_type_add('above1', #{highlight: 'Search'}) |
| 3095 | call prop_type_add('above2', #{highlight: 'DiffChange'}) |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3096 | call prop_type_add('below', #{highlight: 'DiffAdd'}) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3097 | call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'}) |
| 3098 | 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] | 3099 | 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] | 3100 | |
| 3101 | normal gglllj |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3102 | func AddPropBelow() |
| 3103 | call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'}) |
| 3104 | endfunc |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 3105 | func AddLongPropAbove() |
| 3106 | 3,4delete |
| 3107 | set wrap |
| 3108 | call prop_add(1, 0, #{type: 'above1', text: range(50)->join(' '), text_align: 'above', text_padding_left: 2}) |
| 3109 | endfunc |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3110 | END |
| 3111 | call writefile(lines, 'XscriptPropsWithTextAbove', 'D') |
| 3112 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60}) |
| 3113 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1', {}) |
| 3114 | |
Bram Moolenaar | e24b4ab | 2022-09-16 20:51:14 +0100 | [diff] [blame] | 3115 | call term_sendkeys(buf, "ggg$") |
| 3116 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1a', {}) |
| 3117 | call term_sendkeys(buf, "g0") |
| 3118 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1b', {}) |
| 3119 | |
Bram Moolenaar | 4c7fd4d | 2022-09-17 17:15:33 +0100 | [diff] [blame] | 3120 | call term_sendkeys(buf, ":set showbreak=>>\<CR>") |
| 3121 | call term_sendkeys(buf, "ggll") |
| 3122 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_1c', {}) |
| 3123 | call term_sendkeys(buf, ":set showbreak=\<CR>") |
| 3124 | |
Bram Moolenaar | 88b79cb | 2022-09-10 22:32:14 +0100 | [diff] [blame] | 3125 | call term_sendkeys(buf, "ggI") |
| 3126 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_2', {}) |
| 3127 | call term_sendkeys(buf, "inserted \<Esc>") |
| 3128 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_3', {}) |
| 3129 | |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 3130 | call term_sendkeys(buf, ":set number signcolumn=yes\<CR>") |
| 3131 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_4', {}) |
| 3132 | |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 3133 | call term_sendkeys(buf, ":set nowrap\<CR>gg$j") |
| 3134 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {}) |
| 3135 | |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 3136 | call term_sendkeys(buf, ":call AddPropBelow()\<CR>") |
| 3137 | call term_sendkeys(buf, "ggve") |
| 3138 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {}) |
| 3139 | call term_sendkeys(buf, "V") |
| 3140 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {}) |
| 3141 | |
Bram Moolenaar | 3b93cf2 | 2022-09-13 18:34:18 +0100 | [diff] [blame] | 3142 | call term_sendkeys(buf, "\<Esc>ls\<CR>\<Esc>") |
| 3143 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_8', {}) |
| 3144 | |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 3145 | call term_sendkeys(buf, ":call AddLongPropAbove()\<CR>") |
| 3146 | call VerifyScreenDump(buf, 'Test_prop_with_text_above_9', {}) |
| 3147 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 3148 | call StopVimInTerminal(buf) |
| 3149 | endfunc |
| 3150 | |
Bram Moolenaar | 702bd6c | 2022-09-14 16:09:57 +0100 | [diff] [blame] | 3151 | func Test_prop_above_with_indent() |
| 3152 | new |
| 3153 | call setline(1, ['first line', ' second line', ' line below']) |
| 3154 | setlocal cindent |
| 3155 | call prop_type_add('indented', #{highlight: 'Search'}) |
| 3156 | call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4}) |
| 3157 | call assert_equal(' line below', getline(3)) |
| 3158 | |
| 3159 | exe "normal 3G2|a\<CR>" |
| 3160 | call assert_equal(' ', getline(3)) |
| 3161 | call assert_equal(' line below', getline(4)) |
| 3162 | |
| 3163 | bwipe! |
| 3164 | call prop_type_delete('indented') |
| 3165 | endfunc |
| 3166 | |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 3167 | func Test_prop_above_with_number() |
| 3168 | CheckRunVimInTerminal |
| 3169 | |
| 3170 | let lines =<< trim END |
| 3171 | vim9script |
| 3172 | setline(1, ['one one one', 'two two two', 'three three three']) |
| 3173 | set number cpo+=n |
| 3174 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3175 | prop_add(2, 0, { |
| 3176 | text: 'above the text', |
| 3177 | type: 'test', |
| 3178 | text_align: 'above', |
| 3179 | }) |
| 3180 | def g:OneMore() |
| 3181 | prop_add(2, 0, { |
| 3182 | text: 'also above the text', |
| 3183 | type: 'test', |
| 3184 | text_align: 'above', |
| 3185 | }) |
| 3186 | enddef |
| 3187 | END |
| 3188 | call writefile(lines, 'XscriptPropAboveNr', 'D') |
| 3189 | let buf = RunVimInTerminal('-S XscriptPropAboveNr', #{rows: 8}) |
| 3190 | call VerifyScreenDump(buf, 'Test_prop_above_number_1', {}) |
| 3191 | |
| 3192 | call term_sendkeys(buf, ":call OneMore()\<CR>") |
| 3193 | call VerifyScreenDump(buf, 'Test_prop_above_number_2', {}) |
| 3194 | |
| 3195 | call StopVimInTerminal(buf) |
| 3196 | endfunc |
| 3197 | |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3198 | func Test_prop_below_split_line() |
| 3199 | CheckRunVimInTerminal |
| 3200 | |
| 3201 | let lines =<< trim END |
| 3202 | vim9script |
| 3203 | setline(1, ['one one one', 'two two two', 'three three three']) |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3204 | prop_type_add('test', {highlight: 'Search'}) |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3205 | prop_add(2, 0, { |
| 3206 | text: '└─ Virtual text below the 2nd line', |
| 3207 | type: 'test', |
| 3208 | text_align: 'below', |
| 3209 | text_padding_left: 3 |
| 3210 | }) |
| 3211 | END |
| 3212 | call writefile(lines, 'XscriptPropBelowSpitLine', 'D') |
| 3213 | let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8}) |
| 3214 | call term_sendkeys(buf, "2GA\<CR>xx") |
| 3215 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {}) |
| 3216 | |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3217 | call term_sendkeys(buf, "\<Esc>:set number\<CR>") |
| 3218 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_2', {}) |
| 3219 | |
Bram Moolenaar | b84d565 | 2022-09-20 17:57:53 +0100 | [diff] [blame] | 3220 | call term_sendkeys(buf, ":set nowrap\<CR>") |
| 3221 | call VerifyScreenDump(buf, 'Test_prop_below_split_line_3', {}) |
| 3222 | |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3223 | call StopVimInTerminal(buf) |
| 3224 | endfunc |
| 3225 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 3226 | func Test_prop_above_below_smoothscroll() |
| 3227 | CheckRunVimInTerminal |
| 3228 | |
| 3229 | let lines =<< trim END |
| 3230 | vim9script |
| 3231 | setline(1, range(1, 10)->mapnew((_, v) => '" line ' .. v)) |
| 3232 | |
| 3233 | set smoothscroll wrap |
| 3234 | call prop_type_add('mytype', {highlight: 'DiffChange'}) |
| 3235 | call prop_add(3, 0, {text: "insert above", type: "mytype", text_align: 'above'}) |
| 3236 | call prop_add(5, 0, {text: "insert above 1", type: "mytype", text_align: 'above'}) |
| 3237 | call prop_add(5, 0, {text: "insert above 2", type: "mytype", text_align: 'above'}) |
| 3238 | call prop_add(7, 0, {text: "insert below", type: "mytype", text_align: 'below'}) |
| 3239 | call prop_add(9, 0, {text: "insert below 1", type: "mytype", text_align: 'below'}) |
| 3240 | call prop_add(9, 0, {text: "insert below 2", type: "mytype", text_align: 'below'}) |
| 3241 | END |
| 3242 | call writefile(lines, 'XscriptPropsSmoothscroll', 'D') |
| 3243 | let buf = RunVimInTerminal('-S XscriptPropsSmoothscroll', #{rows: 8, cols: 60}) |
| 3244 | call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_1', {}) |
| 3245 | |
| 3246 | for nr in range(2, 16) |
| 3247 | call term_sendkeys(buf, "\<C-E>") |
| 3248 | call VerifyScreenDump(buf, 'Test_prop_above_below_smoothscroll_' .. nr, {}) |
| 3249 | endfor |
| 3250 | |
| 3251 | call StopVimInTerminal(buf) |
| 3252 | endfunc |
| 3253 | |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3254 | func Test_props_with_text_override() |
| 3255 | CheckRunVimInTerminal |
| 3256 | |
| 3257 | let lines =<< trim END |
| 3258 | vim9script |
| 3259 | setline(1, 'some text here') |
| 3260 | hi Likethis ctermfg=blue ctermbg=cyan |
| 3261 | prop_type_add('prop', {highlight: 'Likethis', override: true}) |
| 3262 | prop_add(1, 6, {type: 'prop', text: ' inserted '}) |
| 3263 | hi CursorLine cterm=underline ctermbg=lightgrey |
| 3264 | set cursorline |
| 3265 | END |
Bram Moolenaar | ebd0e8b | 2022-09-14 22:13:59 +0100 | [diff] [blame] | 3266 | call writefile(lines, 'XscriptPropsOverride', 'D') |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3267 | let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60}) |
| 3268 | call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {}) |
| 3269 | |
| 3270 | call term_sendkeys(buf, ":set nocursorline\<CR>") |
| 3271 | call term_sendkeys(buf, "0llvfr") |
| 3272 | call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {}) |
| 3273 | |
| 3274 | call StopVimInTerminal(buf) |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 3275 | endfunc |
| 3276 | |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3277 | func Test_props_with_text_CursorMoved() |
| 3278 | CheckRunVimInTerminal |
| 3279 | |
| 3280 | let lines =<< trim END |
| 3281 | call setline(1, ['this is line one', 'this is line two', 'three', 'four', 'five']) |
| 3282 | |
| 3283 | call prop_type_add('prop', #{highlight: 'Error'}) |
| 3284 | let g:long_text = repeat('x', &columns * 2) |
| 3285 | |
| 3286 | let g:prop_id = v:null |
| 3287 | func! Update() |
| 3288 | if line('.') == 1 |
| 3289 | if g:prop_id == v:null |
| 3290 | let g:prop_id = prop_add(1, 0, #{type: 'prop', text_wrap: 'wrap', text: g:long_text}) |
| 3291 | endif |
| 3292 | elseif g:prop_id != v:null |
| 3293 | call prop_remove(#{id: g:prop_id}) |
| 3294 | let g:prop_id = v:null |
| 3295 | endif |
| 3296 | endfunc |
| 3297 | |
| 3298 | autocmd CursorMoved * call Update() |
| 3299 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3300 | call writefile(lines, 'XscriptPropsCursorMovec', 'D') |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3301 | let buf = RunVimInTerminal('-S XscriptPropsCursorMovec', #{rows: 8, cols: 60}) |
| 3302 | call term_sendkeys(buf, "gg0w") |
| 3303 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {}) |
| 3304 | |
| 3305 | call term_sendkeys(buf, "j") |
| 3306 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_2', {}) |
| 3307 | |
| 3308 | " back to the first state |
| 3309 | call term_sendkeys(buf, "k") |
| 3310 | call VerifyScreenDump(buf, 'Test_prop_with_text_cursormoved_1', {}) |
| 3311 | |
| 3312 | call StopVimInTerminal(buf) |
Bram Moolenaar | 326c5d3 | 2022-08-12 13:05:49 +0100 | [diff] [blame] | 3313 | endfunc |
| 3314 | |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3315 | func Test_props_with_text_after_split_join() |
| 3316 | CheckRunVimInTerminal |
| 3317 | |
| 3318 | let lines =<< trim END |
| 3319 | call setline(1, ['1122']) |
| 3320 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 3321 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 3322 | exe "normal f2i\<CR>\<Esc>" |
| 3323 | |
| 3324 | func AddMore() |
| 3325 | call prop_type_add('another', #{highlight: 'Search'}) |
| 3326 | call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'}) |
| 3327 | call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'}) |
| 3328 | endfunc |
| 3329 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3330 | call writefile(lines, 'XscriptPropsAfterSplitJoin', 'D') |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3331 | let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60}) |
| 3332 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {}) |
| 3333 | |
| 3334 | call term_sendkeys(buf, "ggJ") |
| 3335 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {}) |
| 3336 | |
| 3337 | call term_sendkeys(buf, ":call AddMore()\<CR>") |
| 3338 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {}) |
| 3339 | |
| 3340 | call term_sendkeys(buf, "ggf s\<CR>\<Esc>") |
| 3341 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {}) |
| 3342 | |
| 3343 | call term_sendkeys(buf, "ggJ") |
| 3344 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {}) |
| 3345 | |
| 3346 | call StopVimInTerminal(buf) |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 3347 | endfunc |
| 3348 | |
Bram Moolenaar | 3a4cd39 | 2022-07-30 22:17:18 +0100 | [diff] [blame] | 3349 | func Test_removed_prop_with_text_cleans_up_array() |
| 3350 | new |
| 3351 | call setline(1, 'some text here') |
| 3352 | call prop_type_add('some', #{highlight: 'ErrorMsg'}) |
| 3353 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 3354 | call assert_equal(-1, id1) |
| 3355 | let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"}) |
| 3356 | call assert_equal(-2, id2) |
| 3357 | |
| 3358 | " removing the props resets the index |
| 3359 | call prop_remove(#{id: id1}) |
| 3360 | call prop_remove(#{id: id2}) |
| 3361 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 3362 | call assert_equal(-1, id1) |
| 3363 | |
| 3364 | call prop_type_delete('some') |
| 3365 | bwipe! |
| 3366 | endfunc |
| 3367 | |
Bram Moolenaar | 1f4ee19 | 2022-08-01 15:52:55 +0100 | [diff] [blame] | 3368 | def Test_insert_text_before_virtual_text() |
| 3369 | new foobar |
| 3370 | setline(1, '12345678') |
| 3371 | prop_type_add('test', {highlight: 'Search'}) |
| 3372 | prop_add(1, 5, { |
| 3373 | type: 'test', |
| 3374 | text: ' virtual text ' |
| 3375 | }) |
| 3376 | normal! f4axyz |
| 3377 | normal! f5iXYZ |
| 3378 | assert_equal('1234xyzXYZ5678', getline(1)) |
| 3379 | |
| 3380 | prop_type_delete('test') |
| 3381 | bwipe! |
| 3382 | enddef |
| 3383 | |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3384 | func Test_insert_text_start_incl() |
| 3385 | CheckRunVimInTerminal |
| 3386 | |
| 3387 | let lines =<< trim END |
| 3388 | vim9script |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 3389 | setline(1, ['text one text two', '', 'function(arg)']) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3390 | |
| 3391 | prop_type_add('propincl', {highlight: 'NonText', start_incl: true}) |
| 3392 | prop_add(1, 6, {type: 'propincl', text: 'after '}) |
| 3393 | cursor(1, 6) |
| 3394 | prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false}) |
| 3395 | prop_add(1, 15, {type: 'propnotincl', text: 'before '}) |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 3396 | |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3397 | set cindent sw=4 |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 3398 | prop_type_add('argname', {highlight: 'DiffChange', start_incl: true}) |
| 3399 | prop_add(3, 10, {type: 'argname', text: 'arg: '}) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3400 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3401 | call writefile(lines, 'XscriptPropsStartIncl', 'D') |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3402 | let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60}) |
| 3403 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {}) |
| 3404 | |
| 3405 | call term_sendkeys(buf, "i") |
| 3406 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {}) |
| 3407 | call term_sendkeys(buf, "xx\<Esc>") |
| 3408 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {}) |
| 3409 | |
| 3410 | call term_sendkeys(buf, "2wi") |
| 3411 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {}) |
| 3412 | call term_sendkeys(buf, "yy\<Esc>") |
| 3413 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {}) |
| 3414 | |
Bram Moolenaar | d8d4cfc | 2022-08-15 15:55:10 +0100 | [diff] [blame] | 3415 | call term_sendkeys(buf, "3Gfai\<CR>\<Esc>") |
| 3416 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_6', {}) |
| 3417 | call term_sendkeys(buf, ">>") |
| 3418 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_7', {}) |
| 3419 | call term_sendkeys(buf, "<<<<") |
| 3420 | call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_8', {}) |
| 3421 | |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3422 | call StopVimInTerminal(buf) |
Bram Moolenaar | 28c9f89 | 2022-08-14 13:28:55 +0100 | [diff] [blame] | 3423 | endfunc |
| 3424 | |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3425 | func Test_insert_text_list_mode() |
| 3426 | CheckRunVimInTerminal |
| 3427 | |
| 3428 | let lines =<< trim END |
| 3429 | vim9script |
| 3430 | setline(1, ['This is a line with quite a bit of text here.', |
| 3431 | 'second line', 'third line']) |
| 3432 | set list listchars+=extends:» |
| 3433 | prop_type_add('Prop1', {highlight: 'Error'}) |
| 3434 | prop_add(1, 0, { |
| 3435 | type: 'Prop1', |
| 3436 | text: 'The quick brown fox jumps over the lazy dog', |
| 3437 | text_align: 'right' |
| 3438 | }) |
| 3439 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3440 | call writefile(lines, 'XscriptPropsListMode', 'D') |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3441 | let buf = RunVimInTerminal('-S XscriptPropsListMode', #{rows: 8, cols: 60}) |
| 3442 | call term_sendkeys(buf, "ggj") |
| 3443 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_1', {}) |
| 3444 | |
| 3445 | call term_sendkeys(buf, ":set nowrap\<CR>") |
| 3446 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_2', {}) |
| 3447 | |
| 3448 | call term_sendkeys(buf, "ggd32l") |
| 3449 | call VerifyScreenDump(buf, 'Test_prop_insert_list_mode_3', {}) |
| 3450 | |
| 3451 | call StopVimInTerminal(buf) |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3452 | endfunc |
| 3453 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 3454 | func Test_insert_text_with_padding() |
| 3455 | CheckRunVimInTerminal |
| 3456 | |
| 3457 | let lines =<< trim END |
| 3458 | vim9script |
| 3459 | setline(1, ['Some text to add virtual text to.', |
| 3460 | 'second line', |
| 3461 | 'Another line with some text to make the wrap.']) |
| 3462 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 3463 | prop_add(1, 0, { |
| 3464 | type: 'theprop', |
| 3465 | text: 'after', |
| 3466 | text_align: 'after', |
| 3467 | text_padding_left: 3, |
| 3468 | }) |
| 3469 | prop_add(1, 0, { |
| 3470 | type: 'theprop', |
| 3471 | text: 'right aligned', |
| 3472 | text_align: 'right', |
| 3473 | text_padding_left: 5, |
| 3474 | }) |
| 3475 | prop_add(1, 0, { |
| 3476 | type: 'theprop', |
| 3477 | text: 'below the line', |
| 3478 | text_align: 'below', |
| 3479 | text_padding_left: 4, |
| 3480 | }) |
| 3481 | prop_add(3, 0, { |
| 3482 | type: 'theprop', |
| 3483 | text: 'rightmost', |
| 3484 | text_align: 'right', |
| 3485 | text_padding_left: 6, |
| 3486 | text_wrap: 'wrap', |
| 3487 | }) |
| 3488 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3489 | call writefile(lines, 'XscriptPropsPadded', 'D') |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 3490 | let buf = RunVimInTerminal('-S XscriptPropsPadded', #{rows: 8, cols: 60}) |
| 3491 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_1', {}) |
| 3492 | |
| 3493 | call term_sendkeys(buf, "ggixxxxxxxxxx\<Esc>") |
| 3494 | call term_sendkeys(buf, "3Gix\<Esc>") |
| 3495 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_2', {}) |
| 3496 | |
| 3497 | call term_sendkeys(buf, "ggix\<Esc>") |
| 3498 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_3', {}) |
| 3499 | |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 3500 | call term_sendkeys(buf, ":set list\<CR>") |
| 3501 | call VerifyScreenDump(buf, 'Test_prop_text_with_padding_4', {}) |
| 3502 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 3503 | call StopVimInTerminal(buf) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 3504 | endfunc |
| 3505 | |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 3506 | func Test_long_text_below_with_padding() |
| 3507 | CheckRunVimInTerminal |
| 3508 | |
| 3509 | let lines =<< trim END |
| 3510 | vim9script |
| 3511 | setline(1, ['first line', 'second line']) |
| 3512 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 3513 | prop_add(1, 0, { |
| 3514 | type: 'theprop', |
| 3515 | text: 'after '->repeat(20), |
| 3516 | text_align: 'below', |
| 3517 | text_padding_left: 3, |
| 3518 | }) |
| 3519 | prop_add(1, 0, { |
| 3520 | type: 'theprop', |
| 3521 | text: 'more '->repeat(20), |
| 3522 | text_align: 'below', |
| 3523 | text_padding_left: 30, |
| 3524 | }) |
| 3525 | normal 2Gw |
| 3526 | END |
| 3527 | call writefile(lines, 'XlongTextBelowWithPadding', 'D') |
| 3528 | let buf = RunVimInTerminal('-S XlongTextBelowWithPadding', #{rows: 8, cols: 60}) |
| 3529 | call VerifyScreenDump(buf, 'Test_long_text_with_padding_1', {}) |
| 3530 | |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 3531 | call term_sendkeys(buf, ":set list\<CR>") |
| 3532 | call VerifyScreenDump(buf, 'Test_long_text_with_padding_2', {}) |
| 3533 | |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 3534 | call StopVimInTerminal(buf) |
| 3535 | endfunc |
| 3536 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3537 | func Test_text_after_nowrap() |
| 3538 | CheckRunVimInTerminal |
| 3539 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3540 | let lines =<< trim END |
| 3541 | vim9script |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 3542 | setline(1, ['first line', range(80)->join(' '), 'third', 'fourth']) |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3543 | set nowrap |
| 3544 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 3545 | prop_add(1, 0, { |
| 3546 | type: 'theprop', |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 3547 | text: 'right after the text '->repeat(3), |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3548 | text_align: 'after', |
| 3549 | text_padding_left: 2, |
| 3550 | }) |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 3551 | prop_add(1, 0, { |
| 3552 | type: 'theprop', |
| 3553 | text: 'in the middle '->repeat(4), |
| 3554 | text_align: 'after', |
| 3555 | text_padding_left: 3, |
| 3556 | }) |
| 3557 | prop_add(1, 0, { |
| 3558 | type: 'theprop', |
| 3559 | text: 'the last one '->repeat(3), |
| 3560 | text_align: 'after', |
| 3561 | text_padding_left: 1, |
| 3562 | }) |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3563 | normal 2Gw |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 3564 | def g:ChangeText() |
| 3565 | prop_clear(1) |
| 3566 | set list |
| 3567 | prop_add(1, 0, { |
| 3568 | type: 'theprop', |
| 3569 | text: 'just after txt '->repeat(3), |
| 3570 | text_align: 'after', |
| 3571 | text_padding_left: 2, |
| 3572 | }) |
| 3573 | prop_add(1, 0, { |
| 3574 | type: 'theprop', |
| 3575 | text: 'in the middle '->repeat(4), |
| 3576 | text_align: 'after', |
| 3577 | text_padding_left: 1, |
| 3578 | }) |
| 3579 | enddef |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3580 | END |
| 3581 | call writefile(lines, 'XTextAfterNowrap', 'D') |
| 3582 | let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60}) |
| 3583 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {}) |
| 3584 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 3585 | call term_sendkeys(buf, "30w") |
| 3586 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {}) |
| 3587 | |
| 3588 | call term_sendkeys(buf, "22w") |
| 3589 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {}) |
| 3590 | |
| 3591 | call term_sendkeys(buf, "$") |
| 3592 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {}) |
| 3593 | |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 3594 | call term_sendkeys(buf, "0") |
| 3595 | call term_sendkeys(buf, ":call ChangeText()\<CR>") |
| 3596 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_5', {}) |
| 3597 | |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 3598 | call StopVimInTerminal(buf) |
| 3599 | endfunc |
| 3600 | |
Bram Moolenaar | 02edfaa | 2022-11-18 23:13:47 +0000 | [diff] [blame] | 3601 | func Test_text_after_nowrap_list() |
| 3602 | CheckRunVimInTerminal |
| 3603 | |
| 3604 | let lines =<< trim END |
| 3605 | vim9script |
| 3606 | |
| 3607 | set nowrap |
| 3608 | set listchars+=extends:> |
| 3609 | set list |
| 3610 | setline(1, ['some text here', '', 'last line']) |
| 3611 | |
| 3612 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3613 | prop_add(1, 0, { |
| 3614 | type: 'test', |
| 3615 | text: 'The quick brown fox jumps.', |
| 3616 | text_padding_left: 2, |
| 3617 | }) |
| 3618 | prop_add(1, 0, { |
| 3619 | type: 'test', |
| 3620 | text: 'â– The fox jumps over the lazy dog.', |
| 3621 | text_padding_left: 2, |
| 3622 | }) |
| 3623 | prop_add(1, 0, { |
| 3624 | type: 'test', |
| 3625 | text: 'â– The lazy dog.', |
| 3626 | text_padding_left: 2, |
| 3627 | }) |
| 3628 | normal 3G$ |
| 3629 | END |
| 3630 | call writefile(lines, 'XTextAfterNowrapList', 'D') |
| 3631 | let buf = RunVimInTerminal('-S XTextAfterNowrapList', #{rows: 6, cols: 60}) |
| 3632 | call VerifyScreenDump(buf, 'Test_text_after_nowrap_list_1', {}) |
| 3633 | |
| 3634 | call StopVimInTerminal(buf) |
| 3635 | endfunc |
| 3636 | |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 3637 | func Test_text_below_nowrap() |
| 3638 | CheckRunVimInTerminal |
| 3639 | |
| 3640 | let lines =<< trim END |
| 3641 | vim9script |
| 3642 | setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth']) |
| 3643 | set nowrap number |
| 3644 | prop_type_add('theprop', {highlight: 'DiffChange'}) |
| 3645 | prop_add(1, 0, { |
| 3646 | type: 'theprop', |
| 3647 | text: 'one below the text '->repeat(5), |
| 3648 | text_align: 'below', |
| 3649 | text_padding_left: 2, |
| 3650 | }) |
| 3651 | prop_add(1, 0, { |
| 3652 | type: 'theprop', |
| 3653 | text: 'two below the text '->repeat(5), |
| 3654 | text_align: 'below', |
| 3655 | text_padding_left: 2, |
| 3656 | }) |
| 3657 | normal 2Gw |
| 3658 | END |
| 3659 | call writefile(lines, 'XTextBelowNowrap', 'D') |
| 3660 | let buf = RunVimInTerminal('-S XTextBelowNowrap', #{rows: 8, cols: 60}) |
| 3661 | call VerifyScreenDump(buf, 'Test_text_below_nowrap_1', {}) |
| 3662 | |
| 3663 | call StopVimInTerminal(buf) |
| 3664 | endfunc |
| 3665 | |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 3666 | func Test_virtual_text_in_popup_highlight() |
| 3667 | CheckRunVimInTerminal |
| 3668 | |
| 3669 | let lines =<< trim END |
| 3670 | vim9script |
| 3671 | |
| 3672 | # foreground highlight only, popup background is used |
| 3673 | prop_type_add('Prop1', {'highlight': 'SpecialKey'}) |
| 3674 | # foreground and background highlight, popup background is not used |
| 3675 | prop_type_add('Prop2', {'highlight': 'DiffDelete'}) |
| 3676 | |
| 3677 | var popupText = [{ |
| 3678 | text: 'Some text', |
| 3679 | props: [ |
| 3680 | { |
| 3681 | col: 1, |
| 3682 | type: 'Prop1', |
| 3683 | text: ' + ' |
| 3684 | }, |
| 3685 | { |
| 3686 | col: 6, |
| 3687 | type: 'Prop2', |
| 3688 | text: ' x ' |
| 3689 | }, |
| 3690 | ] |
| 3691 | }] |
| 3692 | var popupArgs = { |
| 3693 | line: 3, |
| 3694 | col: 20, |
| 3695 | maxwidth: 80, |
| 3696 | highlight: 'PMenu', |
| 3697 | border: [], |
| 3698 | borderchars: [' '], |
| 3699 | } |
| 3700 | |
| 3701 | popup_create(popupText, popupArgs) |
| 3702 | END |
| 3703 | call writefile(lines, 'XscriptVirtualHighlight', 'D') |
| 3704 | let buf = RunVimInTerminal('-S XscriptVirtualHighlight', #{rows: 8}) |
| 3705 | call VerifyScreenDump(buf, 'Test_virtual_text_in_popup_highlight_1', {}) |
| 3706 | |
| 3707 | call StopVimInTerminal(buf) |
| 3708 | endfunc |
| 3709 | |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 3710 | func Test_insert_text_change_arg() |
| 3711 | CheckRunVimInTerminal |
| 3712 | |
| 3713 | let lines =<< trim END |
| 3714 | vim9script |
| 3715 | setline(1, ['SetErrorCode( 10, 20 )', 'second line']) |
| 3716 | prop_type_add('param', {highlight: 'DiffChange', start_incl: 1}) |
| 3717 | prop_type_add('padd', {highlight: 'NonText', start_incl: 1}) |
| 3718 | prop_add(1, 15, { |
| 3719 | type: 'param', |
| 3720 | text: 'id:', |
| 3721 | }) |
| 3722 | prop_add(1, 15, { |
| 3723 | type: 'padd', |
| 3724 | text: '-', |
| 3725 | }) |
| 3726 | prop_add(1, 19, { |
| 3727 | type: 'param', |
| 3728 | text: 'id:', |
| 3729 | }) |
| 3730 | prop_add(1, 19, { |
| 3731 | type: 'padd', |
| 3732 | text: '-', |
| 3733 | }) |
| 3734 | END |
Bram Moolenaar | 2fdc9b5 | 2022-09-20 15:59:22 +0100 | [diff] [blame] | 3735 | call writefile(lines, 'XscriptPropsChange', 'D') |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 3736 | let buf = RunVimInTerminal('-S XscriptPropsChange', #{rows: 5, cols: 60}) |
| 3737 | call VerifyScreenDump(buf, 'Test_prop_text_change_arg_1', {}) |
| 3738 | |
| 3739 | call term_sendkeys(buf, "ggf1cw1234\<Esc>") |
| 3740 | call VerifyScreenDump(buf, 'Test_prop_text_change_arg_2', {}) |
| 3741 | |
| 3742 | call StopVimInTerminal(buf) |
Bram Moolenaar | f5240b9 | 2022-08-24 12:24:37 +0100 | [diff] [blame] | 3743 | endfunc |
| 3744 | |
Bram Moolenaar | 2f7bfe6 | 2022-11-13 12:54:50 +0000 | [diff] [blame] | 3745 | def Test_textprop_in_quickfix_window() |
| 3746 | enew! |
| 3747 | var prop_type = 'my_prop' |
| 3748 | prop_type_add(prop_type, {}) |
| 3749 | |
| 3750 | for lnum in range(1, 10) |
| 3751 | setline(lnum, 'hello world') |
| 3752 | endfor |
| 3753 | |
| 3754 | cgetbuffer |
| 3755 | copen |
| 3756 | |
| 3757 | var bufnr = bufnr() |
| 3758 | for lnum in range(1, line('$', bufnr->bufwinid())) |
| 3759 | prop_add(lnum, 1, { |
| 3760 | id: 1000 + lnum, |
| 3761 | type: prop_type, |
| 3762 | bufnr: bufnr, |
| 3763 | }) |
| 3764 | endfor |
| 3765 | |
| 3766 | prop_type_delete(prop_type) |
| 3767 | cclose |
| 3768 | bwipe! |
| 3769 | enddef |
| 3770 | |
Bram Moolenaar | 89469d1 | 2022-12-02 20:46:26 +0000 | [diff] [blame] | 3771 | func Test_text_prop_delete_updates() |
| 3772 | CheckRunVimInTerminal |
| 3773 | |
| 3774 | let lines =<< trim END |
| 3775 | vim9script |
| 3776 | |
| 3777 | setline(1, ['some text', 'more text', 'the end']) |
| 3778 | prop_type_add('test', {highlight: 'DiffChange'}) |
| 3779 | prop_add(1, 0, { |
| 3780 | type: 'test', |
| 3781 | text: 'The quick brown fox jumps over the lazy dog', |
| 3782 | text_align: 'below', |
| 3783 | text_padding_left: 3, |
| 3784 | }) |
| 3785 | prop_add(1, 0, { |
| 3786 | type: 'test', |
| 3787 | text: 'The quick brown fox jumps over the lazy dog', |
| 3788 | text_align: 'below', |
| 3789 | text_padding_left: 5, |
| 3790 | }) |
| 3791 | |
| 3792 | normal! G |
| 3793 | END |
| 3794 | call writefile(lines, 'XtextPropDelete', 'D') |
| 3795 | let buf = RunVimInTerminal('-S XtextPropDelete', #{rows: 10, cols: 60}) |
| 3796 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_1', {}) |
| 3797 | |
| 3798 | " Check that after deleting the text prop type the text properties using |
| 3799 | " this type no longer show and are not counted for cursor positioning. |
| 3800 | call term_sendkeys(buf, ":call prop_type_delete('test')\<CR>") |
| 3801 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_2', {}) |
| 3802 | |
| 3803 | call term_sendkeys(buf, "ggj") |
| 3804 | call VerifyScreenDump(buf, 'Test_prop_delete_updates_3', {}) |
| 3805 | |
| 3806 | call StopVimInTerminal(buf) |
| 3807 | endfunc |
| 3808 | |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 3809 | func Test_text_prop_diff_mode() |
| 3810 | CheckRunVimInTerminal |
| 3811 | |
| 3812 | let lines =<< trim END |
| 3813 | call setline(1, ['9000', '0009', '0009', '9000', '0009']) |
| 3814 | |
| 3815 | let type = 'test' |
| 3816 | call prop_type_add(type, {}) |
| 3817 | let text = '<text>' |
| 3818 | call prop_add(1, 1, {'type': type, 'text': text}) |
| 3819 | call prop_add(2, 0, {'type': type, 'text': text, 'text_align': 'after'}) |
| 3820 | call prop_add(3, 0, {'type': type, 'text': text, 'text_align': 'right'}) |
| 3821 | call prop_add(4, 0, {'type': type, 'text': text, 'text_align': 'above'}) |
| 3822 | call prop_add(5, 0, {'type': type, 'text': text, 'text_align': 'below'}) |
| 3823 | set diff |
| 3824 | |
| 3825 | vnew |
| 3826 | call setline(1, ['000', '000', '000', '000', '000']) |
| 3827 | set diff |
| 3828 | END |
| 3829 | call writefile(lines, 'XtextPropDiff', 'D') |
| 3830 | let buf = RunVimInTerminal('-S XtextPropDiff', #{rows: 10, cols: 60}) |
| 3831 | call VerifyScreenDump(buf, 'Test_prop_diff_mode_1', {}) |
| 3832 | |
| 3833 | call term_sendkeys(buf, ":windo set number\<CR>") |
| 3834 | call VerifyScreenDump(buf, 'Test_prop_diff_mode_2', {}) |
| 3835 | |
| 3836 | call StopVimInTerminal(buf) |
| 3837 | endfunc |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 3838 | |
Bram Moolenaar | 4ce1f99 | 2022-12-19 13:31:06 +0000 | [diff] [blame] | 3839 | func Test_error_when_using_negative_id() |
| 3840 | call prop_type_add('test1', #{highlight: 'ErrorMsg'}) |
| 3841 | call prop_add(1, 1, #{type: 'test1', text: 'virtual'}) |
| 3842 | call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:') |
| 3843 | |
| 3844 | call prop_type_delete('test1') |
| 3845 | endfunc |
| 3846 | |
| 3847 | func Test_error_after_using_negative_id() |
| 3848 | " This needs to run a separate Vim instance because the |
| 3849 | " "did_use_negative_pop_id" will be set. |
| 3850 | CheckRunVimInTerminal |
| 3851 | |
| 3852 | let lines =<< trim END |
| 3853 | vim9script |
| 3854 | |
| 3855 | setline(1, ['one', 'two', 'three']) |
| 3856 | prop_type_add('test_1', {highlight: 'Error'}) |
| 3857 | prop_type_add('test_2', {highlight: 'WildMenu'}) |
| 3858 | |
| 3859 | prop_add(3, 1, { |
| 3860 | type: 'test_1', |
| 3861 | length: 5, |
| 3862 | id: -1 |
| 3863 | }) |
| 3864 | |
| 3865 | def g:AddTextprop() |
| 3866 | prop_add(1, 0, { |
| 3867 | type: 'test_2', |
| 3868 | text: 'The quick fox', |
| 3869 | text_padding_left: 2 |
| 3870 | }) |
| 3871 | enddef |
| 3872 | END |
| 3873 | call writefile(lines, 'XtextPropError', 'D') |
| 3874 | let buf = RunVimInTerminal('-S XtextPropError', #{rows: 8, cols: 60}) |
| 3875 | call VerifyScreenDump(buf, 'Test_prop_negative_error_1', {}) |
| 3876 | |
| 3877 | call term_sendkeys(buf, ":call AddTextprop()\<CR>") |
| 3878 | call VerifyScreenDump(buf, 'Test_prop_negative_error_2', {}) |
| 3879 | |
| 3880 | call StopVimInTerminal(buf) |
| 3881 | endfunc |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 3882 | |
Bram Moolenaar | 2f7bfe6 | 2022-11-13 12:54:50 +0000 | [diff] [blame] | 3883 | |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 3884 | " vim: shiftwidth=2 sts=2 expandtab |