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