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 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 74 | def Test_proptype_buf_list() |
| 75 | new |
| 76 | var bufnr = bufnr('') |
| 77 | try |
| 78 | prop_type_add('global', {}) |
| 79 | prop_type_add('local', {bufnr: bufnr}) |
| 80 | |
| 81 | prop_add(1, 1, {type: 'global'}) |
| 82 | prop_add(1, 1, {type: 'local'}) |
| 83 | |
| 84 | assert_equal([ |
| 85 | {type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1}, |
| 86 | {type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1}, |
| 87 | ], prop_list(1)) |
| 88 | assert_equal( |
| 89 | {lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1}, |
| 90 | prop_find({lnum: 1, type: 'local'})) |
| 91 | assert_equal( |
| 92 | {lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1}, |
| 93 | prop_find({lnum: 1, type: 'global'})) |
| 94 | |
| 95 | prop_remove({type: 'global'}, 1) |
| 96 | prop_remove({type: 'local'}, 1) |
| 97 | finally |
| 98 | prop_type_delete('global') |
| 99 | prop_type_delete('local', {bufnr: bufnr}) |
| 100 | bwipe! |
| 101 | endtry |
| 102 | enddef |
| 103 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 104 | func AddPropTypes() |
| 105 | call prop_type_add('one', {}) |
| 106 | call prop_type_add('two', {}) |
| 107 | call prop_type_add('three', {}) |
| 108 | call prop_type_add('whole', {}) |
| 109 | endfunc |
| 110 | |
| 111 | func DeletePropTypes() |
| 112 | call prop_type_delete('one') |
| 113 | call prop_type_delete('two') |
| 114 | call prop_type_delete('three') |
| 115 | call prop_type_delete('whole') |
| 116 | endfunc |
| 117 | |
| 118 | func SetupPropsInFirstLine() |
| 119 | call setline(1, 'one two three') |
| 120 | call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 121 | eval 1->prop_add(5, {'length': 3, 'id': 12, 'type': 'two'}) |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 122 | call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 123 | call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) |
| 124 | endfunc |
| 125 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 126 | func Get_expected_props() |
| 127 | return [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 128 | \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1}, |
| 129 | \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 130 | \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
| 131 | \ #{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] | 132 | \ ] |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 133 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 134 | |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 135 | func Test_prop_find() |
| 136 | new |
| 137 | call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 138 | |
| 139 | " 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] | 140 | call prop_type_add('prop_name', {'highlight': 'Directory'}) |
| 141 | call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) |
| 142 | call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) |
| 143 | call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) |
| 144 | |
| 145 | let expected = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 146 | \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1}, |
| 147 | \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0}, |
| 148 | \ #{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] | 149 | \ ] |
| 150 | |
| 151 | " Starting at line 5 col 1 this should find the prop at line 5 col 4. |
| 152 | call cursor(5,1) |
| 153 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 154 | call assert_equal(expected[2], result) |
| 155 | |
| 156 | " With skipstart left at false (default), this should find the prop at line |
| 157 | " 5 col 4. |
| 158 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4}, 'b') |
| 159 | call assert_equal(expected[2], result) |
| 160 | |
| 161 | " With skipstart set to true, this should skip the prop at line 5 col 4. |
| 162 | let result = prop_find({'type': 'prop_name', 'lnum': 5, 'col': 4, 'skipstart': 1}, 'b') |
| 163 | unlet result.length |
| 164 | call assert_equal(expected[1], result) |
| 165 | |
| 166 | " Search backwards from line 1 col 10 to find the prop on the same line. |
| 167 | let result = prop_find({'type': 'prop_name', 'lnum': 1, 'col': 10}, 'b') |
| 168 | call assert_equal(expected[0], result) |
| 169 | |
| 170 | " with skipstart set to false, if the start position is anywhere between the |
| 171 | " start and end lines of a text prop (searching forward or backward), the |
| 172 | " result should be the prop on the first line (the line with 'start' set to 1). |
| 173 | call cursor(3,1) |
| 174 | let result = prop_find({'type': 'prop_name'}, 'f') |
| 175 | unlet result.length |
| 176 | call assert_equal(expected[1], result) |
| 177 | let result = prop_find({'type': 'prop_name'}, 'b') |
| 178 | unlet result.length |
| 179 | call assert_equal(expected[1], result) |
| 180 | |
| 181 | " with skipstart set to true, if the start position is anywhere between the |
| 182 | " start and end lines of a text prop (searching forward or backward), all lines |
| 183 | " of the prop will be skipped. |
| 184 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'b') |
| 185 | call assert_equal(expected[0], result) |
| 186 | let result = prop_find({'type': 'prop_name', 'skipstart': 1}, 'f') |
| 187 | call assert_equal(expected[2], result) |
| 188 | |
| 189 | " Use skipstart to search through all props with type name 'prop_name'. |
| 190 | " First forward... |
| 191 | let lnum = 1 |
| 192 | let col = 1 |
| 193 | let i = 0 |
| 194 | for exp in expected |
| 195 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'f') |
| 196 | if !has_key(exp, "length") |
| 197 | unlet result.length |
| 198 | endif |
| 199 | call assert_equal(exp, result) |
| 200 | let lnum = result.lnum |
| 201 | let col = result.col |
| 202 | let i = i + 1 |
| 203 | endfor |
| 204 | |
| 205 | " ...then backwards. |
| 206 | let lnum = 6 |
| 207 | let col = 4 |
| 208 | let i = 2 |
| 209 | while i >= 0 |
| 210 | let result = prop_find({'type': 'prop_name', 'lnum': lnum, 'col': col, 'skipstart': 1}, 'b') |
| 211 | if !has_key(expected[i], "length") |
| 212 | unlet result.length |
| 213 | endif |
| 214 | call assert_equal(expected[i], result) |
| 215 | let lnum = result.lnum |
| 216 | let col = result.col |
| 217 | let i = i - 1 |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 218 | endwhile |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 219 | |
| 220 | " Starting from line 6 col 1 search backwards for prop with id 10. |
| 221 | call cursor(6,1) |
| 222 | let result = prop_find({'id': 10, 'skipstart': 1}, 'b') |
| 223 | call assert_equal(expected[0], result) |
| 224 | |
| 225 | " Starting from line 1 col 1 search forwards for prop with id 12. |
| 226 | call cursor(1,1) |
| 227 | let result = prop_find({'id': 12}, 'f') |
| 228 | call assert_equal(expected[2], result) |
| 229 | |
| 230 | " Search for a prop with an unknown id. |
| 231 | let result = prop_find({'id': 999}, 'f') |
| 232 | call assert_equal({}, result) |
| 233 | |
| 234 | " Search backwards from the proceeding position of the prop with id 11 |
| 235 | " (at line num 2 col 4). This should return an empty dict. |
| 236 | let result = prop_find({'id': 11, 'lnum': 2, 'col': 3}, 'b') |
| 237 | call assert_equal({}, result) |
| 238 | |
| 239 | " When lnum is given and col is omitted, use column 1. |
| 240 | let result = prop_find({'type': 'prop_name', 'lnum': 1}, 'f') |
| 241 | call assert_equal(expected[0], result) |
| 242 | |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 243 | " Negative ID is possible, just like prop is not found. |
Bram Moolenaar | 8e3fc13 | 2021-07-31 18:33:57 +0200 | [diff] [blame] | 244 | call assert_equal({}, prop_find({'id': -1})) |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 245 | call assert_equal({}, prop_find({'id': -2})) |
Bram Moolenaar | 8e3fc13 | 2021-07-31 18:33:57 +0200 | [diff] [blame] | 246 | |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 247 | call prop_clear(1, 6) |
| 248 | |
| 249 | " Default ID is zero |
| 250 | call prop_add(5, 4, {'type': 'prop_name', 'length': 1}) |
| 251 | 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})) |
| 252 | |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 253 | call prop_type_delete('prop_name') |
Bram Moolenaar | e041dde | 2021-08-01 21:30:12 +0200 | [diff] [blame] | 254 | call prop_clear(1, 6) |
Bram Moolenaar | 4da7a25 | 2020-09-02 19:59:00 +0200 | [diff] [blame] | 255 | bwipe! |
Bram Moolenaar | e05a89a | 2020-01-10 19:56:46 +0100 | [diff] [blame] | 256 | endfunc |
| 257 | |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 258 | def Test_prop_find2() |
| 259 | # Multiple props per line, start on the first, should find the second. |
| 260 | new |
| 261 | ['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] | 262 | prop_type_add('misspell', {highlight: 'ErrorMsg'}) |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 263 | for lnum in [1, 2] |
| 264 | for col in [8, 14, 24, 38] |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 265 | prop_add(lnum, col, {type: 'misspell', length: 2}) |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 266 | endfor |
| 267 | endfor |
| 268 | cursor(1, 8) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 269 | 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] | 270 | var result = prop_find({type: 'misspell', skipstart: true}, 'f') |
Bram Moolenaar | eb24556 | 2020-09-03 22:33:44 +0200 | [diff] [blame] | 271 | assert_equal(expected, result) |
| 272 | |
| 273 | prop_type_delete('misspell') |
| 274 | bwipe! |
| 275 | enddef |
| 276 | |
Bram Moolenaar | 346f18e | 2020-03-13 21:36:40 +0100 | [diff] [blame] | 277 | func Test_prop_find_smaller_len_than_match_col() |
| 278 | new |
| 279 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 280 | call setline(1, ['xxxx', 'x']) |
| 281 | call prop_add(1, 4, {'type': 'test'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 282 | call assert_equal( |
| 283 | \ #{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] | 284 | \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b')) |
| 285 | bwipe! |
| 286 | call prop_type_delete('test') |
| 287 | endfunc |
| 288 | |
Bram Moolenaar | 24f21fd | 2021-03-27 22:07:29 +0100 | [diff] [blame] | 289 | func Test_prop_find_with_both_option_enabled() |
| 290 | " Initialize |
| 291 | new |
| 292 | call AddPropTypes() |
| 293 | call SetupPropsInFirstLine() |
| 294 | let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})}) |
| 295 | " Test |
| 296 | call assert_fails("call prop_find({'both': 1})", 'E968:') |
| 297 | call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:') |
| 298 | call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:') |
| 299 | call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1})) |
| 300 | call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1})) |
| 301 | call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1})) |
| 302 | call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1})) |
| 303 | " Clean up |
| 304 | call DeletePropTypes() |
| 305 | bwipe! |
| 306 | endfunc |
| 307 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 308 | func Test_prop_add() |
| 309 | new |
| 310 | call AddPropTypes() |
| 311 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 312 | let expected_props = Get_expected_props() |
| 313 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 314 | call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') |
| 315 | 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] | 316 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 317 | " Insert a line above, text props must still be there. |
| 318 | call append(0, 'empty') |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 319 | call assert_equal(expected_props, prop_list(2)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 320 | " Delete a line above, text props must still be there. |
| 321 | 1del |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 322 | call assert_equal(expected_props, prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 323 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 324 | " Prop without length or end column is zero length |
| 325 | call prop_clear(1) |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 326 | call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) |
| 327 | call prop_add(1, 5, #{type: 'included'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 328 | 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] | 329 | call assert_equal(expected, prop_list(1)) |
| 330 | |
| 331 | " Inserting text makes the prop bigger. |
| 332 | exe "normal 5|ixx\<Esc>" |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 333 | 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] | 334 | call assert_equal(expected, prop_list(1)) |
| 335 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 336 | call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') |
| 337 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 338 | call DeletePropTypes() |
Bram Moolenaar | 12f2003 | 2020-02-26 22:06:00 +0100 | [diff] [blame] | 339 | call prop_type_delete('included') |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 340 | bwipe! |
| 341 | endfunc |
| 342 | |
Yegappan Lakshmanan | ccfb7c6 | 2021-08-16 21:39:09 +0200 | [diff] [blame] | 343 | " Test for the prop_add_list() function |
| 344 | func Test_prop_add_list() |
| 345 | new |
| 346 | call AddPropTypes() |
| 347 | call setline(1, ['one one one', 'two two two', 'six six six', 'ten ten ten']) |
| 348 | call prop_add_list(#{type: 'one', id: 2}, |
| 349 | \ [[1, 1, 1, 3], [2, 5, 2, 7], [3, 6, 4, 6]]) |
| 350 | call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one', |
| 351 | \ length: 2, start: 1}], prop_list(1)) |
| 352 | call assert_equal([#{id: 2, col: 5, type_bufnr: 0, end: 1, type: 'one', |
| 353 | \ length: 2, start: 1}], prop_list(2)) |
| 354 | call assert_equal([#{id: 2, col: 6, type_bufnr: 0, end: 0, type: 'one', |
| 355 | \ length: 7, start: 1}], prop_list(3)) |
| 356 | call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one', |
| 357 | \ length: 5, start: 0}], prop_list(4)) |
| 358 | call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:') |
| 359 | call assert_fails('call prop_add_list({}, {})', 'E1211:') |
| 360 | call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:') |
| 361 | call assert_fails('call prop_add_list(#{type: "abc"}, [[1, 1, 1, 3]])', 'E971:') |
| 362 | call assert_fails('call prop_add_list(#{type: "one"}, [[]])', 'E474:') |
| 363 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 1], {}])', 'E714:') |
| 364 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, "a"]])', 'E474:') |
| 365 | call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2]])', 'E474:') |
| 366 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 2], [2, 2]])', 'E474:') |
| 367 | call assert_fails('call prop_add_list(#{type: "one"}, [[1, 1, 1, 2], [4, 1, 5, 2]])', 'E966:') |
| 368 | call assert_fails('call prop_add_list(#{type: "one"}, [[3, 1, 1, 2]])', 'E966:') |
| 369 | call assert_fails('call prop_add_list(#{type: "one"}, [[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') |
| 370 | call assert_fails('eval #{type: "one"}->prop_add_list([[2, 2, 2, 2], [3, 20, 3, 22]])', 'E964:') |
| 371 | call assert_fails('call prop_add_list(test_null_dict(), [[2, 2, 2]])', 'E965:') |
| 372 | call assert_fails('call prop_add_list(#{type: "one"}, test_null_list())', 'E714:') |
| 373 | call assert_fails('call prop_add_list(#{type: "one"}, [test_null_list()])', 'E714:') |
| 374 | call DeletePropTypes() |
| 375 | bw! |
| 376 | endfunc |
| 377 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 378 | func Test_prop_remove() |
| 379 | new |
| 380 | call AddPropTypes() |
| 381 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 382 | let props = Get_expected_props() |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 383 | call assert_equal(props, prop_list(1)) |
| 384 | |
| 385 | " remove by id |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 386 | call assert_equal(1, {'id': 12}->prop_remove(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 387 | unlet props[2] |
| 388 | call assert_equal(props, prop_list(1)) |
| 389 | |
| 390 | " remove by type |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 391 | call assert_equal(1, prop_remove({'type': 'one'}, 1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 392 | unlet props[1] |
| 393 | call assert_equal(props, prop_list(1)) |
| 394 | |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 395 | " remove from unknown buffer |
| 396 | call assert_fails("call prop_remove({'type': 'one', 'bufnr': 123456}, 1)", 'E158:') |
| 397 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 398 | call DeletePropTypes() |
| 399 | bwipe! |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 400 | |
| 401 | new |
| 402 | call AddPropTypes() |
| 403 | call SetupPropsInFirstLine() |
| 404 | call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) |
| 405 | let props = Get_expected_props() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 406 | 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] | 407 | call assert_equal(props, prop_list(1)) |
| 408 | call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) |
| 409 | unlet props[3] |
| 410 | call assert_equal(props, prop_list(1)) |
| 411 | |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 412 | call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860:') |
| 413 | call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860:') |
Bram Moolenaar | 49b79bd | 2020-03-05 21:52:55 +0100 | [diff] [blame] | 414 | |
| 415 | call DeletePropTypes() |
| 416 | bwipe! |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 417 | endfunc |
| 418 | |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 419 | def Test_prop_add_vim9() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 420 | prop_type_add('comment', { |
Bram Moolenaar | fa2e38d | 2020-09-05 21:00:00 +0200 | [diff] [blame] | 421 | highlight: 'Directory', |
| 422 | priority: 123, |
| 423 | start_incl: true, |
| 424 | end_incl: true, |
| 425 | combine: false, |
| 426 | }) |
| 427 | prop_type_delete('comment') |
| 428 | enddef |
| 429 | |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 430 | def Test_prop_remove_vim9() |
| 431 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 432 | g:AddPropTypes() |
| 433 | g:SetupPropsInFirstLine() |
Bram Moolenaar | e0de171 | 2020-12-02 17:36:54 +0100 | [diff] [blame] | 434 | 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] | 435 | g:DeletePropTypes() |
Bram Moolenaar | a5a40c5 | 2020-09-05 20:50:49 +0200 | [diff] [blame] | 436 | bwipe! |
| 437 | enddef |
| 438 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 439 | func SetupOneLine() |
| 440 | call setline(1, 'xonex xtwoxx') |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 441 | normal gg0 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 442 | call AddPropTypes() |
| 443 | call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) |
| 444 | call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) |
| 445 | let expected = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 446 | \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 447 | \ #{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] | 448 | \] |
| 449 | call assert_equal(expected, prop_list(1)) |
| 450 | return expected |
| 451 | endfunc |
| 452 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 453 | func Test_prop_add_remove_buf() |
| 454 | new |
| 455 | let bufnr = bufnr('') |
| 456 | call AddPropTypes() |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 457 | for lnum in range(1, 4) |
| 458 | call setline(lnum, 'one two three') |
| 459 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 460 | wincmd w |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 461 | for lnum in range(1, 4) |
| 462 | call prop_add(lnum, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) |
| 463 | call prop_add(lnum, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) |
| 464 | call prop_add(lnum, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) |
| 465 | endfor |
| 466 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 467 | let props = [ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 468 | \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, |
| 469 | \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, |
| 470 | \ #{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] | 471 | \] |
| 472 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 473 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 474 | " remove by id |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 475 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 476 | unlet props[1] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 477 | |
| 478 | call prop_remove({'id': 12, 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 479 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 480 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 481 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 482 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 483 | |
| 484 | call prop_remove({'id': 12, 'bufnr': bufnr}, 3, 4) |
| 485 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 486 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 487 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 488 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 489 | |
| 490 | call prop_remove({'id': 12, 'bufnr': bufnr}) |
| 491 | for lnum in range(1, 4) |
| 492 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 493 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 494 | |
| 495 | " remove by type |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 496 | let before_props = deepcopy(props) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 497 | unlet props[0] |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 498 | |
| 499 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 500 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 0a2f578 | 2019-03-22 13:20:43 +0100 | [diff] [blame] | 501 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 502 | call assert_equal(before_props, prop_list(3, {'bufnr': bufnr})) |
| 503 | call assert_equal(before_props, prop_list(4, {'bufnr': bufnr})) |
| 504 | |
| 505 | call prop_remove({'type': 'one', 'bufnr': bufnr}, 3, 4) |
| 506 | call assert_equal(props, prop_list(1, {'bufnr': bufnr})) |
| 507 | call assert_equal(before_props, prop_list(2, {'bufnr': bufnr})) |
| 508 | call assert_equal(props, prop_list(3, {'bufnr': bufnr})) |
| 509 | call assert_equal(props, prop_list(4, {'bufnr': bufnr})) |
| 510 | |
| 511 | call prop_remove({'type': 'one', 'bufnr': bufnr}) |
| 512 | for lnum in range(1, 4) |
| 513 | call assert_equal(props, prop_list(lnum, {'bufnr': bufnr})) |
| 514 | endfor |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 515 | |
| 516 | call DeletePropTypes() |
| 517 | wincmd w |
| 518 | bwipe! |
| 519 | endfunc |
| 520 | |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 521 | func Test_prop_backspace() |
| 522 | new |
| 523 | set bs=2 |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 524 | let expected = SetupOneLine() " 'xonex xtwoxx' |
Bram Moolenaar | 33c8ca9 | 2019-01-02 18:00:27 +0100 | [diff] [blame] | 525 | |
| 526 | exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" |
| 527 | call assert_equal('one xtwoxx', getline(1)) |
| 528 | let expected[0].col = 1 |
| 529 | let expected[1].col = 6 |
| 530 | call assert_equal(expected, prop_list(1)) |
| 531 | |
| 532 | call DeletePropTypes() |
| 533 | bwipe! |
| 534 | set bs& |
| 535 | endfunc |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 536 | |
LemonBoy | d0b1a09 | 2022-05-12 18:45:18 +0100 | [diff] [blame] | 537 | func Test_prop_change() |
| 538 | new |
| 539 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 540 | |
| 541 | " Characterwise. |
| 542 | exe "normal 7|c$\<Esc>" |
| 543 | call assert_equal('xonex ', getline(1)) |
| 544 | call assert_equal(expected[:0], prop_list(1)) |
| 545 | " Linewise. |
| 546 | exe "normal cc\<Esc>" |
| 547 | call assert_equal('', getline(1)) |
| 548 | call assert_equal([], prop_list(1)) |
| 549 | |
| 550 | call DeletePropTypes() |
| 551 | bwipe! |
| 552 | set bs& |
| 553 | endfunc |
| 554 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 555 | func Test_prop_replace() |
| 556 | new |
| 557 | set bs=2 |
| 558 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 559 | |
| 560 | exe "normal 0Ryyy\<Esc>" |
| 561 | call assert_equal('yyyex xtwoxx', getline(1)) |
| 562 | call assert_equal(expected, prop_list(1)) |
| 563 | |
| 564 | exe "normal ftRyy\<BS>" |
| 565 | call assert_equal('yyyex xywoxx', getline(1)) |
| 566 | call assert_equal(expected, prop_list(1)) |
| 567 | |
| 568 | exe "normal 0fwRyy\<BS>" |
| 569 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 570 | call assert_equal(expected, prop_list(1)) |
| 571 | |
| 572 | exe "normal 0foRyy\<BS>\<BS>" |
| 573 | call assert_equal('yyyex xyyoxx', getline(1)) |
| 574 | call assert_equal(expected, prop_list(1)) |
| 575 | |
LemonBoy | 0d534d9 | 2022-05-21 11:20:42 +0100 | [diff] [blame] | 576 | " Replace three 1-byte chars with three 2-byte ones. |
| 577 | exe "normal 0l3rø" |
| 578 | call assert_equal('yøøøx xyyoxx', getline(1)) |
| 579 | let expected[0].length += 3 |
| 580 | let expected[1].col += 3 |
| 581 | call assert_equal(expected, prop_list(1)) |
| 582 | |
Bram Moolenaar | 196d157 | 2019-01-02 23:47:18 +0100 | [diff] [blame] | 583 | call DeletePropTypes() |
| 584 | bwipe! |
| 585 | set bs& |
| 586 | endfunc |
| 587 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 588 | func Test_prop_open_line() |
| 589 | new |
| 590 | |
| 591 | " open new line, props stay in top line |
| 592 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 593 | exe "normal o\<Esc>" |
| 594 | call assert_equal('xonex xtwoxx', getline(1)) |
| 595 | call assert_equal('', getline(2)) |
| 596 | call assert_equal(expected, prop_list(1)) |
| 597 | call DeletePropTypes() |
| 598 | |
| 599 | " move all props to next line |
| 600 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 601 | exe "normal 0i\<CR>\<Esc>" |
| 602 | call assert_equal('', getline(1)) |
| 603 | call assert_equal('xonex xtwoxx', getline(2)) |
| 604 | call assert_equal(expected, prop_list(2)) |
| 605 | call DeletePropTypes() |
| 606 | |
| 607 | " split just before prop, move all props to next line |
| 608 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 609 | exe "normal 0li\<CR>\<Esc>" |
| 610 | call assert_equal('x', getline(1)) |
| 611 | call assert_equal('onex xtwoxx', getline(2)) |
| 612 | let expected[0].col -= 1 |
| 613 | let expected[1].col -= 1 |
| 614 | call assert_equal(expected, prop_list(2)) |
| 615 | call DeletePropTypes() |
| 616 | |
| 617 | " split inside prop, split first prop |
| 618 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 619 | exe "normal 0lli\<CR>\<Esc>" |
| 620 | call assert_equal('xo', getline(1)) |
| 621 | call assert_equal('nex xtwoxx', getline(2)) |
| 622 | let exp_first = [deepcopy(expected[0])] |
| 623 | let exp_first[0].length = 1 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 624 | let exp_first[0].end = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 625 | call assert_equal(exp_first, prop_list(1)) |
| 626 | let expected[0].col = 1 |
| 627 | let expected[0].length = 2 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 628 | let expected[0].start = 0 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 629 | let expected[1].col -= 2 |
| 630 | call assert_equal(expected, prop_list(2)) |
| 631 | call DeletePropTypes() |
| 632 | |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 633 | " split just after first prop, second prop move to next line |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 634 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 635 | exe "normal 0fea\<CR>\<Esc>" |
| 636 | call assert_equal('xone', getline(1)) |
| 637 | call assert_equal('x xtwoxx', getline(2)) |
| 638 | let exp_first = expected[0:0] |
| 639 | call assert_equal(exp_first, prop_list(1)) |
Bram Moolenaar | 5c65e6a | 2019-05-17 11:08:56 +0200 | [diff] [blame] | 640 | let expected = expected[1:1] |
| 641 | let expected[0].col -= 4 |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 642 | call assert_equal(expected, prop_list(2)) |
| 643 | call DeletePropTypes() |
| 644 | |
LemonBoy | 788c06a | 2022-05-14 18:48:05 +0100 | [diff] [blame] | 645 | " split at the space character with 'ai' active, the leading space is removed |
| 646 | " in the second line and the prop is shifted accordingly. |
| 647 | let expected = SetupOneLine() " 'xonex xtwoxx' |
| 648 | set ai |
| 649 | exe "normal 6|i\<CR>\<Esc>" |
| 650 | call assert_equal('xonex', getline(1)) |
| 651 | call assert_equal('xtwoxx', getline(2)) |
| 652 | let expected[1].col -= 6 |
| 653 | call assert_equal(expected, prop_list(1) + prop_list(2)) |
| 654 | set ai& |
| 655 | call DeletePropTypes() |
| 656 | |
Bram Moolenaar | 45dd07f | 2019-05-15 22:45:37 +0200 | [diff] [blame] | 657 | bwipe! |
| 658 | set bs& |
| 659 | endfunc |
| 660 | |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 661 | func Test_prop_clear() |
| 662 | new |
| 663 | call AddPropTypes() |
| 664 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 665 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 666 | |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 667 | eval 1->prop_clear() |
| 668 | call assert_equal([], 1->prop_list()) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 669 | |
| 670 | call DeletePropTypes() |
| 671 | bwipe! |
| 672 | endfunc |
| 673 | |
| 674 | func Test_prop_clear_buf() |
| 675 | new |
| 676 | call AddPropTypes() |
| 677 | call SetupPropsInFirstLine() |
| 678 | let bufnr = bufnr('') |
| 679 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 680 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 98aefe7 | 2018-12-13 22:20:09 +0100 | [diff] [blame] | 681 | |
| 682 | call prop_clear(1, 1, {'bufnr': bufnr}) |
| 683 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 684 | |
| 685 | wincmd w |
| 686 | call DeletePropTypes() |
| 687 | bwipe! |
| 688 | endfunc |
| 689 | |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 690 | func Test_prop_setline() |
| 691 | new |
| 692 | call AddPropTypes() |
| 693 | call SetupPropsInFirstLine() |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 694 | call assert_equal(Get_expected_props(), prop_list(1)) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 695 | |
| 696 | call setline(1, 'foobar') |
| 697 | call assert_equal([], prop_list(1)) |
| 698 | |
| 699 | call DeletePropTypes() |
| 700 | bwipe! |
| 701 | endfunc |
| 702 | |
| 703 | func Test_prop_setbufline() |
| 704 | new |
| 705 | call AddPropTypes() |
| 706 | call SetupPropsInFirstLine() |
| 707 | let bufnr = bufnr('') |
| 708 | wincmd w |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 709 | call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) |
Bram Moolenaar | 21b5038 | 2019-01-04 18:07:24 +0100 | [diff] [blame] | 710 | |
| 711 | call setbufline(bufnr, 1, 'foobar') |
| 712 | call assert_equal([], prop_list(1, {'bufnr': bufnr})) |
| 713 | |
| 714 | wincmd w |
| 715 | call DeletePropTypes() |
| 716 | bwipe! |
| 717 | endfunc |
| 718 | |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 719 | func Test_prop_substitute() |
| 720 | new |
| 721 | " Set first line to 'one two three' |
| 722 | call AddPropTypes() |
| 723 | call SetupPropsInFirstLine() |
| 724 | let expected_props = Get_expected_props() |
| 725 | call assert_equal(expected_props, prop_list(1)) |
| 726 | |
| 727 | " Change "n" in "one" to XX: 'oXXe two three' |
| 728 | s/n/XX/ |
| 729 | let expected_props[0].length += 1 |
| 730 | let expected_props[1].length += 1 |
| 731 | let expected_props[2].col += 1 |
| 732 | let expected_props[3].col += 1 |
| 733 | call assert_equal(expected_props, prop_list(1)) |
| 734 | |
| 735 | " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' |
| 736 | s/t//g |
| 737 | let expected_props[0].length -= 2 |
| 738 | let expected_props[2].length -= 1 |
| 739 | let expected_props[3].length -= 1 |
| 740 | let expected_props[3].col -= 1 |
| 741 | call assert_equal(expected_props, prop_list(1)) |
| 742 | |
| 743 | " Split the line by changing w to line break: 'oXXe ', 'o hree' |
| 744 | " The long prop is split and spans both lines. |
| 745 | " The props on "two" and "three" move to the next line. |
| 746 | s/w/\r/ |
| 747 | let new_props = [ |
| 748 | \ copy(expected_props[0]), |
| 749 | \ copy(expected_props[2]), |
| 750 | \ copy(expected_props[3]), |
| 751 | \ ] |
| 752 | let expected_props[0].length = 5 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 753 | let expected_props[0].end = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 754 | unlet expected_props[3] |
| 755 | unlet expected_props[2] |
| 756 | call assert_equal(expected_props, prop_list(1)) |
| 757 | |
| 758 | let new_props[0].length = 6 |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 759 | let new_props[0].start = 0 |
Bram Moolenaar | 4164bb2 | 2019-01-04 23:09:49 +0100 | [diff] [blame] | 760 | let new_props[1].col = 1 |
| 761 | let new_props[1].length = 1 |
| 762 | let new_props[2].col = 3 |
| 763 | call assert_equal(new_props, prop_list(2)) |
| 764 | |
| 765 | call DeletePropTypes() |
| 766 | bwipe! |
| 767 | endfunc |
| 768 | |
Bram Moolenaar | 663bc89 | 2019-01-08 23:07:24 +0100 | [diff] [blame] | 769 | func Test_prop_change_indent() |
| 770 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 771 | new |
| 772 | call setline(1, [' xxx', 'yyyyy']) |
| 773 | call prop_add(2, 2, {'length': 2, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 774 | 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] | 775 | call assert_equal([expect], prop_list(2)) |
| 776 | |
| 777 | set shiftwidth=3 |
| 778 | normal 2G>> |
| 779 | call assert_equal(' yyyyy', getline(2)) |
| 780 | let expect.col += 3 |
| 781 | call assert_equal([expect], prop_list(2)) |
| 782 | |
| 783 | normal 2G== |
| 784 | call assert_equal(' yyyyy', getline(2)) |
| 785 | let expect.col = 6 |
| 786 | call assert_equal([expect], prop_list(2)) |
| 787 | |
| 788 | call prop_clear(2) |
| 789 | call prop_add(2, 2, {'length': 5, 'type': 'comment'}) |
| 790 | let expect.col = 2 |
| 791 | let expect.length = 5 |
| 792 | call assert_equal([expect], prop_list(2)) |
| 793 | |
| 794 | normal 2G<< |
| 795 | call assert_equal(' yyyyy', getline(2)) |
| 796 | let expect.length = 2 |
| 797 | call assert_equal([expect], prop_list(2)) |
| 798 | |
| 799 | set shiftwidth& |
| 800 | call prop_type_delete('comment') |
| 801 | endfunc |
| 802 | |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 803 | " Setup a three line prop in lines 2 - 4. |
| 804 | " Add short props in line 1 and 5. |
| 805 | func Setup_three_line_prop() |
| 806 | new |
| 807 | call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) |
| 808 | call prop_add(1, 2, {'length': 1, 'type': 'comment'}) |
| 809 | call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) |
| 810 | call prop_add(5, 2, {'length': 1, 'type': 'comment'}) |
| 811 | endfunc |
| 812 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 813 | func Test_prop_multiline() |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 814 | eval 'comment'->prop_type_add({'highlight': 'Directory'}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 815 | new |
| 816 | call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) |
| 817 | |
| 818 | " start halfway line 1, end halfway line 3 |
| 819 | 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] | 820 | 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] | 821 | call assert_equal([expect1], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 822 | 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] | 823 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 824 | 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] | 825 | call assert_equal([expect3], prop_list(3)) |
| 826 | call prop_clear(1, 3) |
| 827 | |
| 828 | " include all three lines |
| 829 | call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) |
| 830 | let expect1.col = 1 |
| 831 | let expect1.length = 8 |
| 832 | call assert_equal([expect1], prop_list(1)) |
| 833 | call assert_equal([expect2], prop_list(2)) |
| 834 | let expect3.length = 9 |
| 835 | call assert_equal([expect3], prop_list(3)) |
| 836 | call prop_clear(1, 3) |
| 837 | |
| 838 | bwipe! |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 839 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 840 | " Test deleting the first line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 841 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 842 | 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] | 843 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 844 | 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] | 845 | call assert_equal([expect2], prop_list(2)) |
| 846 | 2del |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 847 | call assert_equal([expect_short], prop_list(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 848 | 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] | 849 | call assert_equal([expect2], prop_list(2)) |
| 850 | bwipe! |
| 851 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 852 | " Test deleting the last line of a multi-line prop. |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 853 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 854 | 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] | 855 | call assert_equal([expect3], prop_list(3)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 856 | 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] | 857 | call assert_equal([expect4], prop_list(4)) |
| 858 | 4del |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 859 | let expect3.end = 1 |
Bram Moolenaar | c1a9bc1 | 2018-12-28 21:59:29 +0100 | [diff] [blame] | 860 | call assert_equal([expect3], prop_list(3)) |
| 861 | call assert_equal([expect_short], prop_list(4)) |
| 862 | bwipe! |
| 863 | |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 864 | " Test appending a line below the multi-line text prop start. |
Bram Moolenaar | b56ac04 | 2018-12-28 23:22:40 +0100 | [diff] [blame] | 865 | call Setup_three_line_prop() |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 866 | 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] | 867 | call assert_equal([expect2], prop_list(2)) |
| 868 | call append(2, "new line") |
| 869 | call assert_equal([expect2], prop_list(2)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 870 | 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] | 871 | call assert_equal([expect3], prop_list(3)) |
| 872 | bwipe! |
| 873 | |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 874 | call prop_type_delete('comment') |
| 875 | endfunc |
| 876 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 877 | func Test_prop_line2byte() |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 878 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 879 | new |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 880 | call setline(1, ['line1', 'second line', '']) |
Bram Moolenaar | 8cf734e | 2018-12-26 01:09:00 +0100 | [diff] [blame] | 881 | set ff=unix |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 882 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 883 | call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) |
Bram Moolenaar | 00b1e04 | 2018-12-26 23:42:10 +0100 | [diff] [blame] | 884 | call assert_equal(19, line2byte(3)) |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 885 | bwipe! |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 886 | |
| 887 | new |
Bram Moolenaar | a401bba | 2021-08-15 15:04:41 +0200 | [diff] [blame] | 888 | setlocal ff=unix |
Bram Moolenaar | 14c7530 | 2021-08-15 14:28:40 +0200 | [diff] [blame] | 889 | call setline(1, range(500)) |
| 890 | call assert_equal(1491, line2byte(401)) |
| 891 | call prop_add(2, 1, {'type': 'comment'}) |
| 892 | call prop_add(222, 1, {'type': 'comment'}) |
| 893 | call assert_equal(1491, line2byte(401)) |
| 894 | call prop_remove({'type': 'comment'}) |
| 895 | call assert_equal(1491, line2byte(401)) |
| 896 | bwipe! |
| 897 | |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 898 | new |
Bram Moolenaar | 49b9304 | 2021-08-25 17:02:00 +0200 | [diff] [blame] | 899 | setlocal ff=unix |
Bram Moolenaar | cdd8a5e | 2021-08-25 16:40:03 +0200 | [diff] [blame] | 900 | call setline(1, range(520)) |
| 901 | call assert_equal(1491, line2byte(401)) |
| 902 | call prop_add(2, 1, {'type': 'comment'}) |
| 903 | call assert_equal(1491, line2byte(401)) |
| 904 | 2delete |
| 905 | call assert_equal(1489, line2byte(400)) |
| 906 | bwipe! |
| 907 | |
Bram Moolenaar | b413d2e | 2018-12-25 23:15:46 +0100 | [diff] [blame] | 908 | call prop_type_delete('comment') |
| 909 | endfunc |
| 910 | |
Bram Moolenaar | 9df53b6 | 2020-01-13 20:40:51 +0100 | [diff] [blame] | 911 | func Test_prop_byte2line() |
| 912 | new |
| 913 | set ff=unix |
| 914 | call setline(1, ['one one', 'two two', 'three three', 'four four', 'five']) |
| 915 | call assert_equal(4, byte2line(line2byte(4))) |
| 916 | call assert_equal(5, byte2line(line2byte(5))) |
| 917 | |
| 918 | call prop_type_add('prop', {'highlight': 'Directory'}) |
| 919 | call prop_add(3, 1, {'length': 5, 'type': 'prop'}) |
| 920 | call assert_equal(4, byte2line(line2byte(4))) |
| 921 | call assert_equal(5, byte2line(line2byte(5))) |
| 922 | |
| 923 | bwipe! |
| 924 | call prop_type_delete('prop') |
| 925 | endfunc |
| 926 | |
Bram Moolenaar | 59ff640 | 2021-01-30 17:16:28 +0100 | [diff] [blame] | 927 | func Test_prop_goto_byte() |
| 928 | new |
| 929 | call setline(1, '') |
| 930 | call setline(2, 'two three') |
| 931 | call setline(3, '') |
| 932 | call setline(4, 'four five') |
| 933 | |
| 934 | call prop_type_add('testprop', {'highlight': 'Directory'}) |
| 935 | call search('^two') |
| 936 | call prop_add(line('.'), col('.'), { |
| 937 | \ 'length': len('two'), |
| 938 | \ 'type': 'testprop' |
| 939 | \ }) |
| 940 | |
| 941 | call search('two \zsthree') |
| 942 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 943 | exe expected_pos .. 'goto' |
| 944 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 945 | eval actual_pos->assert_equal(expected_pos) |
| 946 | |
| 947 | call search('four \zsfive') |
| 948 | let expected_pos = line2byte(line('.')) + col('.') - 1 |
| 949 | exe expected_pos .. 'goto' |
| 950 | let actual_pos = line2byte(line('.')) + col('.') - 1 |
| 951 | eval actual_pos->assert_equal(expected_pos) |
| 952 | |
| 953 | call prop_type_delete('testprop') |
| 954 | bwipe! |
| 955 | endfunc |
| 956 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 957 | func Test_prop_undo() |
| 958 | new |
| 959 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 960 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 961 | " Set 'undolevels' to break changes into undo-able pieces. |
| 962 | set ul& |
| 963 | |
| 964 | call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 965 | 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] | 966 | call assert_equal(expected, prop_list(1)) |
| 967 | |
| 968 | " Insert a character, then undo. |
| 969 | exe "normal 0lllix\<Esc>" |
| 970 | set ul& |
| 971 | let expected[0].length = 3 |
| 972 | call assert_equal(expected, prop_list(1)) |
| 973 | undo |
| 974 | let expected[0].length = 2 |
| 975 | call assert_equal(expected, prop_list(1)) |
| 976 | |
| 977 | " Delete a character, then undo |
| 978 | exe "normal 0lllx" |
| 979 | set ul& |
| 980 | let expected[0].length = 1 |
| 981 | call assert_equal(expected, prop_list(1)) |
| 982 | undo |
| 983 | let expected[0].length = 2 |
| 984 | call assert_equal(expected, prop_list(1)) |
| 985 | |
| 986 | " Delete the line, then undo |
| 987 | 1d |
| 988 | set ul& |
| 989 | call assert_equal([], prop_list(1)) |
| 990 | undo |
| 991 | call assert_equal(expected, prop_list(1)) |
| 992 | |
| 993 | " Insert a character, delete two characters, then undo with "U" |
| 994 | exe "normal 0lllix\<Esc>" |
| 995 | set ul& |
| 996 | let expected[0].length = 3 |
| 997 | call assert_equal(expected, prop_list(1)) |
| 998 | exe "normal 0lllxx" |
| 999 | set ul& |
| 1000 | let expected[0].length = 1 |
| 1001 | call assert_equal(expected, prop_list(1)) |
| 1002 | normal U |
| 1003 | let expected[0].length = 2 |
| 1004 | call assert_equal(expected, prop_list(1)) |
| 1005 | |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1006 | " substitute a word, then undo |
| 1007 | call setline(1, 'the number 123 is highlighted.') |
| 1008 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1009 | 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] | 1010 | call assert_equal(expected, prop_list(1)) |
| 1011 | set ul& |
| 1012 | 1s/number/foo |
| 1013 | let expected[0].col = 9 |
| 1014 | call assert_equal(expected, prop_list(1)) |
| 1015 | undo |
| 1016 | let expected[0].col = 12 |
| 1017 | call assert_equal(expected, prop_list(1)) |
Bram Moolenaar | f3333b0 | 2019-05-19 22:53:40 +0200 | [diff] [blame] | 1018 | call prop_clear(1) |
| 1019 | |
| 1020 | " substitute with backslash |
| 1021 | call setline(1, 'the number 123 is highlighted.') |
| 1022 | call prop_add(1, 12, {'length': 3, 'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1023 | 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] | 1024 | call assert_equal(expected, prop_list(1)) |
| 1025 | 1s/the/\The |
| 1026 | call assert_equal(expected, prop_list(1)) |
| 1027 | 1s/^/\\ |
| 1028 | let expected[0].col += 1 |
| 1029 | call assert_equal(expected, prop_list(1)) |
| 1030 | 1s/^/\~ |
| 1031 | let expected[0].col += 1 |
| 1032 | call assert_equal(expected, prop_list(1)) |
| 1033 | 1s/123/12\\3 |
| 1034 | let expected[0].length += 1 |
| 1035 | call assert_equal(expected, prop_list(1)) |
| 1036 | call prop_clear(1) |
Bram Moolenaar | 338dfda | 2019-05-19 15:19:57 +0200 | [diff] [blame] | 1037 | |
Bram Moolenaar | 7f1664e | 2019-01-04 17:21:24 +0100 | [diff] [blame] | 1038 | bwipe! |
| 1039 | call prop_type_delete('comment') |
| 1040 | endfunc |
| 1041 | |
Bram Moolenaar | ecafcc1 | 2019-11-16 20:41:51 +0100 | [diff] [blame] | 1042 | func Test_prop_delete_text() |
| 1043 | new |
| 1044 | call prop_type_add('comment', {'highlight': 'Directory'}) |
| 1045 | call setline(1, ['oneone', 'twotwo', 'three']) |
| 1046 | |
| 1047 | " zero length property |
| 1048 | call prop_add(1, 3, {'type': 'comment'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1049 | 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] | 1050 | call assert_equal(expected, prop_list(1)) |
| 1051 | |
| 1052 | " delete one char moves the property |
| 1053 | normal! x |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1054 | 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] | 1055 | call assert_equal(expected, prop_list(1)) |
| 1056 | |
| 1057 | " delete char of the property has no effect |
| 1058 | normal! lx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1059 | 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] | 1060 | call assert_equal(expected, prop_list(1)) |
| 1061 | |
| 1062 | " delete more chars moves property to first column, is not deleted |
| 1063 | normal! 0xxxx |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1064 | 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] | 1065 | call assert_equal(expected, prop_list(1)) |
| 1066 | |
| 1067 | bwipe! |
| 1068 | call prop_type_delete('comment') |
| 1069 | endfunc |
| 1070 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1071 | " screenshot test with textprop highlighting |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1072 | func Test_textprop_screenshot_various() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1073 | CheckScreendump |
Bram Moolenaar | ed79d1e | 2019-02-22 14:38:58 +0100 | [diff] [blame] | 1074 | " The Vim running in the terminal needs to use utf-8. |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1075 | if g:orig_encoding != 'utf-8' |
| 1076 | throw 'Skipped: not using utf-8' |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1077 | endif |
| 1078 | call writefile([ |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1079 | \ "call setline(1, [" |
| 1080 | \ .. "'One two'," |
| 1081 | \ .. "'Numbér 123 änd thœn 4¾7.'," |
| 1082 | \ .. "'--aa--bb--cc--dd--'," |
| 1083 | \ .. "'// comment with error in it'," |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1084 | \ .. "'first line'," |
| 1085 | \ .. "' second line '," |
| 1086 | \ .. "'third line'," |
| 1087 | \ .. "' fourth line'," |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1088 | \ .. "])", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1089 | \ "hi NumberProp ctermfg=blue", |
| 1090 | \ "hi LongProp ctermbg=yellow", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1091 | \ "hi BackgroundProp ctermbg=lightgrey", |
| 1092 | \ "hi UnderlineProp cterm=underline", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1093 | \ "call prop_type_add('number', {'highlight': 'NumberProp'})", |
Bram Moolenaar | a5a7882 | 2019-09-04 21:57:18 +0200 | [diff] [blame] | 1094 | \ "call prop_type_add('long', {'highlight': 'NumberProp'})", |
| 1095 | \ "call prop_type_change('long', {'highlight': 'LongProp'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1096 | \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", |
| 1097 | \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", |
| 1098 | \ "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] | 1099 | \ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 0})", |
| 1100 | \ "call prop_type_add('backgroundcomb', {'highlight': 'NumberProp', 'combine': 1})", |
| 1101 | \ "eval 'backgroundcomb'->prop_type_change({'highlight': 'BackgroundProp'})", |
Bram Moolenaar | 58e32ab | 2019-11-12 22:44:22 +0100 | [diff] [blame] | 1102 | \ "call prop_type_add('error', {'highlight': 'UnderlineProp'})", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1103 | \ "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] | 1104 | \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", |
| 1105 | \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1106 | \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", |
| 1107 | \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", |
| 1108 | \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", |
| 1109 | \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 1110 | \ "call prop_add(4, 6, {'length': 3, 'type': 'background'})", |
| 1111 | \ "call prop_add(4, 12, {'length': 10, 'type': 'backgroundcomb'})", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1112 | \ "call prop_add(4, 17, {'length': 5, 'type': 'error'})", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1113 | \ "call prop_add(5, 7, {'length': 4, 'type': 'long'})", |
| 1114 | \ "call prop_add(6, 1, {'length': 8, 'type': 'long'})", |
| 1115 | \ "call prop_add(8, 1, {'length': 1, 'type': 'long'})", |
| 1116 | \ "call prop_add(8, 11, {'length': 4, 'type': 'long'})", |
Bram Moolenaar | bfd4512 | 2019-05-17 13:05:07 +0200 | [diff] [blame] | 1117 | \ "set number cursorline", |
Bram Moolenaar | b9c67a5 | 2019-01-01 19:49:20 +0100 | [diff] [blame] | 1118 | \ "hi clear SpellBad", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1119 | \ "set spell", |
Bram Moolenaar | de24a87 | 2019-05-05 15:48:00 +0200 | [diff] [blame] | 1120 | \ "syn match Comment '//.*'", |
| 1121 | \ "hi Comment ctermfg=green", |
Bram Moolenaar | 44746aa | 2019-01-02 00:02:11 +0100 | [diff] [blame] | 1122 | \ "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] | 1123 | \ "normal 3G0lli\<BS>\<Esc>", |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1124 | \ "normal 6G0i\<BS>\<Esc>", |
| 1125 | \ "normal 3J", |
| 1126 | \ "normal 3G", |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1127 | \], 'XtestProp') |
Bram Moolenaar | 80e737c | 2019-05-17 19:56:34 +0200 | [diff] [blame] | 1128 | let buf = RunVimInTerminal('-S XtestProp', {'rows': 8}) |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1129 | call VerifyScreenDump(buf, 'Test_textprop_01', {}) |
Bram Moolenaar | e3d31b0 | 2018-12-24 23:07:04 +0100 | [diff] [blame] | 1130 | |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1131 | " clean up |
| 1132 | call StopVimInTerminal(buf) |
Bram Moolenaar | 2f21fa8 | 2018-12-31 20:05:56 +0100 | [diff] [blame] | 1133 | call delete('XtestProp') |
Bram Moolenaar | c6d86dc | 2018-12-31 13:57:36 +0100 | [diff] [blame] | 1134 | endfunc |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1135 | |
Bram Moolenaar | f4ba8bc | 2022-08-05 17:05:04 +0100 | [diff] [blame] | 1136 | func Test_textprop_hl_override() |
| 1137 | CheckScreendump |
| 1138 | |
| 1139 | let lines =<< trim END |
| 1140 | call setline(1, ['One one one one one', 'Two two two two two', 'Three three three three']) |
| 1141 | hi OverProp ctermfg=blue ctermbg=yellow |
| 1142 | hi CursorLine cterm=bold,underline ctermfg=red ctermbg=green |
| 1143 | hi Vsual ctermfg=cyan ctermbg=grey |
| 1144 | call prop_type_add('under', #{highlight: 'OverProp'}) |
| 1145 | call prop_type_add('over', #{highlight: 'OverProp', override: 1}) |
| 1146 | call prop_add(1, 5, #{type: 'under', length: 4}) |
| 1147 | call prop_add(1, 13, #{type: 'over', length: 4}) |
| 1148 | call prop_add(2, 5, #{type: 'under', length: 4}) |
| 1149 | call prop_add(2, 13, #{type: 'over', length: 4}) |
| 1150 | call prop_add(3, 5, #{type: 'under', length: 4}) |
| 1151 | call prop_add(3, 13, #{type: 'over', length: 4}) |
| 1152 | set cursorline |
| 1153 | 2 |
| 1154 | END |
| 1155 | call writefile(lines, 'XtestOverProp') |
| 1156 | let buf = RunVimInTerminal('-S XtestOverProp', {'rows': 8}) |
| 1157 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_1', {}) |
| 1158 | |
| 1159 | call term_sendkeys(buf, "3Gllv$hh") |
| 1160 | call VerifyScreenDump(buf, 'Test_textprop_hl_override_2', {}) |
| 1161 | call term_sendkeys(buf, "\<Esc>") |
| 1162 | |
| 1163 | " clean up |
| 1164 | call StopVimInTerminal(buf) |
| 1165 | call delete('XtestOverProp') |
| 1166 | endfunc |
| 1167 | |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1168 | func RunTestVisualBlock(width, dump) |
| 1169 | call writefile([ |
| 1170 | \ "call setline(1, [" |
| 1171 | \ .. "'xxxxxxxxx 123 x'," |
| 1172 | \ .. "'xxxxxxxx 123 x'," |
| 1173 | \ .. "'xxxxxxx 123 x'," |
| 1174 | \ .. "'xxxxxx 123 x'," |
| 1175 | \ .. "'xxxxx 123 x'," |
| 1176 | \ .. "'xxxx 123 xx'," |
| 1177 | \ .. "'xxx 123 xxx'," |
| 1178 | \ .. "'xx 123 xxxx'," |
| 1179 | \ .. "'x 123 xxxxx'," |
| 1180 | \ .. "' 123 xxxxxx'," |
| 1181 | \ .. "])", |
| 1182 | \ "hi SearchProp ctermbg=yellow", |
| 1183 | \ "call prop_type_add('search', {'highlight': 'SearchProp'})", |
| 1184 | \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", |
| 1185 | \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", |
| 1186 | \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", |
| 1187 | \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", |
| 1188 | \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", |
| 1189 | \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", |
| 1190 | \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", |
| 1191 | \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", |
| 1192 | \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", |
| 1193 | \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", |
| 1194 | \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", |
| 1195 | \], 'XtestPropVis') |
| 1196 | let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) |
| 1197 | call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) |
| 1198 | |
| 1199 | " clean up |
| 1200 | call StopVimInTerminal(buf) |
| 1201 | call delete('XtestPropVis') |
| 1202 | endfunc |
| 1203 | |
| 1204 | " screenshot test with Visual block mode operations |
| 1205 | func Test_textprop_screenshot_visual() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1206 | CheckScreendump |
Bram Moolenaar | 8055d17 | 2019-05-17 22:57:26 +0200 | [diff] [blame] | 1207 | |
| 1208 | " Delete two columns while text props are three chars wide. |
| 1209 | call RunTestVisualBlock(2, '01') |
| 1210 | |
| 1211 | " Same, but delete four columns |
| 1212 | call RunTestVisualBlock(4, '02') |
| 1213 | endfunc |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1214 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1215 | func Test_textprop_after_tab() |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1216 | CheckScreendump |
Bram Moolenaar | 37e66cf | 2019-06-19 18:16:10 +0200 | [diff] [blame] | 1217 | |
Bram Moolenaar | a956bf6 | 2019-06-19 17:34:24 +0200 | [diff] [blame] | 1218 | let lines =<< trim END |
| 1219 | call setline(1, [ |
| 1220 | \ "\txxx", |
| 1221 | \ "x\txxx", |
| 1222 | \ ]) |
| 1223 | hi SearchProp ctermbg=yellow |
| 1224 | call prop_type_add('search', {'highlight': 'SearchProp'}) |
| 1225 | call prop_add(1, 2, {'length': 3, 'type': 'search'}) |
| 1226 | call prop_add(2, 3, {'length': 3, 'type': 'search'}) |
| 1227 | END |
| 1228 | call writefile(lines, 'XtestPropTab') |
| 1229 | let buf = RunVimInTerminal('-S XtestPropTab', {'rows': 6}) |
| 1230 | call VerifyScreenDump(buf, 'Test_textprop_tab', {}) |
| 1231 | |
| 1232 | " clean up |
| 1233 | call StopVimInTerminal(buf) |
| 1234 | call delete('XtestPropTab') |
| 1235 | endfunc |
| 1236 | |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 1237 | func Test_textprop_nowrap_scrolled() |
| 1238 | CheckScreendump |
| 1239 | |
| 1240 | let lines =<< trim END |
| 1241 | vim9script |
| 1242 | set nowrap |
| 1243 | setline(1, 'The number 123 is smaller than 4567.' .. repeat('X', &columns)) |
| 1244 | prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1245 | prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1246 | prop_add(1, 32, {'length': 4, 'type': 'number'}) |
| 1247 | feedkeys('gg20zl', 'nxt') |
| 1248 | END |
| 1249 | call writefile(lines, 'XtestNowrap') |
| 1250 | let buf = RunVimInTerminal('-S XtestNowrap', {'rows': 6}) |
| 1251 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_01', {}) |
| 1252 | |
| 1253 | call term_sendkeys(buf, "$") |
| 1254 | call VerifyScreenDump(buf, 'Test_textprop_nowrap_02', {}) |
| 1255 | |
| 1256 | " clean up |
| 1257 | call StopVimInTerminal(buf) |
| 1258 | call delete('XtestNowrap') |
| 1259 | endfunc |
| 1260 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1261 | func Test_textprop_with_syntax() |
| 1262 | CheckScreendump |
| 1263 | |
| 1264 | let lines =<< trim END |
| 1265 | call setline(1, [ |
| 1266 | \ "(abc)", |
| 1267 | \ ]) |
| 1268 | syn match csParens "[()]" display |
| 1269 | hi! link csParens MatchParen |
| 1270 | |
| 1271 | call prop_type_add('TPTitle', #{ highlight: 'Title' }) |
| 1272 | call prop_add(1, 2, #{type: 'TPTitle', end_col: 5}) |
| 1273 | END |
| 1274 | call writefile(lines, 'XtestPropSyn') |
| 1275 | let buf = RunVimInTerminal('-S XtestPropSyn', {'rows': 6}) |
| 1276 | call VerifyScreenDump(buf, 'Test_textprop_syn_1', {}) |
| 1277 | |
| 1278 | " clean up |
| 1279 | call StopVimInTerminal(buf) |
| 1280 | call delete('XtestPropSyn') |
| 1281 | endfunc |
| 1282 | |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1283 | " Adding a text property to a new buffer should not fail |
| 1284 | func Test_textprop_empty_buffer() |
| 1285 | call prop_type_add('comment', {'highlight': 'Search'}) |
| 1286 | new |
| 1287 | call prop_add(1, 1, {'type': 'comment'}) |
| 1288 | close |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1289 | call prop_type_delete('comment') |
| 1290 | endfunc |
| 1291 | |
Bram Moolenaar | d74af42 | 2019-06-28 21:38:00 +0200 | [diff] [blame] | 1292 | " Adding a text property with invalid highlight should be ignored. |
| 1293 | func Test_textprop_invalid_highlight() |
| 1294 | call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:') |
| 1295 | new |
| 1296 | call setline(1, ['asdf','asdf']) |
| 1297 | call prop_add(1, 1, {'length': 4, 'type': 'dni'}) |
| 1298 | redraw |
| 1299 | bwipe! |
| 1300 | call prop_type_delete('dni') |
| 1301 | endfunc |
| 1302 | |
Bram Moolenaar | adfde11 | 2019-05-25 22:11:45 +0200 | [diff] [blame] | 1303 | " Adding a text property to an empty buffer and then editing another |
| 1304 | func Test_textprop_empty_buffer_next() |
| 1305 | call prop_type_add("xxx", {}) |
| 1306 | call prop_add(1, 1, {"type": "xxx"}) |
| 1307 | next X |
| 1308 | call prop_type_delete('xxx') |
Bram Moolenaar | d79eef2 | 2019-05-24 20:41:55 +0200 | [diff] [blame] | 1309 | endfunc |
Bram Moolenaar | f0884c5 | 2019-05-24 21:22:29 +0200 | [diff] [blame] | 1310 | |
| 1311 | func Test_textprop_remove_from_buf() |
| 1312 | new |
| 1313 | let buf = bufnr('') |
| 1314 | call prop_type_add('one', {'bufnr': buf}) |
| 1315 | call prop_add(1, 1, {'type': 'one', 'id': 234}) |
| 1316 | file x |
| 1317 | edit y |
| 1318 | call prop_remove({'id': 234, 'bufnr': buf}, 1) |
| 1319 | call prop_type_delete('one', {'bufnr': buf}) |
| 1320 | bwipe! x |
| 1321 | close |
| 1322 | endfunc |
Bram Moolenaar | 45311b5 | 2019-08-13 22:27:32 +0200 | [diff] [blame] | 1323 | |
| 1324 | func Test_textprop_in_unloaded_buf() |
| 1325 | edit Xaaa |
| 1326 | call setline(1, 'aaa') |
| 1327 | write |
| 1328 | edit Xbbb |
| 1329 | call setline(1, 'bbb') |
| 1330 | write |
| 1331 | let bnr = bufnr('') |
| 1332 | edit Xaaa |
| 1333 | |
| 1334 | call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'}) |
| 1335 | call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:') |
| 1336 | exe 'buf ' .. bnr |
| 1337 | call assert_equal('bbb', getline(1)) |
| 1338 | call assert_equal(0, prop_list(1)->len()) |
| 1339 | |
| 1340 | bwipe! Xaaa |
| 1341 | bwipe! Xbbb |
| 1342 | cal delete('Xaaa') |
| 1343 | cal delete('Xbbb') |
| 1344 | endfunc |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1345 | |
| 1346 | func Test_proptype_substitute2() |
| 1347 | new |
| 1348 | " text_prop.vim |
| 1349 | call setline(1, [ |
| 1350 | \ 'The num 123 is smaller than 4567.', |
| 1351 | \ '123 The number 123 is smaller than 4567.', |
| 1352 | \ '123 The number 123 is smaller than 4567.']) |
| 1353 | |
| 1354 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1355 | |
| 1356 | call prop_add(1, 12, {'length': 3, 'type': 'number'}) |
| 1357 | call prop_add(2, 1, {'length': 3, 'type': 'number'}) |
| 1358 | call prop_add(3, 36, {'length': 4, 'type': 'number'}) |
| 1359 | set ul& |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1360 | let expected = [ |
| 1361 | \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1}, |
| 1362 | \ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1}, |
| 1363 | \ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}] |
| 1364 | |
| 1365 | " TODO |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1366 | if 0 |
| 1367 | " Add some text in between |
| 1368 | %s/\s\+/ /g |
| 1369 | 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] | 1370 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1371 | " remove some text |
| 1372 | :1s/[a-z]\{3\}//g |
| 1373 | let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}] |
| 1374 | call assert_equal(expected, prop_list(1)) |
| 1375 | endif |
| 1376 | |
| 1377 | call prop_type_delete('number') |
Bram Moolenaar | 1fd30d7 | 2019-10-25 22:13:29 +0200 | [diff] [blame] | 1378 | bwipe! |
| 1379 | endfunc |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1380 | |
Bram Moolenaar | 8902b31 | 2020-09-20 21:04:35 +0200 | [diff] [blame] | 1381 | " This was causing property corruption. |
| 1382 | func Test_proptype_substitute3() |
| 1383 | new |
| 1384 | call setline(1, ['abcxxx', 'def']) |
| 1385 | call prop_type_add("test", {"highlight": "Search"}) |
| 1386 | call prop_add(1, 2, {"end_lnum": 2, "end_col": 2, "type": "test"}) |
| 1387 | %s/x\+$// |
| 1388 | redraw |
| 1389 | |
| 1390 | call prop_type_delete('test') |
| 1391 | bwipe! |
| 1392 | endfunc |
| 1393 | |
Bram Moolenaar | 213bbaf | 2022-08-05 19:46:48 +0100 | [diff] [blame] | 1394 | func Test_proptype_substitute_join() |
| 1395 | new |
| 1396 | call setline(1, [ |
| 1397 | \ 'This is some end', |
| 1398 | \ 'start is highlighted end', |
| 1399 | \ 'some is highlighted', |
| 1400 | \ 'start is also highlighted']) |
| 1401 | |
| 1402 | call prop_type_add('number', {'highlight': 'ErrorMsg'}) |
| 1403 | |
| 1404 | call prop_add(1, 6, {'length': 2, 'type': 'number'}) |
| 1405 | call prop_add(2, 7, {'length': 2, 'type': 'number'}) |
| 1406 | call prop_add(3, 6, {'length': 2, 'type': 'number'}) |
| 1407 | call prop_add(4, 7, {'length': 2, 'type': 'number'}) |
| 1408 | " The highlighted "is" in line 1, 2 and 4 is kept and ajudsted. |
| 1409 | " The highlighted "is" in line 3 is deleted. |
| 1410 | let expected = [ |
| 1411 | \ #{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'number', length: 2, start: 1}, |
| 1412 | \ #{type_bufnr: 0, id: 0, col: 21, end: 1, type: 'number', length: 2, start: 1}, |
| 1413 | \ #{type_bufnr: 0, id: 0, col: 43, end: 1, type: 'number', length: 2, start: 1}] |
| 1414 | |
| 1415 | s/end\nstart/joined/ |
| 1416 | s/end\n.*\nstart/joined/ |
| 1417 | call assert_equal('This is some joined is highlighted joined is also highlighted', getline(1)) |
| 1418 | call assert_equal(expected, prop_list(1)) |
| 1419 | |
| 1420 | call prop_type_delete('number') |
| 1421 | bwipe! |
| 1422 | endfunc |
| 1423 | |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1424 | func SaveOptions() |
| 1425 | let d = #{tabstop: &tabstop, |
| 1426 | \ softtabstop: &softtabstop, |
| 1427 | \ shiftwidth: &shiftwidth, |
| 1428 | \ expandtab: &expandtab, |
| 1429 | \ foldmethod: '"' .. &foldmethod .. '"', |
| 1430 | \ } |
| 1431 | return d |
| 1432 | endfunc |
| 1433 | |
| 1434 | func RestoreOptions(dict) |
| 1435 | for name in keys(a:dict) |
| 1436 | exe 'let &' .. name .. ' = ' .. a:dict[name] |
| 1437 | endfor |
| 1438 | endfunc |
| 1439 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1440 | func Test_textprop_noexpandtab() |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1441 | new |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1442 | let save_dict = SaveOptions() |
| 1443 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1444 | set tabstop=8 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1445 | set softtabstop=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1446 | set shiftwidth=4 |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1447 | set noexpandtab |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1448 | set foldmethod=marker |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1449 | |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1450 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx") |
| 1451 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1452 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1453 | call feedkeys("0i\<tab>", "tx") |
| 1454 | call prop_remove({'type': 'test'}) |
| 1455 | call prop_add(1, 2, {'end_col': 3, 'type': 'test'}) |
| 1456 | call feedkeys("A\<left>\<tab>", "tx") |
| 1457 | call prop_remove({'type': 'test'}) |
| 1458 | try |
| 1459 | " It is correct that this does not pass |
| 1460 | call prop_add(1, 6, {'end_col': 7, 'type': 'test'}) |
| 1461 | " Has already collapsed here, start_col:6 does not result in an error |
| 1462 | call feedkeys("A\<left>\<tab>", "tx") |
| 1463 | catch /^Vim\%((\a\+)\)\=:E964/ |
| 1464 | endtry |
| 1465 | call prop_remove({'type': 'test'}) |
Bram Moolenaar | ac15fd8 | 2020-01-09 21:35:48 +0100 | [diff] [blame] | 1466 | call prop_type_delete('test') |
| 1467 | |
| 1468 | call RestoreOptions(save_dict) |
| 1469 | bwipe! |
| 1470 | endfunc |
| 1471 | |
| 1472 | func Test_textprop_noexpandtab_redraw() |
| 1473 | new |
| 1474 | let save_dict = SaveOptions() |
| 1475 | |
| 1476 | set tabstop=8 |
| 1477 | set softtabstop=4 |
| 1478 | set shiftwidth=4 |
| 1479 | set noexpandtab |
| 1480 | set foldmethod=marker |
| 1481 | |
| 1482 | call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx") |
| 1483 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1484 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1485 | call feedkeys("0i\<tab>", "tx") |
| 1486 | " Internally broken at the next line |
| 1487 | call feedkeys("A\<left>\<tab>", "tx") |
| 1488 | redraw |
| 1489 | " Index calculation failed internally on next line |
| 1490 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
| 1491 | call prop_remove({'type': 'test', 'all': v:true}) |
| 1492 | call prop_type_delete('test') |
| 1493 | call prop_type_delete('test') |
| 1494 | |
| 1495 | call RestoreOptions(save_dict) |
| 1496 | bwipe! |
| 1497 | endfunc |
| 1498 | |
| 1499 | func Test_textprop_ins_str() |
| 1500 | new |
| 1501 | call setline(1, 'just some text') |
| 1502 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1503 | call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1504 | 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] | 1505 | |
| 1506 | call feedkeys("foi\<F8>\<Esc>", "tx") |
| 1507 | call assert_equal('just s<F8>ome text', getline(1)) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1508 | 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] | 1509 | |
| 1510 | bwipe! |
| 1511 | call prop_remove({'type': 'test'}) |
| 1512 | call prop_type_delete('test') |
Bram Moolenaar | 5cb0b93 | 2020-01-03 21:25:59 +0100 | [diff] [blame] | 1513 | endfunc |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1514 | |
| 1515 | func Test_find_prop_later_in_line() |
| 1516 | new |
| 1517 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1518 | call setline(1, 'just some text') |
| 1519 | call prop_add(1, 1, {'length': 4, 'type': 'test'}) |
| 1520 | call prop_add(1, 10, {'length': 3, 'type': 'test'}) |
| 1521 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1522 | call assert_equal( |
| 1523 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1}, |
| 1524 | \ prop_find(#{type: 'test', lnum: 1, col: 6})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1525 | |
| 1526 | bwipe! |
| 1527 | call prop_type_delete('test') |
| 1528 | endfunc |
| 1529 | |
| 1530 | func Test_find_zerowidth_prop_sol() |
| 1531 | new |
| 1532 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1533 | call setline(1, 'just some text') |
| 1534 | call prop_add(1, 1, {'length': 0, 'type': 'test'}) |
| 1535 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1536 | call assert_equal( |
| 1537 | \ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1}, |
| 1538 | \ prop_find(#{type: 'test', lnum: 1})) |
Bram Moolenaar | 66b9885 | 2020-03-11 19:15:52 +0100 | [diff] [blame] | 1539 | |
| 1540 | bwipe! |
| 1541 | call prop_type_delete('test') |
| 1542 | endfunc |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1543 | |
| 1544 | " Test for passing invalid arguments to prop_xxx() functions |
| 1545 | func Test_prop_func_invalid_args() |
| 1546 | call assert_fails('call prop_clear(1, 2, [])', 'E715:') |
| 1547 | call assert_fails('call prop_clear(-1, 2)', 'E16:') |
Yegappan Lakshmanan | 5b73992 | 2021-07-10 13:15:41 +0200 | [diff] [blame] | 1548 | call assert_fails('call prop_find(test_null_dict())', 'E715:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1549 | call assert_fails('call prop_find({"bufnr" : []})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1550 | call assert_fails('call prop_find({})', 'E968:') |
| 1551 | call assert_fails('call prop_find({}, "x")', 'E474:') |
| 1552 | call assert_fails('call prop_find({"lnum" : -2})', 'E16:') |
| 1553 | call assert_fails('call prop_list(1, [])', 'E715:') |
Bram Moolenaar | 9d48956 | 2020-07-30 20:08:50 +0200 | [diff] [blame] | 1554 | call assert_fails('call prop_list(-1, {})', 'E16:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1555 | call assert_fails('call prop_remove([])', 'E474:') |
| 1556 | call assert_fails('call prop_remove({}, -2)', 'E16:') |
| 1557 | call assert_fails('call prop_remove({})', 'E968:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1558 | call assert_fails('call prop_type_add([], {})', 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1559 | call assert_fails("call prop_type_change('long', {'xyz' : 10})", 'E971:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1560 | call assert_fails("call prop_type_delete([])", 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1561 | call assert_fails("call prop_type_delete('xyz', [])", 'E715:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1562 | call assert_fails("call prop_type_get([])", 'E730:') |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1563 | call assert_fails("call prop_type_get('', [])", 'E474:') |
| 1564 | call assert_fails("call prop_type_list([])", 'E715:') |
Bram Moolenaar | 3dc3474 | 2021-03-02 13:36:47 +0100 | [diff] [blame] | 1565 | call assert_fails("call prop_type_add('yyy', 'not_a_dict')", 'E715:') |
| 1566 | call assert_fails("call prop_add(1, 5, {'type':'missing_type', 'length':1})", 'E971:') |
| 1567 | call assert_fails("call prop_add(1, 5, {'type': ''})", 'E971:') |
| 1568 | call assert_fails('call prop_add(1, 1, 0)', 'E715:') |
| 1569 | |
| 1570 | new |
| 1571 | call setline(1, ['first', 'second']) |
| 1572 | call prop_type_add('xxx', {}) |
| 1573 | |
| 1574 | call assert_fails("call prop_type_add('xxx', {})", 'E969:') |
| 1575 | call assert_fails("call prop_add(2, 0, {'type': 'xxx'})", 'E964:') |
| 1576 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':1})", 'E475:') |
| 1577 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_lnum':3})", 'E966:') |
| 1578 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'length':-1})", 'E475:') |
| 1579 | call assert_fails("call prop_add(2, 3, {'type': 'xxx', 'end_col':0})", 'E475:') |
| 1580 | call assert_fails("call prop_add(2, 3, {'length':1})", 'E965:') |
| 1581 | |
| 1582 | call prop_type_delete('xxx') |
| 1583 | bwipe! |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 1584 | endfunc |
| 1585 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1586 | func Test_prop_split_join() |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1587 | new |
| 1588 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1589 | call setline(1, 'just some text') |
| 1590 | call prop_add(1, 6, {'length': 4, 'type': 'test'}) |
| 1591 | |
| 1592 | " Split in middle of "some" |
| 1593 | execute "normal! 8|i\<CR>" |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1594 | call assert_equal( |
| 1595 | \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}], |
| 1596 | \ prop_list(1)) |
| 1597 | call assert_equal( |
| 1598 | \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}], |
| 1599 | \ prop_list(2)) |
Bram Moolenaar | 87be9be | 2020-05-30 15:32:02 +0200 | [diff] [blame] | 1600 | |
| 1601 | " Join the two lines back together |
| 1602 | normal! 1GJ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1603 | 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] | 1604 | |
| 1605 | bwipe! |
| 1606 | call prop_type_delete('test') |
| 1607 | endfunc |
| 1608 | |
Bram Moolenaar | c8f12c9 | 2020-09-15 20:34:10 +0200 | [diff] [blame] | 1609 | func Test_prop_increment_decrement() |
| 1610 | new |
| 1611 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1612 | call setline(1, 'its 998 times') |
| 1613 | call prop_add(1, 5, {'length': 3, 'type': 'test'}) |
| 1614 | |
| 1615 | exe "normal! 0f9\<C-A>" |
| 1616 | eval getline(1)->assert_equal('its 999 times') |
| 1617 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1618 | \ #{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] | 1619 | |
| 1620 | exe "normal! 0f9\<C-A>" |
| 1621 | eval getline(1)->assert_equal('its 1000 times') |
| 1622 | eval prop_list(1)->assert_equal([ |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1623 | \ #{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] | 1624 | |
| 1625 | bwipe! |
| 1626 | call prop_type_delete('test') |
| 1627 | endfunc |
| 1628 | |
Bram Moolenaar | 8b51b7f | 2020-09-15 21:34:18 +0200 | [diff] [blame] | 1629 | func Test_prop_block_insert() |
| 1630 | new |
| 1631 | call prop_type_add('test', {'highlight': 'ErrorMsg'}) |
| 1632 | call setline(1, ['one ', 'two ']) |
| 1633 | call prop_add(1, 1, {'length': 3, 'type': 'test'}) |
| 1634 | call prop_add(2, 1, {'length': 3, 'type': 'test'}) |
| 1635 | |
| 1636 | " insert "xx" in the first column of both lines |
| 1637 | exe "normal! gg0\<C-V>jIxx\<Esc>" |
| 1638 | eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1639 | 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] | 1640 | eval prop_list(1)->assert_equal(expected) |
| 1641 | eval prop_list(2)->assert_equal(expected) |
| 1642 | |
| 1643 | " insert "yy" inside the text props to make them longer |
| 1644 | exe "normal! gg03l\<C-V>jIyy\<Esc>" |
| 1645 | eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo ']) |
| 1646 | let expected[0].length = 5 |
| 1647 | eval prop_list(1)->assert_equal(expected) |
| 1648 | eval prop_list(2)->assert_equal(expected) |
| 1649 | |
| 1650 | " insert "zz" after the text props, text props don't change |
| 1651 | exe "normal! gg07l\<C-V>jIzz\<Esc>" |
| 1652 | eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz ']) |
| 1653 | eval prop_list(1)->assert_equal(expected) |
| 1654 | eval prop_list(2)->assert_equal(expected) |
| 1655 | |
| 1656 | bwipe! |
| 1657 | call prop_type_delete('test') |
| 1658 | endfunc |
| 1659 | |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 1660 | " this was causing an ml_get error because w_botline was wrong |
| 1661 | func Test_prop_one_line_window() |
| 1662 | enew |
| 1663 | call range(2)->setline(1) |
| 1664 | call prop_type_add('testprop', {}) |
| 1665 | call prop_add(1, 1, {'type': 'testprop'}) |
| 1666 | call popup_create('popup', {'textprop': 'testprop'}) |
| 1667 | $ |
| 1668 | new |
| 1669 | wincmd _ |
| 1670 | call feedkeys("\r", 'xt') |
| 1671 | redraw |
| 1672 | |
| 1673 | call popup_clear() |
| 1674 | call prop_type_delete('testprop') |
| 1675 | close |
| 1676 | bwipe! |
| 1677 | endfunc |
| 1678 | |
Bram Moolenaar | f05a1e5 | 2022-08-02 11:48:53 +0100 | [diff] [blame] | 1679 | def Test_prop_column_zero_error() |
| 1680 | prop_type_add('proptype', {highlight: 'Search'}) |
| 1681 | var caught = false |
| 1682 | try |
| 1683 | popup_create([{ |
| 1684 | text: 'a', |
| 1685 | props: [{col: 0, length: 1, type: 'type'}], |
| 1686 | }], {}) |
| 1687 | catch /E964:/ |
| 1688 | caught = true |
| 1689 | endtry |
| 1690 | assert_true(caught) |
| 1691 | |
| 1692 | popup_clear() |
| 1693 | prop_type_delete('proptype') |
| 1694 | enddef |
| 1695 | |
Bram Moolenaar | 840f91f | 2021-05-26 22:32:10 +0200 | [diff] [blame] | 1696 | " This was calling ml_append_int() and copy a text property from a previous |
| 1697 | " line at the wrong moment. Exact text length matters. |
| 1698 | def Test_prop_splits_data_block() |
| 1699 | new |
| 1700 | var lines: list<string> = [repeat('x', 35)]->repeat(41) |
| 1701 | + [repeat('!', 35)] |
| 1702 | + [repeat('x', 35)]->repeat(56) |
| 1703 | lines->setline(1) |
| 1704 | prop_type_add('someprop', {highlight: 'ErrorMsg'}) |
| 1705 | prop_add(1, 27, {end_lnum: 1, end_col: 70, type: 'someprop'}) |
| 1706 | prop_remove({type: 'someprop'}, 1) |
| 1707 | prop_add(35, 22, {end_lnum: 43, end_col: 43, type: 'someprop'}) |
| 1708 | prop_remove({type: 'someprop'}, 35, 43) |
| 1709 | assert_equal([], prop_list(42)) |
| 1710 | |
| 1711 | bwipe! |
| 1712 | prop_type_delete('someprop') |
| 1713 | enddef |
| 1714 | |
Bram Moolenaar | 4cd5c52 | 2021-06-27 13:04:00 +0200 | [diff] [blame] | 1715 | " This was calling ml_delete_int() and try to change text properties. |
| 1716 | def Test_prop_add_delete_line() |
| 1717 | new |
| 1718 | var a = 10 |
| 1719 | var b = 20 |
| 1720 | repeat([''], a)->append('$') |
| 1721 | prop_type_add('Test', {highlight: 'ErrorMsg'}) |
| 1722 | for lnum in range(1, a) |
| 1723 | for col in range(1, b) |
| 1724 | prop_add(1, 1, {end_lnum: lnum, end_col: col, type: 'Test'}) |
| 1725 | endfor |
| 1726 | endfor |
| 1727 | |
| 1728 | # check deleting lines is OK |
| 1729 | :5del |
| 1730 | :1del |
| 1731 | :$del |
| 1732 | |
| 1733 | prop_type_delete('Test') |
| 1734 | bwipe! |
| 1735 | enddef |
| 1736 | |
Paul Ollis | 1bdc60e | 2022-05-15 22:24:55 +0100 | [diff] [blame] | 1737 | " This test is to detect a regression related to #10430. It is not an attempt |
| 1738 | " fully cover deleting lines in the presence of multi-line properties. |
| 1739 | def Test_delete_line_within_multiline_prop() |
| 1740 | new |
| 1741 | setline(1, '# Top.') |
| 1742 | append(1, ['some_text = """', 'A string.', '"""', '# Bottom.']) |
| 1743 | prop_type_add('Identifier', {'highlight': 'ModeMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1744 | prop_type_add('String', {'highlight': 'MoreMsg', 'priority': 0, 'combine': 0, 'start_incl': 0, 'end_incl': 0}) |
| 1745 | prop_add(2, 1, {'type': 'Identifier', 'end_lnum': 2, 'end_col': 9}) |
| 1746 | prop_add(2, 13, {'type': 'String', 'end_lnum': 4, 'end_col': 4}) |
| 1747 | |
| 1748 | # The property for line 3 should extend into the previous and next lines. |
| 1749 | var props = prop_list(3) |
| 1750 | var prop = props[0] |
| 1751 | assert_equal(1, len(props)) |
| 1752 | assert_equal(0, prop['start']) |
| 1753 | assert_equal(0, prop['end']) |
| 1754 | |
| 1755 | # This deletion should run without raising an exception. |
| 1756 | try |
| 1757 | :2 del |
| 1758 | catch |
| 1759 | assert_report('Line delete should have workd, but it raised an error.') |
| 1760 | endtry |
| 1761 | |
| 1762 | # The property for line 2 (was 3) should no longer extend into the previous |
| 1763 | # line. |
| 1764 | props = prop_list(2) |
| 1765 | prop = props[0] |
| 1766 | assert_equal(1, len(props)) |
| 1767 | assert_equal(1, prop['start'], 'Property was not changed to start within the line.') |
| 1768 | |
| 1769 | # This deletion should run without raising an exception. |
| 1770 | try |
| 1771 | :3 del |
| 1772 | catch |
| 1773 | assert_report('Line delete should have workd, but it raised an error.') |
| 1774 | endtry |
| 1775 | |
| 1776 | # The property for line 2 (originally 3) should no longer extend into the next |
| 1777 | # line. |
| 1778 | props = prop_list(2) |
| 1779 | prop = props[0] |
| 1780 | assert_equal(1, len(props)) |
| 1781 | assert_equal(1, prop['end'], 'Property was not changed to end within the line.') |
| 1782 | |
| 1783 | prop_type_delete('Identifier') |
| 1784 | prop_type_delete('String') |
| 1785 | bwip! |
| 1786 | enddef |
| 1787 | |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1788 | func Test_prop_in_linebreak() |
| 1789 | CheckRunVimInTerminal |
| 1790 | |
| 1791 | let lines =<< trim END |
| 1792 | set breakindent linebreak breakat+=] |
| 1793 | call printf('%s]%s', repeat('x', 50), repeat('x', 70))->setline(1) |
| 1794 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 1795 | call prop_add(1, 51, #{length: 1, type: 'test'}) |
| 1796 | END |
| 1797 | call writefile(lines, 'XscriptPropLinebreak') |
| 1798 | let buf = RunVimInTerminal('-S XscriptPropLinebreak', #{rows: 10}) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1799 | call VerifyScreenDump(buf, 'Test_prop_linebreak', {}) |
| 1800 | |
| 1801 | call StopVimInTerminal(buf) |
| 1802 | call delete('XscriptPropLinebreak') |
| 1803 | endfunc |
| 1804 | |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 1805 | func Test_prop_after_tab() |
| 1806 | CheckRunVimInTerminal |
| 1807 | |
| 1808 | let lines =<< trim END |
| 1809 | set breakindent linebreak breakat+=] |
| 1810 | call setline(1, "\t[xxx]") |
| 1811 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 1812 | call prop_add(1, 2, #{length: 1, type: 'test'}) |
| 1813 | END |
| 1814 | call writefile(lines, 'XscriptPropAfterTab') |
| 1815 | let buf = RunVimInTerminal('-S XscriptPropAfterTab', #{rows: 10}) |
Bram Moolenaar | 42eba04 | 2021-11-30 20:22:49 +0000 | [diff] [blame] | 1816 | call VerifyScreenDump(buf, 'Test_prop_after_tab', {}) |
| 1817 | |
| 1818 | call StopVimInTerminal(buf) |
| 1819 | call delete('XscriptPropAfterTab') |
| 1820 | endfunc |
| 1821 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 1822 | func Test_prop_after_linebreak() |
| 1823 | CheckRunVimInTerminal |
| 1824 | |
| 1825 | let lines =<< trim END |
| 1826 | set linebreak wrap |
| 1827 | call printf('%s+(%s)', 'x'->repeat(&columns / 2), 'x'->repeat(&columns / 2))->setline(1) |
| 1828 | call prop_type_add('test', #{highlight: 'ErrorMsg'}) |
| 1829 | call prop_add(1, (&columns / 2) + 2, #{length: 1, type: 'test'}) |
| 1830 | END |
| 1831 | call writefile(lines, 'XscriptPropAfterLinebreak') |
| 1832 | let buf = RunVimInTerminal('-S XscriptPropAfterLinebreak', #{rows: 10}) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 1833 | call VerifyScreenDump(buf, 'Test_prop_after_linebreak', {}) |
| 1834 | |
| 1835 | call StopVimInTerminal(buf) |
| 1836 | call delete('XscriptPropAfterLinebreak') |
| 1837 | endfunc |
| 1838 | |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1839 | " Buffer number of 0 should be ignored, as if the parameter wasn't passed. |
| 1840 | def Test_prop_bufnr_zero() |
| 1841 | new |
| 1842 | try |
| 1843 | var bufnr = bufnr('') |
| 1844 | setline(1, 'hello') |
| 1845 | prop_type_add('bufnr-global', {highlight: 'ErrorMsg'}) |
| 1846 | prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr}) |
| 1847 | |
| 1848 | prop_add(1, 1, {type: 'bufnr-global', length: 1}) |
| 1849 | prop_add(1, 2, {type: 'bufnr-buffer', length: 1}) |
| 1850 | |
| 1851 | var list = prop_list(1) |
| 1852 | assert_equal([ |
| 1853 | {id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1}, |
| 1854 | {id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1}, |
| 1855 | ], list) |
| 1856 | |
| 1857 | assert_equal( |
| 1858 | {highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1}, |
| 1859 | prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr})) |
| 1860 | |
| 1861 | assert_equal( |
| 1862 | {highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1}, |
| 1863 | prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr})) |
| 1864 | finally |
| 1865 | bwipe! |
| 1866 | prop_type_delete('bufnr-global') |
| 1867 | endtry |
| 1868 | enddef |
| 1869 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 1870 | " Tests for the prop_list() function |
| 1871 | func Test_prop_list() |
| 1872 | let lines =<< trim END |
| 1873 | new |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 1874 | call g:AddPropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 1875 | call setline(1, repeat([repeat('a', 60)], 10)) |
| 1876 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 1877 | call prop_add(1, 5, {'type': 'two', 'id': 10, 'end_col': 7}) |
| 1878 | call prop_add(3, 12, {'type': 'one', 'id': 20, 'end_col': 14}) |
| 1879 | call prop_add(3, 13, {'type': 'two', 'id': 10, 'end_col': 15}) |
| 1880 | call prop_add(5, 20, {'type': 'one', 'id': 10, 'end_col': 22}) |
| 1881 | call prop_add(5, 21, {'type': 'two', 'id': 20, 'end_col': 23}) |
| 1882 | call assert_equal([ |
| 1883 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1884 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1885 | \ {'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 1886 | \ 'type': 'two', 'length': 2, 'start': 1}], prop_list(1)) |
| 1887 | #" text properties between a few lines |
| 1888 | call assert_equal([ |
| 1889 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 1890 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1891 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 1892 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 1893 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 1894 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1895 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 1896 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 1897 | \ prop_list(2, {'end_lnum': 5})) |
| 1898 | #" text properties across all the lines |
| 1899 | call assert_equal([ |
| 1900 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1901 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1902 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 1903 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1904 | \ {'lnum': 5, 'id': 10, 'col': 20, 'type_bufnr': 0, 'end': 1, |
| 1905 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 1906 | \ prop_list(1, {'types': ['one'], 'end_lnum': -1})) |
| 1907 | #" text properties with the specified identifier |
| 1908 | call assert_equal([ |
| 1909 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 1910 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1911 | \ {'lnum': 5, 'id': 20, 'col': 21, 'type_bufnr': 0, 'end': 1, |
| 1912 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 1913 | \ prop_list(1, {'ids': [20], 'end_lnum': 10})) |
| 1914 | #" text properties of the specified type and id |
| 1915 | call assert_equal([ |
| 1916 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 1917 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 1918 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 1919 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 1920 | \ prop_list(1, {'types': ['two'], 'ids': [10], 'end_lnum': 20})) |
| 1921 | call assert_equal([], prop_list(1, {'ids': [40, 50], 'end_lnum': 10})) |
| 1922 | call assert_equal([], prop_list(6, {'end_lnum': 10})) |
| 1923 | call assert_equal([], prop_list(2, {'end_lnum': 2})) |
| 1924 | #" error cases |
| 1925 | call assert_fails("echo prop_list(1, {'end_lnum': -20})", 'E16:') |
| 1926 | call assert_fails("echo prop_list(4, {'end_lnum': 2})", 'E16:') |
| 1927 | call assert_fails("echo prop_list(1, {'end_lnum': '$'})", 'E889:') |
| 1928 | call assert_fails("echo prop_list(1, {'types': ['blue'], 'end_lnum': 10})", |
| 1929 | \ 'E971:') |
| 1930 | call assert_fails("echo prop_list(1, {'types': ['one', 'blue'], |
| 1931 | \ 'end_lnum': 10})", 'E971:') |
| 1932 | call assert_fails("echo prop_list(1, {'types': ['one', 10], |
| 1933 | \ 'end_lnum': 10})", 'E928:') |
| 1934 | call assert_fails("echo prop_list(1, {'types': ['']})", 'E971:') |
| 1935 | call assert_equal([], prop_list(2, {'types': []})) |
| 1936 | call assert_equal([], prop_list(2, {'types': test_null_list()})) |
| 1937 | call assert_fails("call prop_list(1, {'types': {}})", 'E714:') |
| 1938 | call assert_fails("call prop_list(1, {'types': 'one'})", 'E714:') |
| 1939 | call assert_equal([], prop_list(2, {'types': ['one'], |
| 1940 | \ 'ids': test_null_list()})) |
| 1941 | call assert_equal([], prop_list(2, {'types': ['one'], 'ids': []})) |
| 1942 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': {}})", |
| 1943 | \ 'E714:') |
| 1944 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': 10})", |
| 1945 | \ 'E714:') |
| 1946 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [[]]})", |
| 1947 | \ 'E745:') |
| 1948 | call assert_fails("call prop_list(1, {'types': ['one'], 'ids': [10, []]})", |
| 1949 | \ 'E745:') |
Martin Tournoij | e2390c7 | 2021-07-28 13:30:16 +0200 | [diff] [blame] | 1950 | |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 1951 | #" get text properties from a non-current buffer |
| 1952 | wincmd w |
| 1953 | call assert_equal([ |
| 1954 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1955 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1956 | \ {'lnum': 1, 'id': 10, 'col': 5, 'type_bufnr': 0, 'end': 1, |
| 1957 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 1958 | \ {'lnum': 3, 'id': 20, 'col': 12, 'type_bufnr': 0, 'end': 1, |
| 1959 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 1960 | \ {'lnum': 3, 'id': 10, 'col': 13, 'type_bufnr': 0, 'end': 1, |
| 1961 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 1962 | \ prop_list(1, {'bufnr': winbufnr(1), 'end_lnum': 4})) |
| 1963 | wincmd w |
| 1964 | |
| 1965 | #" get text properties after clearing all the properties |
| 1966 | call prop_clear(1, line('$')) |
| 1967 | call assert_equal([], prop_list(1, {'end_lnum': 10})) |
| 1968 | |
| 1969 | call prop_add(2, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 1970 | call prop_add(2, 4, {'type': 'two', 'id': 10, 'end_col': 6}) |
| 1971 | call prop_add(2, 4, {'type': 'three', 'id': 15, 'end_col': 6}) |
| 1972 | #" get text properties with a list of types |
| 1973 | call assert_equal([ |
| 1974 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1975 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 1976 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1977 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 1978 | \ prop_list(2, {'types': ['one', 'two']})) |
| 1979 | call assert_equal([ |
| 1980 | \ {'id': 15, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1981 | \ 'type': 'three', 'length': 2, 'start': 1}, |
| 1982 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1983 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 1984 | \ prop_list(2, {'types': ['one', 'three']})) |
| 1985 | #" get text properties with a list of identifiers |
| 1986 | call assert_equal([ |
| 1987 | \ {'id': 10, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1988 | \ 'type': 'two', 'length': 2, 'start': 1}, |
| 1989 | \ {'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 1990 | \ 'type': 'one', 'length': 2, 'start': 1}], |
| 1991 | \ prop_list(2, {'ids': [5, 10, 20]})) |
| 1992 | call prop_clear(1, line('$')) |
| 1993 | call assert_equal([], prop_list(2, {'types': ['one', 'two']})) |
| 1994 | call assert_equal([], prop_list(2, {'ids': [5, 10, 20]})) |
| 1995 | |
| 1996 | #" get text properties from a hidden buffer |
| 1997 | edit! Xaaa |
| 1998 | call setline(1, repeat([repeat('b', 60)], 10)) |
| 1999 | call prop_add(1, 4, {'type': 'one', 'id': 5, 'end_col': 6}) |
| 2000 | call prop_add(4, 8, {'type': 'two', 'id': 10, 'end_col': 10}) |
| 2001 | VAR bnr = bufnr() |
| 2002 | hide edit Xbbb |
| 2003 | call assert_equal([ |
| 2004 | \ {'lnum': 1, 'id': 5, 'col': 4, 'type_bufnr': 0, 'end': 1, |
| 2005 | \ 'type': 'one', 'length': 2, 'start': 1}, |
| 2006 | \ {'lnum': 4, 'id': 10, 'col': 8, 'type_bufnr': 0, 'end': 1, |
| 2007 | \ 'type': 'two', 'length': 2, 'start': 1}], |
| 2008 | \ prop_list(1, {'bufnr': bnr, |
| 2009 | \ 'types': ['one', 'two'], 'ids': [5, 10], 'end_lnum': -1})) |
| 2010 | #" get text properties from an unloaded buffer |
| 2011 | bunload! Xaaa |
| 2012 | call assert_equal([], prop_list(1, {'bufnr': bnr, 'end_lnum': -1})) |
| 2013 | |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2014 | call g:DeletePropTypes() |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2015 | :%bw! |
| 2016 | END |
Bram Moolenaar | 62aec93 | 2022-01-29 21:45:34 +0000 | [diff] [blame] | 2017 | call v9.CheckLegacyAndVim9Success(lines) |
Yegappan Lakshmanan | e021662 | 2021-11-23 11:46:32 +0000 | [diff] [blame] | 2018 | endfunc |
Bram Moolenaar | 23999d7 | 2020-12-23 14:36:00 +0100 | [diff] [blame] | 2019 | |
LemonBoy | 9bd3ce2 | 2022-04-18 21:54:02 +0100 | [diff] [blame] | 2020 | func Test_prop_find_prev_on_same_line() |
| 2021 | new |
| 2022 | |
| 2023 | call setline(1, 'the quikc bronw fox jumsp over the layz dog') |
| 2024 | call prop_type_add('misspell', #{highlight: 'ErrorMsg'}) |
| 2025 | for col in [8, 14, 24, 38] |
| 2026 | call prop_add(1, col, #{type: 'misspell', length: 2}) |
| 2027 | endfor |
| 2028 | |
| 2029 | call cursor(1,18) |
| 2030 | let expected = [ |
| 2031 | \ #{lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1}, |
| 2032 | \ #{lnum: 1, id: 0, col: 24, end: 1, type: 'misspell', type_bufnr: 0, length: 2, start: 1} |
| 2033 | \ ] |
| 2034 | |
| 2035 | let result = prop_find(#{type: 'misspell'}, 'b') |
| 2036 | call assert_equal(expected[0], result) |
| 2037 | let result = prop_find(#{type: 'misspell'}, 'f') |
| 2038 | call assert_equal(expected[1], result) |
| 2039 | |
| 2040 | call prop_type_delete('misspell') |
| 2041 | bwipe! |
| 2042 | endfunc |
| 2043 | |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2044 | func Test_prop_spell() |
| 2045 | new |
| 2046 | set spell |
| 2047 | call AddPropTypes() |
| 2048 | |
| 2049 | call setline(1, ["helo world", "helo helo helo"]) |
| 2050 | call prop_add(1, 1, #{type: 'one', length: 4}) |
| 2051 | call prop_add(1, 6, #{type: 'two', length: 5}) |
| 2052 | call prop_add(2, 1, #{type: 'three', length: 4}) |
| 2053 | call prop_add(2, 6, #{type: 'three', length: 4}) |
| 2054 | call prop_add(2, 11, #{type: 'three', length: 4}) |
| 2055 | |
| 2056 | " The first prop over 'helo' increases its length after the word is corrected |
| 2057 | " to 'Hello', the second one is shifted to the right. |
| 2058 | let expected = [ |
| 2059 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2060 | \ 'length': 5, 'start': 1}, |
| 2061 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2062 | \ 'length': 5, 'start': 1} |
| 2063 | \ ] |
| 2064 | call feedkeys("z=1\<CR>", 'xt') |
| 2065 | |
| 2066 | call assert_equal('Hello world', getline(1)) |
| 2067 | call assert_equal(expected, prop_list(1)) |
| 2068 | |
| 2069 | " Repeat the replacement done by z= |
| 2070 | spellrepall |
| 2071 | |
| 2072 | let expected = [ |
| 2073 | \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2074 | \ 'length': 5, 'start': 1}, |
| 2075 | \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2076 | \ 'length': 5, 'start': 1}, |
| 2077 | \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three', |
| 2078 | \ 'length': 5, 'start': 1} |
| 2079 | \ ] |
| 2080 | call assert_equal('Hello Hello Hello', getline(2)) |
| 2081 | call assert_equal(expected, prop_list(2)) |
| 2082 | |
| 2083 | call DeletePropTypes() |
| 2084 | set spell& |
| 2085 | bwipe! |
| 2086 | endfunc |
| 2087 | |
LemonBoy | 4b93674 | 2022-05-13 21:56:28 +0100 | [diff] [blame] | 2088 | func Test_prop_shift_block() |
| 2089 | new |
| 2090 | call AddPropTypes() |
| 2091 | |
| 2092 | call setline(1, ['some highlighted text']->repeat(2)) |
| 2093 | call prop_add(1, 10, #{type: 'one', length: 11}) |
| 2094 | call prop_add(2, 10, #{type: 'two', length: 11}) |
| 2095 | |
| 2096 | call cursor(1, 1) |
| 2097 | call feedkeys("5l\<c-v>>", 'nxt') |
| 2098 | call cursor(2, 1) |
| 2099 | call feedkeys("5l\<c-v><", 'nxt') |
| 2100 | |
| 2101 | let expected = [ |
| 2102 | \ {'lnum': 1, 'id': 0, 'col': 8, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2103 | \ 'length': 11, 'start' : 1}, |
| 2104 | \ {'lnum': 2, 'id': 0, 'col': 6, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2105 | \ 'length': 11, 'start' : 1} |
| 2106 | \ ] |
| 2107 | call assert_equal(expected, prop_list(1, #{end_lnum: 2})) |
| 2108 | |
| 2109 | call DeletePropTypes() |
| 2110 | bwipe! |
| 2111 | endfunc |
LemonBoy | b7a7012 | 2022-05-13 12:41:50 +0100 | [diff] [blame] | 2112 | |
LemonBoy | 698cb4c | 2022-05-14 18:10:15 +0100 | [diff] [blame] | 2113 | func Test_prop_insert_multiline() |
| 2114 | new |
| 2115 | call AddPropTypes() |
| 2116 | |
| 2117 | call setline(1, ['foobar', 'barbaz']) |
| 2118 | call prop_add(1, 4, #{end_lnum: 2, end_col: 4, type: 'one'}) |
| 2119 | |
| 2120 | call feedkeys("1Goquxqux\<Esc>", 'nxt') |
| 2121 | call feedkeys("2GOquxqux\<Esc>", 'nxt') |
| 2122 | |
| 2123 | let lines =<< trim END |
| 2124 | foobar |
| 2125 | quxqux |
| 2126 | quxqux |
| 2127 | barbaz |
| 2128 | END |
| 2129 | call assert_equal(lines, getline(1, '$')) |
| 2130 | let expected = [ |
| 2131 | \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2132 | \ 'length': 4 ,'start': 1}, |
| 2133 | \ {'lnum': 2, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2134 | \ 'length': 7, 'start': 0}, |
| 2135 | \ {'lnum': 3, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 0, 'type': 'one', |
| 2136 | \ 'length': 7, 'start': 0}, |
| 2137 | \ {'lnum': 4, 'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2138 | \ 'length': 3, 'start': 0} |
| 2139 | \ ] |
| 2140 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2141 | |
| 2142 | call DeletePropTypes() |
| 2143 | bwipe! |
| 2144 | endfunc |
| 2145 | |
LemonBoy | b559b30 | 2022-05-15 13:08:02 +0100 | [diff] [blame] | 2146 | func Test_prop_blockwise_change() |
| 2147 | new |
| 2148 | call AddPropTypes() |
| 2149 | |
| 2150 | call setline(1, ['foooooo', 'bar', 'baaaaz']) |
| 2151 | call prop_add(1, 1, #{end_col: 3, type: 'one'}) |
| 2152 | call prop_add(2, 1, #{end_col: 3, type: 'two'}) |
| 2153 | call prop_add(3, 1, #{end_col: 3, type: 'three'}) |
| 2154 | |
| 2155 | " Replace the first two columns with '123', since 'start_incl' is false the |
| 2156 | " prop is not extended. |
| 2157 | call feedkeys("gg\<c-v>2jc123\<Esc>", 'nxt') |
| 2158 | |
| 2159 | let lines =<< trim END |
| 2160 | 123oooooo |
| 2161 | 123ar |
| 2162 | 123aaaaz |
| 2163 | END |
| 2164 | call assert_equal(lines, getline(1, '$')) |
| 2165 | let expected = [ |
| 2166 | \ {'lnum': 1, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'one', |
| 2167 | \ 'length': 1, 'start': 1}, |
| 2168 | \ {'lnum': 2, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1, 'type': 'two', |
| 2169 | \ 'length': 1, 'start': 1}, |
| 2170 | \ {'lnum': 3, 'id': 0, 'col': 4, 'type_bufnr': 0, 'end': 1 , |
| 2171 | \ 'type': 'three', 'length': 1, 'start': 1} |
| 2172 | \ ] |
| 2173 | call assert_equal(expected, prop_list(1, #{end_lnum: 10})) |
| 2174 | |
| 2175 | call DeletePropTypes() |
| 2176 | bwipe! |
| 2177 | endfunc |
| 2178 | |
Paul Ollis | 4c3d21a | 2022-05-24 21:26:37 +0100 | [diff] [blame] | 2179 | func Do_test_props_do_not_affect_byte_offsets(ff, increment) |
| 2180 | new |
| 2181 | let lcount = 410 |
| 2182 | |
| 2183 | " File format affects byte-offset calculations, so make sure it is known. |
| 2184 | exec 'setlocal fileformat=' . a:ff |
| 2185 | |
| 2186 | " Fill the buffer with varying length lines. We need a suitably large number |
| 2187 | " to force Vim code through paths wehere previous error have occurred. This |
| 2188 | " is more 'art' than 'science'. |
| 2189 | let text = 'a' |
| 2190 | call setline(1, text) |
| 2191 | let offsets = [1] |
| 2192 | for idx in range(lcount) |
| 2193 | call add(offsets, offsets[idx] + len(text) + a:increment) |
| 2194 | if (idx % 6) == 0 |
| 2195 | let text = text . 'a' |
| 2196 | endif |
| 2197 | call append(line('$'), text) |
| 2198 | endfor |
| 2199 | |
| 2200 | " Set a property that spans a few lines to cause Vim's internal buffer code |
| 2201 | " to perform a reasonable amount of rearrangement. |
| 2202 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2203 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 6, 'end_col': 2}) |
| 2204 | |
| 2205 | for idx in range(lcount) |
| 2206 | let boff = line2byte(idx + 1) |
| 2207 | call assert_equal(offsets[idx], boff, 'Bad byte offset at line ' . (idx + 1)) |
| 2208 | endfor |
| 2209 | |
| 2210 | call prop_type_delete('one') |
| 2211 | bwipe! |
| 2212 | endfunc |
| 2213 | |
| 2214 | func Test_props_do_not_affect_byte_offsets() |
| 2215 | call Do_test_props_do_not_affect_byte_offsets('unix', 1) |
| 2216 | endfunc |
| 2217 | |
| 2218 | func Test_props_do_not_affect_byte_offsets_dos() |
| 2219 | call Do_test_props_do_not_affect_byte_offsets('dos', 2) |
| 2220 | endfunc |
| 2221 | |
| 2222 | func Test_props_do_not_affect_byte_offsets_editline() |
| 2223 | new |
| 2224 | let lcount = 410 |
| 2225 | |
| 2226 | " File format affects byte-offset calculations, so make sure it is known. |
| 2227 | setlocal fileformat=unix |
| 2228 | |
| 2229 | " Fill the buffer with varying length lines. We need a suitably large number |
| 2230 | " to force Vim code through paths wehere previous error have occurred. This |
| 2231 | " is more 'art' than 'science'. |
| 2232 | let text = 'aa' |
| 2233 | call setline(1, text) |
| 2234 | let offsets = [1] |
| 2235 | for idx in range(lcount) |
| 2236 | call add(offsets, offsets[idx] + len(text) + 1) |
| 2237 | if (idx % 6) == 0 |
| 2238 | let text = text . 'a' |
| 2239 | endif |
| 2240 | call append(line('$'), text) |
| 2241 | endfor |
| 2242 | |
| 2243 | " Set a property that just covers the first line. When this test was |
| 2244 | " developed, this did not trigger a byte-offset error. |
| 2245 | call prop_type_add('one', {'highlight': 'ErrorMsg'}) |
| 2246 | call prop_add(1, 1, {'type': 'one', 'end_lnum': 1, 'end_col': 3}) |
| 2247 | |
| 2248 | for idx in range(lcount) |
| 2249 | let boff = line2byte(idx + 1) |
| 2250 | call assert_equal(offsets[idx], boff, |
| 2251 | \ 'Confounding bad byte offset at line ' . (idx + 1)) |
| 2252 | endfor |
| 2253 | |
| 2254 | " Insert text in the middle of the first line, keeping the property |
| 2255 | " unchanged. |
| 2256 | :1 |
| 2257 | normal aHello |
| 2258 | for idx in range(1, lcount) |
| 2259 | let offsets[idx] = offsets[idx] + 5 |
| 2260 | endfor |
| 2261 | |
| 2262 | for idx in range(lcount) |
| 2263 | let boff = line2byte(idx + 1) |
| 2264 | call assert_equal(offsets[idx], boff, |
| 2265 | \ 'Bad byte offset at line ' . (idx + 1)) |
| 2266 | endfor |
| 2267 | |
| 2268 | call prop_type_delete('one') |
| 2269 | bwipe! |
| 2270 | endfunc |
| 2271 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2272 | func Test_prop_inserts_text() |
| 2273 | CheckRunVimInTerminal |
| 2274 | |
| 2275 | " Just a basic check for now |
| 2276 | let lines =<< trim END |
| 2277 | call setline(1, 'insert some text here and other text there and some more text after wrapping') |
| 2278 | call prop_type_add('someprop', #{highlight: 'ErrorMsg'}) |
| 2279 | call prop_type_add('otherprop', #{highlight: 'Search'}) |
| 2280 | call prop_type_add('moreprop', #{highlight: 'DiffAdd'}) |
| 2281 | call prop_add(1, 18, #{type: 'someprop', text: 'SOME '}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 2282 | call prop_add(1, 38, #{type: 'otherprop', text: "OTHER\t"}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2283 | call prop_add(1, 69, #{type: 'moreprop', text: 'MORE '}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2284 | normal $ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2285 | |
| 2286 | call setline(2, 'prepost') |
| 2287 | call prop_type_add('multibyte', #{highlight: 'Visual'}) |
| 2288 | call prop_add(2, 4, #{type: 'multibyte', text: 'söme和平téxt'}) |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2289 | |
| 2290 | call setline(3, '') |
| 2291 | call prop_add(3, 1, #{type: 'someprop', text: 'empty line'}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2292 | END |
| 2293 | call writefile(lines, 'XscriptPropsWithText') |
| 2294 | let buf = RunVimInTerminal('-S XscriptPropsWithText', #{rows: 6, cols: 60}) |
Bram Moolenaar | 711483c | 2022-07-30 21:33:46 +0100 | [diff] [blame] | 2295 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_1', {}) |
| 2296 | |
| 2297 | call term_sendkeys(buf, ":set signcolumn=yes\<CR>") |
| 2298 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_2', {}) |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2299 | |
Bram Moolenaar | afd2aa7 | 2022-08-05 13:07:23 +0100 | [diff] [blame] | 2300 | call term_sendkeys(buf, "2G$") |
| 2301 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_3', {}) |
| 2302 | |
| 2303 | call term_sendkeys(buf, "3G") |
| 2304 | call VerifyScreenDump(buf, 'Test_prop_inserts_text_4', {}) |
| 2305 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2306 | call StopVimInTerminal(buf) |
| 2307 | call delete('XscriptPropsWithText') |
| 2308 | endfunc |
| 2309 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2310 | func Test_props_with_text_after() |
| 2311 | CheckRunVimInTerminal |
| 2312 | |
| 2313 | let lines =<< trim END |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2314 | set showbreak=+++ |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2315 | call setline(1, 'some text here and other text there') |
| 2316 | call prop_type_add('rightprop', #{highlight: 'ErrorMsg'}) |
| 2317 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2318 | call prop_type_add('belowprop', #{highlight: 'DiffAdd'}) |
| 2319 | call prop_add(1, 0, #{type: 'rightprop', text: ' RIGHT ', text_align: 'right'}) |
Bram Moolenaar | 783ef72 | 2022-08-01 16:11:06 +0100 | [diff] [blame] | 2320 | 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] | 2321 | call prop_add(1, 0, #{type: 'belowprop', text: ' BELOW ', text_align: 'below'}) |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 2322 | 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] | 2323 | |
| 2324 | call setline(2, 'Last line.') |
| 2325 | call prop_add(2, 0, #{type: 'afterprop', text: ' After Last ', text_align: 'after'}) |
| 2326 | normal G$ |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2327 | |
| 2328 | call setline(3, 'right here') |
| 2329 | 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] | 2330 | END |
| 2331 | call writefile(lines, 'XscriptPropsWithTextAfter') |
Bram Moolenaar | 50e75fe | 2022-08-05 20:25:50 +0100 | [diff] [blame] | 2332 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfter', #{rows: 8, cols: 60}) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2333 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_1', {}) |
| 2334 | |
| 2335 | call StopVimInTerminal(buf) |
| 2336 | call delete('XscriptPropsWithTextAfter') |
| 2337 | endfunc |
| 2338 | |
Bram Moolenaar | cba6952 | 2022-08-06 21:03:53 +0100 | [diff] [blame] | 2339 | func Test_props_with_text_after_below_trunc() |
| 2340 | CheckRunVimInTerminal |
| 2341 | |
| 2342 | let lines =<< trim END |
| 2343 | vim9script |
| 2344 | edit foobar |
| 2345 | set showbreak=+++ |
| 2346 | setline(1, ['onasdf asdf asdf asdf asd fas df', 'two']) |
| 2347 | prop_type_add('test', {highlight: 'Special'}) |
| 2348 | prop_add(1, 0, { |
| 2349 | type: 'test', |
| 2350 | text: 'the quick brown fox jumps over the lazy dog', |
| 2351 | text_align: 'after' |
| 2352 | }) |
| 2353 | prop_add(1, 0, { |
| 2354 | type: 'test', |
| 2355 | text: 'the quick brown fox jumps over the lazy dog', |
| 2356 | text_align: 'below' |
| 2357 | }) |
| 2358 | normal G$ |
| 2359 | END |
| 2360 | call writefile(lines, 'XscriptPropsAfterTrunc') |
| 2361 | let buf = RunVimInTerminal('-S XscriptPropsAfterTrunc', #{rows: 8, cols: 60}) |
| 2362 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_below_trunc_1', {}) |
| 2363 | |
| 2364 | call StopVimInTerminal(buf) |
| 2365 | call delete('XscriptPropsAfterTrunc') |
| 2366 | endfunc |
| 2367 | |
Bram Moolenaar | e175dc6 | 2022-08-01 22:18:50 +0100 | [diff] [blame] | 2368 | func Test_props_with_text_after_joined() |
| 2369 | CheckRunVimInTerminal |
| 2370 | |
| 2371 | let lines =<< trim END |
| 2372 | call setline(1, ['one', 'two', 'three', 'four']) |
| 2373 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2374 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE', text_align: 'after'}) |
| 2375 | call prop_add(4, 0, #{type: 'afterprop', text: ' FOUR', text_align: 'after'}) |
| 2376 | normal ggJ |
| 2377 | normal GkJ |
| 2378 | |
| 2379 | call setline(3, ['a', 'b', 'c', 'd', 'e', 'f']) |
| 2380 | call prop_add(3, 0, #{type: 'afterprop', text: ' AAA', text_align: 'after'}) |
| 2381 | call prop_add(5, 0, #{type: 'afterprop', text: ' CCC', text_align: 'after'}) |
| 2382 | call prop_add(7, 0, #{type: 'afterprop', text: ' EEE', text_align: 'after'}) |
| 2383 | call prop_add(8, 0, #{type: 'afterprop', text: ' FFF', text_align: 'after'}) |
| 2384 | normal 3G6J |
| 2385 | END |
| 2386 | call writefile(lines, 'XscriptPropsWithTextAfterJoined') |
| 2387 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterJoined', #{rows: 6, cols: 60}) |
| 2388 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_joined_1', {}) |
| 2389 | |
| 2390 | call StopVimInTerminal(buf) |
| 2391 | call delete('XscriptPropsWithTextAfterJoined') |
| 2392 | endfunc |
| 2393 | |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2394 | func Test_props_with_text_after_truncated() |
| 2395 | CheckRunVimInTerminal |
| 2396 | |
| 2397 | let lines =<< trim END |
| 2398 | call setline(1, ['one two three four five six seven']) |
| 2399 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2400 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE'}) |
| 2401 | |
| 2402 | call setline(2, ['one two three four five six seven']) |
| 2403 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right'}) |
| 2404 | |
| 2405 | call setline(3, ['one two three four five six seven']) |
| 2406 | 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'}) |
| 2407 | |
| 2408 | call setline(4, ['cursor here']) |
| 2409 | normal 4Gfh |
| 2410 | END |
| 2411 | call writefile(lines, 'XscriptPropsWithTextAfterTrunc') |
| 2412 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterTrunc', #{rows: 9, cols: 60}) |
| 2413 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_1', {}) |
| 2414 | |
| 2415 | call term_sendkeys(buf, ":37vsp\<CR>gg") |
| 2416 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_2', {}) |
| 2417 | |
| 2418 | call term_sendkeys(buf, ":36wincmd |\<CR>") |
| 2419 | call term_sendkeys(buf, "2G$") |
| 2420 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_3', {}) |
| 2421 | |
| 2422 | call term_sendkeys(buf, ":33wincmd |\<CR>") |
| 2423 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_4', {}) |
| 2424 | |
| 2425 | call term_sendkeys(buf, ":18wincmd |\<CR>") |
| 2426 | call term_sendkeys(buf, "0fx") |
| 2427 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_trunc_5', {}) |
| 2428 | |
| 2429 | call StopVimInTerminal(buf) |
| 2430 | call delete('XscriptPropsWithTextAfterTrunc') |
| 2431 | endfunc |
| 2432 | |
| 2433 | func Test_props_with_text_after_wraps() |
| 2434 | CheckRunVimInTerminal |
| 2435 | |
| 2436 | let lines =<< trim END |
| 2437 | call setline(1, ['one two three four five six seven']) |
| 2438 | call prop_type_add('afterprop', #{highlight: 'Search'}) |
| 2439 | call prop_add(1, 0, #{type: 'afterprop', text: ' ONE and TWO and THREE and FOUR and FIVE', text_wrap: 'wrap'}) |
| 2440 | |
| 2441 | call setline(2, ['one two three four five six seven']) |
| 2442 | call prop_add(2, 0, #{type: 'afterprop', text: ' one AND two AND three AND four AND five', text_align: 'right', text_wrap: 'wrap'}) |
| 2443 | |
| 2444 | call setline(3, ['one two three four five six seven']) |
| 2445 | 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'}) |
| 2446 | |
| 2447 | call setline(4, ['cursor here']) |
| 2448 | normal 4Gfh |
| 2449 | END |
| 2450 | call writefile(lines, 'XscriptPropsWithTextAfterWraps') |
| 2451 | let buf = RunVimInTerminal('-S XscriptPropsWithTextAfterWraps', #{rows: 9, cols: 60}) |
| 2452 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_wraps_1', {}) |
| 2453 | |
| 2454 | call StopVimInTerminal(buf) |
| 2455 | call delete('XscriptPropsWithTextAfterWraps') |
| 2456 | endfunc |
| 2457 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2458 | func Test_props_with_text_after_nowrap() |
| 2459 | CheckRunVimInTerminal |
| 2460 | |
| 2461 | let lines =<< trim END |
| 2462 | set nowrap |
| 2463 | call setline(1, ['one', 'two', 'three']) |
| 2464 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 2465 | call prop_type_add('anotherprop', #{highlight: 'Search'}) |
Bram Moolenaar | db9b96d | 2022-08-06 17:38:53 +0100 | [diff] [blame] | 2466 | call prop_type_add('someprop', #{highlight: 'DiffChange'}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2467 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 2468 | call prop_add(2, 0, #{type: 'anotherprop', text: 'another', text_align: 'below'}) |
| 2469 | 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] | 2470 | call prop_add(1, 0, #{type: 'someprop', text: 'right here', text_align: 'right'}) |
| 2471 | call prop_add(1, 0, #{type: 'someprop', text: ' After the text', text_align: 'after'}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2472 | normal G$ |
| 2473 | END |
| 2474 | call writefile(lines, 'XscriptPropsAfterNowrap') |
Bram Moolenaar | db9b96d | 2022-08-06 17:38:53 +0100 | [diff] [blame] | 2475 | let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 10, cols: 60}) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2476 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {}) |
| 2477 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2478 | call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3\<CR>") |
| 2479 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {}) |
| 2480 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2481 | call StopVimInTerminal(buf) |
| 2482 | call delete('XscriptPropsAfterNowrap') |
| 2483 | endfunc |
| 2484 | |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 2485 | func Test_props_with_text_below_nowrap() |
| 2486 | CheckRunVimInTerminal |
| 2487 | |
| 2488 | let lines =<< trim END |
| 2489 | vim9script |
| 2490 | edit foobar |
| 2491 | set nowrap |
| 2492 | set showbreak=+++\ |
| 2493 | setline(1, ['onasdf asdf asdf sdf df asdf asdf e asdf asdf asdf asdf asd fas df', 'two']) |
| 2494 | prop_type_add('test', {highlight: 'Special'}) |
| 2495 | prop_add(1, 0, { |
| 2496 | type: 'test', |
| 2497 | text: 'the quick brown fox jumps over the lazy dog', |
| 2498 | text_align: 'after' |
| 2499 | }) |
| 2500 | prop_add(1, 0, { |
| 2501 | type: 'test', |
| 2502 | text: 'the quick brown fox jumps over the lazy dog', |
| 2503 | text_align: 'below' |
| 2504 | }) |
| 2505 | normal G$ |
| 2506 | END |
| 2507 | call writefile(lines, 'XscriptPropsBelowNowrap') |
| 2508 | let buf = RunVimInTerminal('-S XscriptPropsBelowNowrap', #{rows: 8, cols: 60}) |
| 2509 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_1', {}) |
| 2510 | |
| 2511 | call term_sendkeys(buf, "gg$") |
| 2512 | call VerifyScreenDump(buf, 'Test_prop_with_text_below_nowrap_2', {}) |
| 2513 | |
| 2514 | call StopVimInTerminal(buf) |
| 2515 | call delete('XscriptPropsBelowNowrap') |
| 2516 | endfunc |
| 2517 | |
Bram Moolenaar | 7d0f7e9 | 2022-08-06 17:10:57 +0100 | [diff] [blame] | 2518 | func Test_props_with_text_after_split_join() |
| 2519 | CheckRunVimInTerminal |
| 2520 | |
| 2521 | let lines =<< trim END |
| 2522 | call setline(1, ['1122']) |
| 2523 | call prop_type_add('belowprop', #{highlight: 'ErrorMsg'}) |
| 2524 | call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'}) |
| 2525 | exe "normal f2i\<CR>\<Esc>" |
| 2526 | |
| 2527 | func AddMore() |
| 2528 | call prop_type_add('another', #{highlight: 'Search'}) |
| 2529 | call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'}) |
| 2530 | call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'}) |
| 2531 | endfunc |
| 2532 | END |
| 2533 | call writefile(lines, 'XscriptPropsAfterSplitJoin') |
| 2534 | let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60}) |
| 2535 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {}) |
| 2536 | |
| 2537 | call term_sendkeys(buf, "ggJ") |
| 2538 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {}) |
| 2539 | |
| 2540 | call term_sendkeys(buf, ":call AddMore()\<CR>") |
| 2541 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {}) |
| 2542 | |
| 2543 | call term_sendkeys(buf, "ggf s\<CR>\<Esc>") |
| 2544 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {}) |
| 2545 | |
| 2546 | call term_sendkeys(buf, "ggJ") |
| 2547 | call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {}) |
| 2548 | |
| 2549 | call StopVimInTerminal(buf) |
| 2550 | call delete('XscriptPropsAfterSplitJoin') |
| 2551 | endfunc |
| 2552 | |
Bram Moolenaar | 3a4cd39 | 2022-07-30 22:17:18 +0100 | [diff] [blame] | 2553 | func Test_removed_prop_with_text_cleans_up_array() |
| 2554 | new |
| 2555 | call setline(1, 'some text here') |
| 2556 | call prop_type_add('some', #{highlight: 'ErrorMsg'}) |
| 2557 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 2558 | call assert_equal(-1, id1) |
| 2559 | let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"}) |
| 2560 | call assert_equal(-2, id2) |
| 2561 | |
| 2562 | " removing the props resets the index |
| 2563 | call prop_remove(#{id: id1}) |
| 2564 | call prop_remove(#{id: id2}) |
| 2565 | let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) |
| 2566 | call assert_equal(-1, id1) |
| 2567 | |
| 2568 | call prop_type_delete('some') |
| 2569 | bwipe! |
| 2570 | endfunc |
| 2571 | |
Bram Moolenaar | 1f4ee19 | 2022-08-01 15:52:55 +0100 | [diff] [blame] | 2572 | def Test_insert_text_before_virtual_text() |
| 2573 | new foobar |
| 2574 | setline(1, '12345678') |
| 2575 | prop_type_add('test', {highlight: 'Search'}) |
| 2576 | prop_add(1, 5, { |
| 2577 | type: 'test', |
| 2578 | text: ' virtual text ' |
| 2579 | }) |
| 2580 | normal! f4axyz |
| 2581 | normal! f5iXYZ |
| 2582 | assert_equal('1234xyzXYZ5678', getline(1)) |
| 2583 | |
| 2584 | prop_type_delete('test') |
| 2585 | bwipe! |
| 2586 | enddef |
| 2587 | |
Bram Moolenaar | 99fa721 | 2020-04-26 15:59:55 +0200 | [diff] [blame] | 2588 | " vim: shiftwidth=2 sts=2 expandtab |