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