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