Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 1 | " Tests for diff mode |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 3 | source shared.vim |
| 4 | source screendump.vim |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 5 | source check.vim |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 6 | |
| 7 | func Test_diff_fold_sync() |
| 8 | enew! |
Bram Moolenaar | e8fa05b | 2018-09-16 15:48:06 +0200 | [diff] [blame] | 9 | let g:update_count = 0 |
| 10 | au DiffUpdated * let g:update_count += 1 |
| 11 | |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 12 | let l = range(50) |
| 13 | call setline(1, l) |
| 14 | diffthis |
| 15 | let winone = win_getid() |
| 16 | new |
| 17 | let l[25] = 'diff' |
| 18 | call setline(1, l) |
| 19 | diffthis |
| 20 | let wintwo = win_getid() |
| 21 | " line 15 is inside the closed fold |
| 22 | call assert_equal(19, foldclosedend(10)) |
| 23 | call win_gotoid(winone) |
| 24 | call assert_equal(19, foldclosedend(10)) |
| 25 | " open the fold |
| 26 | normal zv |
| 27 | call assert_equal(-1, foldclosedend(10)) |
| 28 | " fold in other window must have opened too |
| 29 | call win_gotoid(wintwo) |
| 30 | call assert_equal(-1, foldclosedend(10)) |
| 31 | |
| 32 | " cursor position is in sync |
| 33 | normal 23G |
| 34 | call win_gotoid(winone) |
| 35 | call assert_equal(23, getcurpos()[1]) |
| 36 | |
Bram Moolenaar | f65cc66 | 2022-06-26 18:17:50 +0100 | [diff] [blame] | 37 | " depending on how redraw is done DiffUpdated may be triggered once or twice |
| 38 | call assert_inrange(1, 2, g:update_count) |
Bram Moolenaar | e8fa05b | 2018-09-16 15:48:06 +0200 | [diff] [blame] | 39 | au! DiffUpdated |
| 40 | |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 41 | windo diffoff |
| 42 | close! |
| 43 | set nomodified |
| 44 | endfunc |
| 45 | |
| 46 | func Test_vert_split() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 47 | set diffopt=filler |
| 48 | call Common_vert_split() |
| 49 | set diffopt& |
| 50 | endfunc |
| 51 | |
| 52 | func Test_vert_split_internal() |
| 53 | set diffopt=internal,filler |
| 54 | call Common_vert_split() |
| 55 | set diffopt& |
| 56 | endfunc |
| 57 | |
| 58 | func Common_vert_split() |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 59 | " Disable the title to avoid xterm keeping the wrong one. |
| 60 | set notitle noicon |
| 61 | new |
| 62 | let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee'] |
| 63 | call setline(1, l) |
| 64 | w! Xtest |
| 65 | normal dd |
| 66 | $ |
| 67 | put |
| 68 | normal kkrXoxxx |
| 69 | w! Xtest2 |
| 70 | file Nop |
| 71 | normal ggoyyyjjjozzzz |
| 72 | set foldmethod=marker foldcolumn=4 |
| 73 | call assert_equal(0, &diff) |
| 74 | call assert_equal('marker', &foldmethod) |
| 75 | call assert_equal(4, &foldcolumn) |
| 76 | call assert_equal(0, &scrollbind) |
| 77 | call assert_equal(0, &cursorbind) |
| 78 | call assert_equal(1, &wrap) |
| 79 | |
| 80 | vert diffsplit Xtest |
| 81 | vert diffsplit Xtest2 |
| 82 | call assert_equal(1, &diff) |
| 83 | call assert_equal('diff', &foldmethod) |
| 84 | call assert_equal(2, &foldcolumn) |
| 85 | call assert_equal(1, &scrollbind) |
| 86 | call assert_equal(1, &cursorbind) |
| 87 | call assert_equal(0, &wrap) |
| 88 | |
| 89 | let diff_fdm = &fdm |
| 90 | let diff_fdc = &fdc |
| 91 | " repeat entering diff mode here to see if this saves the wrong settings |
| 92 | diffthis |
| 93 | " jump to second window for a moment to have filler line appear at start of |
| 94 | " first window |
| 95 | wincmd w |
| 96 | normal gg |
| 97 | wincmd p |
| 98 | normal gg |
| 99 | call assert_equal(2, winline()) |
| 100 | normal j |
| 101 | call assert_equal(4, winline()) |
| 102 | normal j |
| 103 | call assert_equal(5, winline()) |
| 104 | normal j |
| 105 | call assert_equal(6, winline()) |
| 106 | normal j |
| 107 | call assert_equal(8, winline()) |
| 108 | normal j |
| 109 | call assert_equal(9, winline()) |
| 110 | |
| 111 | wincmd w |
| 112 | normal gg |
| 113 | call assert_equal(1, winline()) |
| 114 | normal j |
| 115 | call assert_equal(2, winline()) |
| 116 | normal j |
| 117 | call assert_equal(4, winline()) |
| 118 | normal j |
| 119 | call assert_equal(5, winline()) |
| 120 | normal j |
| 121 | call assert_equal(8, winline()) |
| 122 | |
| 123 | wincmd w |
| 124 | normal gg |
| 125 | call assert_equal(2, winline()) |
| 126 | normal j |
| 127 | call assert_equal(3, winline()) |
| 128 | normal j |
| 129 | call assert_equal(4, winline()) |
| 130 | normal j |
| 131 | call assert_equal(5, winline()) |
| 132 | normal j |
| 133 | call assert_equal(6, winline()) |
| 134 | normal j |
| 135 | call assert_equal(7, winline()) |
| 136 | normal j |
| 137 | call assert_equal(8, winline()) |
| 138 | |
| 139 | " Test diffoff |
| 140 | diffoff! |
zeertzjq | 5fd6ab8 | 2022-08-17 12:09:45 +0100 | [diff] [blame] | 141 | 1wincmd w |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 142 | let &diff = 1 |
| 143 | let &fdm = diff_fdm |
| 144 | let &fdc = diff_fdc |
| 145 | 4wincmd w |
| 146 | diffoff! |
| 147 | 1wincmd w |
| 148 | call assert_equal(0, &diff) |
| 149 | call assert_equal('marker', &foldmethod) |
| 150 | call assert_equal(4, &foldcolumn) |
| 151 | call assert_equal(0, &scrollbind) |
| 152 | call assert_equal(0, &cursorbind) |
| 153 | call assert_equal(1, &wrap) |
| 154 | |
| 155 | wincmd w |
| 156 | call assert_equal(0, &diff) |
| 157 | call assert_equal('marker', &foldmethod) |
| 158 | call assert_equal(4, &foldcolumn) |
| 159 | call assert_equal(0, &scrollbind) |
| 160 | call assert_equal(0, &cursorbind) |
| 161 | call assert_equal(1, &wrap) |
| 162 | |
| 163 | wincmd w |
| 164 | call assert_equal(0, &diff) |
| 165 | call assert_equal('marker', &foldmethod) |
| 166 | call assert_equal(4, &foldcolumn) |
| 167 | call assert_equal(0, &scrollbind) |
| 168 | call assert_equal(0, &cursorbind) |
| 169 | call assert_equal(1, &wrap) |
| 170 | |
Bram Moolenaar | 623cf88 | 2016-07-30 16:36:01 +0200 | [diff] [blame] | 171 | call delete('Xtest') |
| 172 | call delete('Xtest2') |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 173 | windo bw! |
| 174 | endfunc |
| 175 | |
| 176 | func Test_filler_lines() |
| 177 | " Test that diffing shows correct filler lines |
| 178 | enew! |
| 179 | put =range(4,10) |
| 180 | 1d _ |
| 181 | vnew |
| 182 | put =range(1,10) |
| 183 | 1d _ |
| 184 | windo diffthis |
| 185 | wincmd h |
| 186 | call assert_equal(1, line('w0')) |
| 187 | unlet! diff_fdm diff_fdc |
Bram Moolenaar | 90d121f | 2016-07-30 19:11:25 +0200 | [diff] [blame] | 188 | windo diffoff |
| 189 | bwipe! |
| 190 | enew! |
| 191 | endfunc |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 192 | |
Bram Moolenaar | 90d121f | 2016-07-30 19:11:25 +0200 | [diff] [blame] | 193 | func Test_diffget_diffput() |
| 194 | enew! |
| 195 | let l = range(50) |
| 196 | call setline(1, l) |
| 197 | call assert_fails('diffget', 'E99:') |
| 198 | diffthis |
| 199 | call assert_fails('diffget', 'E100:') |
| 200 | new |
| 201 | let l[10] = 'one' |
| 202 | let l[20] = 'two' |
| 203 | let l[30] = 'three' |
| 204 | let l[40] = 'four' |
| 205 | call setline(1, l) |
| 206 | diffthis |
| 207 | call assert_equal('one', getline(11)) |
| 208 | 11diffget |
| 209 | call assert_equal('10', getline(11)) |
| 210 | 21diffput |
| 211 | wincmd w |
| 212 | call assert_equal('two', getline(21)) |
| 213 | normal 31Gdo |
| 214 | call assert_equal('three', getline(31)) |
| 215 | call assert_equal('40', getline(41)) |
| 216 | normal 41Gdp |
| 217 | wincmd w |
| 218 | call assert_equal('40', getline(41)) |
| 219 | new |
| 220 | diffthis |
| 221 | call assert_fails('diffget', 'E101:') |
| 222 | |
| 223 | windo diffoff |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 224 | %bwipe! |
| 225 | endfunc |
| 226 | |
Bram Moolenaar | 5f57bdc | 2018-10-25 17:52:23 +0200 | [diff] [blame] | 227 | " Test putting two changes from one buffer to another |
| 228 | func Test_diffput_two() |
| 229 | new a |
| 230 | let win_a = win_getid() |
| 231 | call setline(1, range(1, 10)) |
| 232 | diffthis |
| 233 | new b |
| 234 | let win_b = win_getid() |
| 235 | call setline(1, range(1, 10)) |
| 236 | 8del |
| 237 | 5del |
| 238 | diffthis |
| 239 | call win_gotoid(win_a) |
| 240 | %diffput |
| 241 | call win_gotoid(win_b) |
| 242 | call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$')) |
| 243 | bwipe! a |
| 244 | bwipe! b |
| 245 | endfunc |
| 246 | |
Yegappan Lakshmanan | 3044324 | 2021-06-10 21:52:15 +0200 | [diff] [blame] | 247 | " Test for :diffget/:diffput with a range that is inside a diff chunk |
| 248 | func Test_diffget_diffput_range() |
| 249 | call setline(1, range(1, 10)) |
| 250 | new |
| 251 | call setline(1, range(11, 20)) |
| 252 | windo diffthis |
| 253 | 3,5diffget |
| 254 | call assert_equal(['13', '14', '15'], getline(3, 5)) |
| 255 | call setline(1, range(1, 10)) |
| 256 | 4,8diffput |
| 257 | wincmd p |
| 258 | call assert_equal(['13', '4', '5', '6', '7', '8', '19'], getline(3, 9)) |
| 259 | %bw! |
| 260 | endfunc |
| 261 | |
| 262 | " Test for :diffget/:diffput with an empty buffer and a non-empty buffer |
| 263 | func Test_diffget_diffput_empty_buffer() |
| 264 | %d _ |
| 265 | new |
| 266 | call setline(1, 'one') |
| 267 | windo diffthis |
| 268 | diffget |
| 269 | call assert_equal(['one'], getline(1, '$')) |
| 270 | %d _ |
| 271 | diffput |
| 272 | wincmd p |
| 273 | call assert_equal([''], getline(1, '$')) |
| 274 | %bw! |
| 275 | endfunc |
| 276 | |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 277 | " :diffput and :diffget completes names of buffers which |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 278 | " are in diff mode and which are different than current buffer. |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 279 | " No completion when the current window is not in diff mode. |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 280 | func Test_diffget_diffput_completion() |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 281 | e Xdiff1 | diffthis |
| 282 | botright new Xdiff2 |
| 283 | botright new Xdiff3 | split | diffthis |
| 284 | botright new Xdiff4 | diffthis |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 285 | |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 286 | wincmd t |
| 287 | call assert_equal('Xdiff1', bufname('%')) |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 288 | call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 289 | call assert_equal('"diffput Xdiff3 Xdiff4', @:) |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 290 | call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 291 | call assert_equal('"diffget Xdiff3 Xdiff4', @:) |
| 292 | call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer')) |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 293 | |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 294 | " Xdiff2 is not in diff mode, so no completion for :diffput, :diffget |
| 295 | wincmd j |
| 296 | call assert_equal('Xdiff2', bufname('%')) |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 297 | call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') |
| 298 | call assert_equal('"diffput ', @:) |
| 299 | call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') |
| 300 | call assert_equal('"diffget ', @:) |
| 301 | call assert_equal([], getcompletion('', 'diff_buffer')) |
| 302 | |
Bram Moolenaar | efcc329 | 2019-12-30 21:59:03 +0100 | [diff] [blame] | 303 | " Xdiff3 is split in 2 windows, only the top one is in diff mode. |
| 304 | " So completion of :diffput :diffget only happens in the top window. |
| 305 | wincmd j |
| 306 | call assert_equal('Xdiff3', bufname('%')) |
| 307 | call assert_equal(1, &diff) |
| 308 | call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') |
| 309 | call assert_equal('"diffput Xdiff1 Xdiff4', @:) |
| 310 | call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') |
| 311 | call assert_equal('"diffget Xdiff1 Xdiff4', @:) |
| 312 | call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer')) |
| 313 | |
| 314 | wincmd j |
| 315 | call assert_equal('Xdiff3', bufname('%')) |
| 316 | call assert_equal(0, &diff) |
| 317 | call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') |
| 318 | call assert_equal('"diffput ', @:) |
| 319 | call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') |
| 320 | call assert_equal('"diffget ', @:) |
| 321 | call assert_equal([], getcompletion('', 'diff_buffer')) |
| 322 | |
| 323 | wincmd j |
| 324 | call assert_equal('Xdiff4', bufname('%')) |
| 325 | call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx') |
| 326 | call assert_equal('"diffput Xdiff1 Xdiff3', @:) |
| 327 | call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx') |
| 328 | call assert_equal('"diffget Xdiff1 Xdiff3', @:) |
| 329 | call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer')) |
| 330 | |
Bram Moolenaar | ae7dba8 | 2019-12-29 13:56:33 +0100 | [diff] [blame] | 331 | %bwipe |
| 332 | endfunc |
| 333 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 334 | func Test_dp_do_buffer() |
| 335 | e! one |
| 336 | let bn1=bufnr('%') |
| 337 | let l = range(60) |
| 338 | call setline(1, l) |
| 339 | diffthis |
| 340 | |
| 341 | new two |
| 342 | let l[10] = 'one' |
| 343 | let l[20] = 'two' |
| 344 | let l[30] = 'three' |
| 345 | let l[40] = 'four' |
| 346 | let l[50] = 'five' |
| 347 | call setline(1, l) |
| 348 | diffthis |
| 349 | |
| 350 | " dp and do with invalid buffer number. |
| 351 | 11 |
| 352 | call assert_fails('norm 99999dp', 'E102:') |
| 353 | call assert_fails('norm 99999do', 'E102:') |
| 354 | call assert_fails('diffput non_existing_buffer', 'E94:') |
| 355 | call assert_fails('diffget non_existing_buffer', 'E94:') |
| 356 | |
| 357 | " dp and do with valid buffer number. |
| 358 | call assert_equal('one', getline('.')) |
| 359 | exe 'norm ' . bn1 . 'do' |
| 360 | call assert_equal('10', getline('.')) |
| 361 | 21 |
| 362 | call assert_equal('two', getline('.')) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 363 | diffget one |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 364 | call assert_equal('20', getline('.')) |
| 365 | |
| 366 | 31 |
| 367 | exe 'norm ' . bn1 . 'dp' |
| 368 | 41 |
| 369 | diffput one |
| 370 | wincmd w |
| 371 | 31 |
| 372 | call assert_equal('three', getline('.')) |
| 373 | 41 |
| 374 | call assert_equal('four', getline('.')) |
| 375 | |
| 376 | " dp and do with buffer number which is not in diff mode. |
| 377 | new not_in_diff_mode |
| 378 | let bn3=bufnr('%') |
| 379 | wincmd w |
| 380 | 51 |
| 381 | call assert_fails('exe "norm" . bn3 . "dp"', 'E103:') |
| 382 | call assert_fails('exe "norm" . bn3 . "do"', 'E103:') |
| 383 | call assert_fails('diffput not_in_diff_mode', 'E94:') |
| 384 | call assert_fails('diffget not_in_diff_mode', 'E94:') |
| 385 | |
| 386 | windo diffoff |
| 387 | %bwipe! |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 388 | endfunc |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 389 | |
Bram Moolenaar | df77cef | 2018-10-07 17:46:42 +0200 | [diff] [blame] | 390 | func Test_do_lastline() |
| 391 | e! one |
| 392 | call setline(1, ['1','2','3','4','5','6']) |
| 393 | diffthis |
| 394 | |
| 395 | new two |
| 396 | call setline(1, ['2','4','5']) |
| 397 | diffthis |
| 398 | |
| 399 | 1 |
| 400 | norm dp]c |
| 401 | norm dp]c |
| 402 | wincmd w |
| 403 | call assert_equal(4, line('$')) |
| 404 | norm G |
| 405 | norm do |
| 406 | call assert_equal(3, line('$')) |
| 407 | |
| 408 | windo diffoff |
| 409 | %bwipe! |
| 410 | endfunc |
| 411 | |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 412 | func Test_diffoff() |
| 413 | enew! |
| 414 | call setline(1, ['Two', 'Three']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 415 | redraw |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 416 | let normattr = screenattr(1, 1) |
| 417 | diffthis |
| 418 | botright vert new |
| 419 | call setline(1, ['One', '', 'Two', 'Three']) |
| 420 | diffthis |
| 421 | redraw |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 422 | call assert_notequal(normattr, 1->screenattr(1)) |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 423 | diffoff! |
| 424 | redraw |
| 425 | call assert_equal(normattr, screenattr(1, 1)) |
| 426 | bwipe! |
| 427 | bwipe! |
| 428 | endfunc |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 429 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 430 | func Common_icase_test() |
| 431 | edit one |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 432 | call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 433 | redraw |
| 434 | let normattr = screenattr(1, 1) |
| 435 | diffthis |
| 436 | |
| 437 | botright vert new two |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 438 | call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 439 | diffthis |
| 440 | |
| 441 | redraw |
| 442 | call assert_equal(normattr, screenattr(1, 1)) |
| 443 | call assert_equal(normattr, screenattr(2, 1)) |
| 444 | call assert_notequal(normattr, screenattr(3, 1)) |
| 445 | call assert_equal(normattr, screenattr(4, 1)) |
| 446 | |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 447 | let dtextattr = screenattr(5, 3) |
| 448 | call assert_notequal(dtextattr, screenattr(5, 1)) |
| 449 | call assert_notequal(dtextattr, screenattr(5, 5)) |
| 450 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 451 | diffoff! |
| 452 | %bwipe! |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 453 | endfunc |
| 454 | |
| 455 | func Test_diffopt_icase() |
| 456 | set diffopt=icase,foldcolumn:0 |
| 457 | call Common_icase_test() |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 458 | set diffopt& |
| 459 | endfunc |
| 460 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 461 | func Test_diffopt_icase_internal() |
| 462 | set diffopt=icase,foldcolumn:0,internal |
| 463 | call Common_icase_test() |
| 464 | set diffopt& |
| 465 | endfunc |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 466 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 467 | func Common_iwhite_test() |
| 468 | edit one |
| 469 | " Difference in trailing spaces and amount of spaces should be ignored, |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 470 | " but not other space differences. |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 471 | call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 472 | redraw |
| 473 | let normattr = screenattr(1, 1) |
| 474 | diffthis |
| 475 | |
| 476 | botright vert new two |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 477 | call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 478 | diffthis |
| 479 | |
| 480 | redraw |
| 481 | call assert_equal(normattr, screenattr(1, 1)) |
| 482 | call assert_equal(normattr, screenattr(2, 1)) |
| 483 | call assert_equal(normattr, screenattr(3, 1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 484 | call assert_equal(normattr, screenattr(4, 1)) |
| 485 | call assert_notequal(normattr, screenattr(5, 1)) |
| 486 | call assert_notequal(normattr, screenattr(6, 1)) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 487 | |
| 488 | diffoff! |
| 489 | %bwipe! |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 490 | endfunc |
| 491 | |
| 492 | func Test_diffopt_iwhite() |
| 493 | set diffopt=iwhite,foldcolumn:0 |
| 494 | call Common_iwhite_test() |
| 495 | set diffopt& |
| 496 | endfunc |
| 497 | |
| 498 | func Test_diffopt_iwhite_internal() |
| 499 | set diffopt=internal,iwhite,foldcolumn:0 |
| 500 | call Common_iwhite_test() |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 501 | set diffopt& |
| 502 | endfunc |
| 503 | |
| 504 | func Test_diffopt_context() |
| 505 | enew! |
| 506 | call setline(1, ['1', '2', '3', '4', '5', '6', '7']) |
| 507 | diffthis |
| 508 | new |
| 509 | call setline(1, ['1', '2', '3', '4', '5x', '6', '7']) |
| 510 | diffthis |
| 511 | |
| 512 | set diffopt=context:2 |
| 513 | call assert_equal('+-- 2 lines: 1', foldtextresult(1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 514 | set diffopt=internal,context:2 |
| 515 | call assert_equal('+-- 2 lines: 1', foldtextresult(1)) |
| 516 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 517 | set diffopt=context:1 |
| 518 | call assert_equal('+-- 3 lines: 1', foldtextresult(1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 519 | set diffopt=internal,context:1 |
| 520 | call assert_equal('+-- 3 lines: 1', foldtextresult(1)) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 521 | |
| 522 | diffoff! |
| 523 | %bwipe! |
| 524 | set diffopt& |
| 525 | endfunc |
| 526 | |
| 527 | func Test_diffopt_horizontal() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 528 | set diffopt=internal,horizontal |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 529 | diffsplit |
| 530 | |
| 531 | call assert_equal(&columns, winwidth(1)) |
| 532 | call assert_equal(&columns, winwidth(2)) |
| 533 | call assert_equal(&lines, winheight(1) + winheight(2) + 3) |
| 534 | call assert_inrange(0, 1, winheight(1) - winheight(2)) |
| 535 | |
| 536 | set diffopt& |
| 537 | diffoff! |
| 538 | %bwipe |
| 539 | endfunc |
| 540 | |
| 541 | func Test_diffopt_vertical() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 542 | set diffopt=internal,vertical |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 543 | diffsplit |
| 544 | |
| 545 | call assert_equal(&lines - 2, winheight(1)) |
| 546 | call assert_equal(&lines - 2, winheight(2)) |
| 547 | call assert_equal(&columns, winwidth(1) + winwidth(2) + 1) |
| 548 | call assert_inrange(0, 1, winwidth(1) - winwidth(2)) |
| 549 | |
| 550 | set diffopt& |
| 551 | diffoff! |
| 552 | %bwipe |
| 553 | endfunc |
| 554 | |
Bram Moolenaar | 97ce419 | 2017-12-01 20:35:58 +0100 | [diff] [blame] | 555 | func Test_diffopt_hiddenoff() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 556 | set diffopt=internal,filler,foldcolumn:0,hiddenoff |
Bram Moolenaar | 97ce419 | 2017-12-01 20:35:58 +0100 | [diff] [blame] | 557 | e! one |
| 558 | call setline(1, ['Two', 'Three']) |
| 559 | redraw |
| 560 | let normattr = screenattr(1, 1) |
| 561 | diffthis |
| 562 | botright vert new two |
| 563 | call setline(1, ['One', 'Four']) |
| 564 | diffthis |
| 565 | redraw |
| 566 | call assert_notequal(normattr, screenattr(1, 1)) |
| 567 | set hidden |
| 568 | close |
| 569 | redraw |
| 570 | " should not diffing with hidden buffer two while 'hiddenoff' is enabled |
| 571 | call assert_equal(normattr, screenattr(1, 1)) |
| 572 | |
| 573 | bwipe! |
| 574 | bwipe! |
| 575 | set hidden& diffopt& |
| 576 | endfunc |
| 577 | |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 578 | func Test_diffoff_hidden() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 579 | set diffopt=internal,filler,foldcolumn:0 |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 580 | e! one |
| 581 | call setline(1, ['Two', 'Three']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 582 | redraw |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 583 | let normattr = screenattr(1, 1) |
| 584 | diffthis |
| 585 | botright vert new two |
| 586 | call setline(1, ['One', 'Four']) |
| 587 | diffthis |
| 588 | redraw |
| 589 | call assert_notequal(normattr, screenattr(1, 1)) |
| 590 | set hidden |
| 591 | close |
| 592 | redraw |
| 593 | " diffing with hidden buffer two |
| 594 | call assert_notequal(normattr, screenattr(1, 1)) |
| 595 | diffoff |
| 596 | redraw |
| 597 | call assert_equal(normattr, screenattr(1, 1)) |
| 598 | diffthis |
| 599 | redraw |
| 600 | " still diffing with hidden buffer two |
| 601 | call assert_notequal(normattr, screenattr(1, 1)) |
| 602 | diffoff! |
| 603 | redraw |
| 604 | call assert_equal(normattr, screenattr(1, 1)) |
| 605 | diffthis |
| 606 | redraw |
| 607 | " no longer diffing with hidden buffer two |
| 608 | call assert_equal(normattr, screenattr(1, 1)) |
| 609 | |
| 610 | bwipe! |
| 611 | bwipe! |
| 612 | set hidden& diffopt& |
| 613 | endfunc |
| 614 | |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 615 | func Test_setting_cursor() |
| 616 | new Xtest1 |
| 617 | put =range(1,90) |
| 618 | wq |
| 619 | new Xtest2 |
| 620 | put =range(1,100) |
| 621 | wq |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 622 | |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 623 | tabe Xtest2 |
| 624 | $ |
| 625 | diffsp Xtest1 |
| 626 | tabclose |
| 627 | |
| 628 | call delete('Xtest1') |
| 629 | call delete('Xtest2') |
| 630 | endfunc |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 631 | |
| 632 | func Test_diff_move_to() |
| 633 | new |
| 634 | call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
| 635 | diffthis |
| 636 | vnew |
| 637 | call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x']) |
| 638 | diffthis |
| 639 | norm ]c |
| 640 | call assert_equal(2, line('.')) |
| 641 | norm 3]c |
| 642 | call assert_equal(9, line('.')) |
| 643 | norm 10]c |
| 644 | call assert_equal(11, line('.')) |
| 645 | norm [c |
| 646 | call assert_equal(9, line('.')) |
| 647 | norm 2[c |
| 648 | call assert_equal(5, line('.')) |
| 649 | norm 10[c |
| 650 | call assert_equal(2, line('.')) |
| 651 | %bwipe! |
| 652 | endfunc |
| 653 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 654 | func Test_diffexpr() |
Bram Moolenaar | aeb313f | 2020-11-27 19:13:28 +0100 | [diff] [blame] | 655 | CheckExecutable diff |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 656 | |
| 657 | func DiffExpr() |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 658 | " Prepend some text to check diff type detection |
Bram Moolenaar | 3b8defd | 2018-09-13 13:03:11 +0200 | [diff] [blame] | 659 | call writefile(['warning', ' message'], v:fname_out) |
| 660 | silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 661 | endfunc |
| 662 | set diffexpr=DiffExpr() |
| 663 | set diffopt=foldcolumn:0 |
| 664 | |
| 665 | enew! |
| 666 | call setline(1, ['one', 'two', 'three']) |
| 667 | redraw |
| 668 | let normattr = screenattr(1, 1) |
| 669 | diffthis |
| 670 | |
| 671 | botright vert new |
| 672 | call setline(1, ['one', 'two', 'three.']) |
| 673 | diffthis |
| 674 | |
| 675 | redraw |
| 676 | call assert_equal(normattr, screenattr(1, 1)) |
| 677 | call assert_equal(normattr, screenattr(2, 1)) |
| 678 | call assert_notequal(normattr, screenattr(3, 1)) |
Yegappan Lakshmanan | 3044324 | 2021-06-10 21:52:15 +0200 | [diff] [blame] | 679 | diffoff! |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 680 | |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 681 | " Try using a non-existing function for 'diffexpr'. |
Yegappan Lakshmanan | 3044324 | 2021-06-10 21:52:15 +0200 | [diff] [blame] | 682 | set diffexpr=NewDiffFunc() |
| 683 | call assert_fails('windo diffthis', ['E117:', 'E97:']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 684 | diffoff! |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 685 | |
| 686 | " Using a script-local function |
| 687 | func s:NewDiffExpr() |
| 688 | endfunc |
| 689 | set diffexpr=s:NewDiffExpr() |
| 690 | call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr) |
| 691 | set diffexpr=<SID>NewDiffExpr() |
| 692 | call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr) |
| 693 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 694 | %bwipe! |
| 695 | set diffexpr& diffopt& |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 696 | delfunc DiffExpr |
| 697 | delfunc s:NewDiffExpr |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 698 | endfunc |
| 699 | |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 700 | func Test_diffpatch() |
| 701 | " The patch program on MS-Windows may fail or hang. |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 702 | CheckExecutable patch |
| 703 | CheckUnix |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 704 | new |
| 705 | insert |
| 706 | *************** |
| 707 | *** 1,3 **** |
| 708 | 1 |
| 709 | ! 2 |
| 710 | 3 |
| 711 | --- 1,4 ---- |
| 712 | 1 |
| 713 | ! 2x |
| 714 | 3 |
| 715 | + 4 |
| 716 | . |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 717 | saveas! Xpatch |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 718 | bwipe! |
| 719 | new |
| 720 | call assert_fails('diffpatch Xpatch', 'E816:') |
Bram Moolenaar | 1ef73e3 | 2017-03-09 19:21:30 +0100 | [diff] [blame] | 721 | |
Bram Moolenaar | a95ab32 | 2017-03-11 19:21:53 +0100 | [diff] [blame] | 722 | for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch'] |
Bram Moolenaar | 1ef73e3 | 2017-03-09 19:21:30 +0100 | [diff] [blame] | 723 | call setline(1, ['1', '2', '3']) |
| 724 | if name != 'Xpatch' |
| 725 | call rename('Xpatch', name) |
| 726 | endif |
| 727 | exe 'diffpatch ' . escape(name, '$') |
| 728 | call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) |
| 729 | if name != 'Xpatch' |
| 730 | call rename(name, 'Xpatch') |
| 731 | endif |
| 732 | bwipe! |
| 733 | endfor |
| 734 | |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 735 | call delete('Xpatch') |
| 736 | bwipe! |
| 737 | endfunc |
| 738 | |
Bram Moolenaar | 23a971d | 2023-04-04 22:04:53 +0100 | [diff] [blame] | 739 | " FIXME: test fails, the Xresult file can't be read |
| 740 | func No_Test_diffpatch_restricted() |
| 741 | let lines =<< trim END |
| 742 | call assert_fails('diffpatch NoSuchDiff', 'E145:') |
| 743 | |
| 744 | call writefile(v:errors, 'Xresult') |
| 745 | qa! |
| 746 | END |
| 747 | call writefile(lines, 'Xrestricted', 'D') |
| 748 | if RunVim([], [], '-Z --clean -S Xrestricted') |
| 749 | call assert_equal([], readfile('Xresult')) |
| 750 | endif |
| 751 | call delete('Xresult') |
| 752 | endfunc |
| 753 | |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 754 | func Test_diff_too_many_buffers() |
| 755 | for i in range(1, 8) |
| 756 | exe "new Xtest" . i |
| 757 | diffthis |
| 758 | endfor |
| 759 | new Xtest9 |
| 760 | call assert_fails('diffthis', 'E96:') |
| 761 | %bwipe! |
| 762 | endfunc |
| 763 | |
| 764 | func Test_diff_nomodifiable() |
| 765 | new |
| 766 | call setline(1, [1, 2, 3, 4]) |
| 767 | setl nomodifiable |
| 768 | diffthis |
| 769 | vnew |
| 770 | call setline(1, ['1x', 2, 3, 3, 4]) |
| 771 | diffthis |
| 772 | call assert_fails('norm dp', 'E793:') |
| 773 | setl nomodifiable |
| 774 | call assert_fails('norm do', 'E21:') |
| 775 | %bwipe! |
| 776 | endfunc |
Bram Moolenaar | f58a847 | 2017-03-05 18:03:04 +0100 | [diff] [blame] | 777 | |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 778 | func Test_diff_hlID() |
| 779 | new |
| 780 | call setline(1, [1, 2, 3]) |
| 781 | diffthis |
| 782 | vnew |
| 783 | call setline(1, ['1x', 2, 'x', 3]) |
| 784 | diffthis |
| 785 | redraw |
| 786 | |
Bram Moolenaar | a74e494 | 2019-08-04 17:35:53 +0200 | [diff] [blame] | 787 | call diff_hlID(-1, 1)->synIDattr("name")->assert_equal("") |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 788 | |
Bram Moolenaar | a74e494 | 2019-08-04 17:35:53 +0200 | [diff] [blame] | 789 | call diff_hlID(1, 1)->synIDattr("name")->assert_equal("DiffChange") |
| 790 | call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText") |
| 791 | call diff_hlID(2, 1)->synIDattr("name")->assert_equal("") |
| 792 | call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd") |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 793 | eval 4->diff_hlID(1)->synIDattr("name")->assert_equal("") |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 794 | |
| 795 | wincmd w |
| 796 | call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") |
| 797 | call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") |
| 798 | call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "") |
| 799 | |
| 800 | %bwipe! |
| 801 | endfunc |
| 802 | |
| 803 | func Test_diff_filler() |
| 804 | new |
| 805 | call setline(1, [1, 2, 3, 'x', 4]) |
| 806 | diffthis |
| 807 | vnew |
| 808 | call setline(1, [1, 2, 'y', 'y', 3, 4]) |
| 809 | diffthis |
| 810 | redraw |
| 811 | |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 812 | call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'v:val->diff_filler()')) |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 813 | wincmd w |
| 814 | call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) |
| 815 | |
| 816 | %bwipe! |
| 817 | endfunc |
| 818 | |
Bram Moolenaar | f58a847 | 2017-03-05 18:03:04 +0100 | [diff] [blame] | 819 | func Test_diff_lastline() |
| 820 | enew! |
| 821 | only! |
| 822 | call setline(1, ['This is a ', 'line with five ', 'rows']) |
| 823 | diffthis |
| 824 | botright vert new |
| 825 | call setline(1, ['This is', 'a line with ', 'four rows']) |
| 826 | diffthis |
| 827 | 1 |
| 828 | call feedkeys("Je a\<CR>", 'tx') |
| 829 | call feedkeys("Je a\<CR>", 'tx') |
| 830 | let w1lines = winline() |
| 831 | wincmd w |
| 832 | $ |
| 833 | let w2lines = winline() |
| 834 | call assert_equal(w2lines, w1lines) |
| 835 | bwipe! |
| 836 | bwipe! |
| 837 | endfunc |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 838 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 839 | func WriteDiffFiles(buf, list1, list2) |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 840 | call writefile(a:list1, 'Xdifile1') |
| 841 | call writefile(a:list2, 'Xdifile2') |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 842 | if a:buf |
| 843 | call term_sendkeys(a:buf, ":checktime\<CR>") |
| 844 | endif |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 845 | endfunc |
| 846 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 847 | " Verify a screendump with both the internal and external diff. |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 848 | func VerifyBoth(buf, dumpfile, extra) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 849 | " trailing : for leaving the cursor on the command line |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 850 | for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"] |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 851 | call term_sendkeys(a:buf, cmd) |
| 852 | if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external') |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 853 | " don't let the next iteration overwrite the "failed" file. |
| 854 | return |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 855 | endif |
| 856 | endfor |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 857 | |
| 858 | " also test unified diff |
| 859 | call term_sendkeys(a:buf, ":call SetupUnified()\<CR>:") |
glacambre | ad5c178 | 2021-05-24 14:20:53 +0200 | [diff] [blame] | 860 | call term_sendkeys(a:buf, ":redraw!\<CR>:") |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 861 | call VerifyScreenDump(a:buf, a:dumpfile, {}, 'unified') |
| 862 | call term_sendkeys(a:buf, ":call StopUnified()\<CR>:") |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 863 | endfunc |
| 864 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 865 | " Verify a screendump with the internal diff only. |
| 866 | func VerifyInternal(buf, dumpfile, extra) |
| 867 | call term_sendkeys(a:buf, ":diffupdate!\<CR>") |
| 868 | " trailing : for leaving the cursor on the command line |
| 869 | call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:") |
| 870 | call VerifyScreenDump(a:buf, a:dumpfile, {}) |
| 871 | endfunc |
| 872 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 873 | func Test_diff_screen() |
rhysd | e93d5ca | 2024-02-01 21:22:14 +0100 | [diff] [blame] | 874 | if has('osx') && !empty($CI) && system('uname -m') =~# 'arm64' |
| 875 | throw 'Skipped: FIXME: This test fails on M1 Mac on GitHub Actions' |
| 876 | endif |
| 877 | |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 878 | let g:test_is_flaky = 1 |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 879 | CheckScreendump |
| 880 | CheckFeature menu |
| 881 | |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 882 | let lines =<< trim END |
| 883 | func UnifiedDiffExpr() |
| 884 | " Prepend some text to check diff type detection |
| 885 | call writefile(['warning', ' message'], v:fname_out) |
glacambre | ad5c178 | 2021-05-24 14:20:53 +0200 | [diff] [blame] | 886 | silent exe '!diff -U0 ' .. v:fname_in .. ' ' .. v:fname_new .. '>>' .. v:fname_out |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 887 | endfunc |
| 888 | func SetupUnified() |
| 889 | set diffexpr=UnifiedDiffExpr() |
glacambre | ad5c178 | 2021-05-24 14:20:53 +0200 | [diff] [blame] | 890 | diffupdate |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 891 | endfunc |
| 892 | func StopUnified() |
| 893 | set diffexpr= |
| 894 | endfunc |
| 895 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 896 | call writefile(lines, 'XdiffSetup', 'D') |
Bram Moolenaar | 485b627 | 2021-05-18 19:19:03 +0200 | [diff] [blame] | 897 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 898 | " clean up already existing swap files, just in case |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 899 | call delete('.Xdifile1.swp') |
| 900 | call delete('.Xdifile2.swp') |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 901 | |
| 902 | " Test 1: Add a line in beginning of file 2 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 903 | call WriteDiffFiles(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 904 | let buf = RunVimInTerminal('-d -S XdiffSetup Xdifile1 Xdifile2', {}) |
Bram Moolenaar | 8ee4c01 | 2019-03-29 18:08:18 +0100 | [diff] [blame] | 905 | " Set autoread mode, so that Vim won't complain once we re-write the test |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 906 | " files |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 907 | call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w") |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 908 | |
| 909 | call VerifyBoth(buf, 'Test_diff_01', '') |
| 910 | |
| 911 | " Test 2: Add a line in beginning of file 1 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 912 | call WriteDiffFiles(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 913 | call VerifyBoth(buf, 'Test_diff_02', '') |
| 914 | |
| 915 | " Test 3: Add a line at the end of file 2 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 916 | call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 917 | call VerifyBoth(buf, 'Test_diff_03', '') |
| 918 | |
| 919 | " Test 4: Add a line at the end of file 1 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 920 | call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 921 | call VerifyBoth(buf, 'Test_diff_04', '') |
| 922 | |
| 923 | " Test 5: Add a line in the middle of file 2, remove on at the end of file 1 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 924 | call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 925 | call VerifyBoth(buf, 'Test_diff_05', '') |
| 926 | |
| 927 | " Test 6: Add a line in the middle of file 1, remove on at the end of file 2 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 928 | call WriteDiffFiles(buf, [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 929 | call VerifyBoth(buf, 'Test_diff_06', '') |
| 930 | |
Bram Moolenaar | b9ddda6 | 2019-02-19 23:00:50 +0100 | [diff] [blame] | 931 | " Variants on test 6 with different context settings |
| 932 | call term_sendkeys(buf, ":set diffopt+=context:2\<cr>") |
| 933 | call VerifyScreenDump(buf, 'Test_diff_06.2', {}) |
| 934 | call term_sendkeys(buf, ":set diffopt-=context:2\<cr>") |
| 935 | call term_sendkeys(buf, ":set diffopt+=context:1\<cr>") |
| 936 | call VerifyScreenDump(buf, 'Test_diff_06.1', {}) |
| 937 | call term_sendkeys(buf, ":set diffopt-=context:1\<cr>") |
| 938 | call term_sendkeys(buf, ":set diffopt+=context:0\<cr>") |
| 939 | call VerifyScreenDump(buf, 'Test_diff_06.0', {}) |
| 940 | call term_sendkeys(buf, ":set diffopt-=context:0\<cr>") |
| 941 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 942 | " Test 7 - 9: Test normal/patience/histogram diff algorithm |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 943 | call WriteDiffFiles(buf, ['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{', |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 944 | \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");', |
| 945 | \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {', |
| 946 | \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)', |
| 947 | \ '{', ' frobnitz(fact(10));', '}'], |
| 948 | \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {', |
| 949 | \ ' return fib(n-1) + fib(n-2);', ' }', ' return 1;', '}', '', '// Frobs foo heartily', |
| 950 | \ 'int frobnitz(int foo)', '{', ' int i;', ' for(i = 0; i < 10; i++)', ' {', |
| 951 | \ ' printf("%d\n", foo);', ' }', '}', '', |
| 952 | \ 'int main(int argc, char **argv)', '{', ' frobnitz(fib(10));', '}']) |
| 953 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 954 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 955 | call VerifyScreenDump(buf, 'Test_diff_07', {}) |
| 956 | |
| 957 | call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>") |
| 958 | call VerifyScreenDump(buf, 'Test_diff_08', {}) |
| 959 | |
| 960 | call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>") |
| 961 | call VerifyScreenDump(buf, 'Test_diff_09', {}) |
| 962 | |
| 963 | " Test 10-11: normal/indent-heuristic |
| 964 | call term_sendkeys(buf, ":set diffopt&vim\<cr>") |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 965 | call WriteDiffFiles(buf, ['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'], |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 966 | \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '', |
| 967 | \ ' values.each do |v|', ' v.finalize', ' end']) |
| 968 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 969 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 970 | call VerifyScreenDump(buf, 'Test_diff_10', {}) |
| 971 | |
Bram Moolenaar | b6fc728 | 2018-12-04 22:24:16 +0100 | [diff] [blame] | 972 | " Leave trailing : at commandline! |
| 973 | call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>:\<cr>") |
| 974 | call VerifyScreenDump(buf, 'Test_diff_11', {}, 'one') |
| 975 | " shouldn't matter, if indent-algorithm comes before or after the algorithm |
| 976 | call term_sendkeys(buf, ":set diffopt&\<cr>") |
| 977 | call term_sendkeys(buf, ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>") |
| 978 | call VerifyScreenDump(buf, 'Test_diff_11', {}, 'two') |
| 979 | call term_sendkeys(buf, ":set diffopt&\<cr>") |
| 980 | call term_sendkeys(buf, ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>") |
| 981 | call VerifyScreenDump(buf, 'Test_diff_11', {}, 'three') |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 982 | |
| 983 | " Test 12: diff the same file |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 984 | call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 985 | call VerifyBoth(buf, 'Test_diff_12', '') |
| 986 | |
| 987 | " Test 13: diff an empty file |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 988 | call WriteDiffFiles(buf, [], []) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 989 | call VerifyBoth(buf, 'Test_diff_13', '') |
| 990 | |
| 991 | " Test 14: test diffopt+=icase |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 992 | call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe']) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 993 | call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase") |
| 994 | |
| 995 | " Test 15-16: test diffopt+=iwhite |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 996 | call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'], |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 997 | \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}']) |
| 998 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 999 | call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>") |
| 1000 | call VerifyScreenDump(buf, 'Test_diff_15', {}) |
| 1001 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 1002 | call VerifyScreenDump(buf, 'Test_diff_16', {}) |
| 1003 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 1004 | " Test 17: test diffopt+=iblank |
| 1005 | call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy']) |
| 1006 | call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank") |
| 1007 | |
| 1008 | " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol |
| 1009 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite") |
| 1010 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall") |
| 1011 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol") |
| 1012 | |
| 1013 | " Test 19: test diffopt+=iwhiteeol |
| 1014 | call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar']) |
| 1015 | call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol") |
| 1016 | |
| 1017 | " Test 19: test diffopt+=iwhiteall |
| 1018 | call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall") |
| 1019 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 1020 | " clean up |
| 1021 | call StopVimInTerminal(buf) |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1022 | call delete('Xdifile1') |
| 1023 | call delete('Xdifile2') |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 1024 | endfunc |
| 1025 | |
Bram Moolenaar | 04626c2 | 2021-09-01 16:02:07 +0200 | [diff] [blame] | 1026 | func Test_diff_with_scroll_and_change() |
| 1027 | CheckScreendump |
| 1028 | |
| 1029 | let lines =<< trim END |
| 1030 | call setline(1, range(1, 15)) |
| 1031 | vnew |
| 1032 | call setline(1, range(9, 15)) |
| 1033 | windo diffthis |
| 1034 | wincmd h |
| 1035 | exe "normal Gl5\<C-E>" |
| 1036 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1037 | call writefile(lines, 'Xtest_scroll_change', 'D') |
Bram Moolenaar | 04626c2 | 2021-09-01 16:02:07 +0200 | [diff] [blame] | 1038 | let buf = RunVimInTerminal('-S Xtest_scroll_change', {}) |
| 1039 | |
| 1040 | call VerifyScreenDump(buf, 'Test_diff_scroll_change_01', {}) |
| 1041 | |
| 1042 | call term_sendkeys(buf, "ax\<Esc>") |
| 1043 | call VerifyScreenDump(buf, 'Test_diff_scroll_change_02', {}) |
| 1044 | |
Bram Moolenaar | 841c225 | 2021-10-22 20:56:55 +0100 | [diff] [blame] | 1045 | call term_sendkeys(buf, "\<C-W>lay\<Esc>") |
| 1046 | call VerifyScreenDump(buf, 'Test_diff_scroll_change_03', {}) |
| 1047 | |
Bram Moolenaar | 04626c2 | 2021-09-01 16:02:07 +0200 | [diff] [blame] | 1048 | " clean up |
| 1049 | call StopVimInTerminal(buf) |
Bram Moolenaar | 04626c2 | 2021-09-01 16:02:07 +0200 | [diff] [blame] | 1050 | endfunc |
| 1051 | |
Bram Moolenaar | 4a5abbd | 2018-10-02 18:26:10 +0200 | [diff] [blame] | 1052 | func Test_diff_with_cursorline() |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 1053 | CheckScreendump |
Bram Moolenaar | 4a5abbd | 2018-10-02 18:26:10 +0200 | [diff] [blame] | 1054 | |
| 1055 | call writefile([ |
| 1056 | \ 'hi CursorLine ctermbg=red ctermfg=white', |
| 1057 | \ 'set cursorline', |
| 1058 | \ 'call setline(1, ["foo","foo","foo","bar"])', |
| 1059 | \ 'vnew', |
| 1060 | \ 'call setline(1, ["bee","foo","foo","baz"])', |
| 1061 | \ 'windo diffthis', |
| 1062 | \ '2wincmd w', |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1063 | \ ], 'Xtest_diff_cursorline', 'D') |
Bram Moolenaar | 4a5abbd | 2018-10-02 18:26:10 +0200 | [diff] [blame] | 1064 | let buf = RunVimInTerminal('-S Xtest_diff_cursorline', {}) |
| 1065 | |
| 1066 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_01', {}) |
| 1067 | call term_sendkeys(buf, "j") |
| 1068 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_02', {}) |
| 1069 | call term_sendkeys(buf, "j") |
| 1070 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_03', {}) |
| 1071 | |
| 1072 | " clean up |
| 1073 | call StopVimInTerminal(buf) |
Bram Moolenaar | 4a5abbd | 2018-10-02 18:26:10 +0200 | [diff] [blame] | 1074 | endfunc |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1075 | |
Bram Moolenaar | 127969c | 2022-03-06 19:54:13 +0000 | [diff] [blame] | 1076 | func Test_diff_with_cursorline_number() |
| 1077 | CheckScreendump |
| 1078 | |
| 1079 | let lines =<< trim END |
| 1080 | hi CursorLine ctermbg=red ctermfg=white |
| 1081 | hi CursorLineNr ctermbg=white ctermfg=black cterm=underline |
| 1082 | set cursorline number |
| 1083 | call setline(1, ["baz", "foo", "foo", "bar"]) |
| 1084 | 2 |
| 1085 | vnew |
| 1086 | call setline(1, ["foo", "foo", "bar"]) |
| 1087 | windo diffthis |
| 1088 | 1wincmd w |
| 1089 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1090 | call writefile(lines, 'Xtest_diff_cursorline_number', 'D') |
Bram Moolenaar | 127969c | 2022-03-06 19:54:13 +0000 | [diff] [blame] | 1091 | let buf = RunVimInTerminal('-S Xtest_diff_cursorline_number', {}) |
| 1092 | |
| 1093 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_01', {}) |
| 1094 | call term_sendkeys(buf, ":set cursorlineopt=number\r") |
| 1095 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_02', {}) |
| 1096 | |
| 1097 | " clean up |
| 1098 | call StopVimInTerminal(buf) |
Bram Moolenaar | 127969c | 2022-03-06 19:54:13 +0000 | [diff] [blame] | 1099 | endfunc |
| 1100 | |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1101 | func Test_diff_with_cursorline_breakindent() |
| 1102 | CheckScreendump |
| 1103 | |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 1104 | let lines =<< trim END |
| 1105 | hi CursorLine ctermbg=red ctermfg=white |
| 1106 | set noequalalways wrap diffopt=followwrap cursorline breakindent |
| 1107 | 50vnew |
| 1108 | call setline(1, [' ', ' ', ' ', ' ']) |
| 1109 | exe "norm! 20Afoo\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abar\<Esc>" |
| 1110 | vnew |
| 1111 | call setline(1, [' ', ' ', ' ', ' ']) |
| 1112 | exe "norm! 20Abee\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abaz\<Esc>" |
| 1113 | windo diffthis |
| 1114 | 2wincmd w |
| 1115 | END |
| 1116 | call writefile(lines, 'Xtest_diff_cursorline_breakindent', 'D') |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1117 | let buf = RunVimInTerminal('-S Xtest_diff_cursorline_breakindent', {}) |
| 1118 | |
| 1119 | call term_sendkeys(buf, "gg0") |
| 1120 | call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_01', {}) |
| 1121 | call term_sendkeys(buf, "j") |
| 1122 | call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_02', {}) |
| 1123 | call term_sendkeys(buf, "j") |
| 1124 | call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_03', {}) |
| 1125 | call term_sendkeys(buf, "j") |
| 1126 | call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_04', {}) |
| 1127 | |
| 1128 | " clean up |
| 1129 | call StopVimInTerminal(buf) |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1130 | endfunc |
| 1131 | |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 1132 | func Test_diff_breakindent_after_filler() |
| 1133 | CheckScreendump |
| 1134 | |
| 1135 | let lines =<< trim END |
zeertzjq | f0a9d65 | 2024-02-12 22:53:20 +0100 | [diff] [blame] | 1136 | set laststatus=0 diffopt+=followwrap breakindent breakindentopt=min:0 |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 1137 | call setline(1, ['a', ' ' .. repeat('c', 50)]) |
| 1138 | vnew |
| 1139 | call setline(1, ['a', 'b', ' ' .. repeat('c', 50)]) |
| 1140 | windo diffthis |
| 1141 | norm! G$ |
| 1142 | END |
| 1143 | call writefile(lines, 'Xtest_diff_breakindent_after_filler', 'D') |
| 1144 | let buf = RunVimInTerminal('-S Xtest_diff_breakindent_after_filler', #{rows: 8, cols: 45}) |
| 1145 | call VerifyScreenDump(buf, 'Test_diff_breakindent_after_filler', {}) |
| 1146 | |
| 1147 | " clean up |
| 1148 | call StopVimInTerminal(buf) |
| 1149 | endfunc |
| 1150 | |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1151 | func Test_diff_with_syntax() |
| 1152 | CheckScreendump |
| 1153 | |
| 1154 | let lines =<< trim END |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1155 | void doNothing() { |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1156 | int x = 0; |
| 1157 | char *s = "hello"; |
| 1158 | return 5; |
| 1159 | } |
| 1160 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1161 | call writefile(lines, 'Xprogram1.c', 'D') |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1162 | let lines =<< trim END |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1163 | void doSomething() { |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1164 | int x = 0; |
| 1165 | char *s = "there"; |
| 1166 | return 5; |
| 1167 | } |
| 1168 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1169 | call writefile(lines, 'Xprogram2.c', 'D') |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1170 | |
| 1171 | let lines =<< trim END |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1172 | edit Xprogram1.c |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1173 | diffsplit Xprogram2.c |
| 1174 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1175 | call writefile(lines, 'Xtest_diff_syntax', 'D') |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1176 | let buf = RunVimInTerminal('-S Xtest_diff_syntax', {}) |
| 1177 | |
| 1178 | call VerifyScreenDump(buf, 'Test_diff_syntax_1', {}) |
| 1179 | |
| 1180 | " clean up |
| 1181 | call StopVimInTerminal(buf) |
Bram Moolenaar | 248fdb3 | 2019-09-15 19:31:28 +0200 | [diff] [blame] | 1182 | endfunc |
| 1183 | |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1184 | func Test_diff_of_diff() |
Bram Moolenaar | 3c8ee62 | 2019-08-03 22:55:50 +0200 | [diff] [blame] | 1185 | CheckScreendump |
| 1186 | CheckFeature rightleft |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1187 | |
| 1188 | call writefile([ |
| 1189 | \ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])', |
| 1190 | \ 'vnew', |
| 1191 | \ 'call setline(1, ["aa","bb","cc"])', |
| 1192 | \ 'windo diffthis', |
Bram Moolenaar | 8ee4c01 | 2019-03-29 18:08:18 +0100 | [diff] [blame] | 1193 | \ '1wincmd w', |
| 1194 | \ 'setlocal number', |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1195 | \ ], 'Xtest_diff_diff', 'D') |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1196 | let buf = RunVimInTerminal('-S Xtest_diff_diff', {}) |
| 1197 | |
| 1198 | call VerifyScreenDump(buf, 'Test_diff_of_diff_01', {}) |
| 1199 | |
Bram Moolenaar | e73f911 | 2019-03-29 18:29:54 +0100 | [diff] [blame] | 1200 | call term_sendkeys(buf, ":set rightleft\<cr>") |
| 1201 | call VerifyScreenDump(buf, 'Test_diff_of_diff_02', {}) |
| 1202 | |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1203 | " clean up |
| 1204 | call StopVimInTerminal(buf) |
Bram Moolenaar | f7acf2b | 2018-11-01 21:14:53 +0100 | [diff] [blame] | 1205 | endfunc |
Bram Moolenaar | c823477 | 2019-11-10 21:00:27 +0100 | [diff] [blame] | 1206 | |
| 1207 | func CloseoffSetup() |
| 1208 | enew |
| 1209 | call setline(1, ['one', 'two', 'three']) |
| 1210 | diffthis |
| 1211 | new |
| 1212 | call setline(1, ['one', 'tow', 'three']) |
| 1213 | diffthis |
| 1214 | call assert_equal(1, &diff) |
| 1215 | only! |
| 1216 | endfunc |
| 1217 | |
| 1218 | func Test_diff_closeoff() |
| 1219 | " "closeoff" included by default: last diff win gets 'diff' reset' |
| 1220 | call CloseoffSetup() |
| 1221 | call assert_equal(0, &diff) |
| 1222 | enew! |
| 1223 | |
| 1224 | " "closeoff" excluded: last diff win keeps 'diff' set' |
| 1225 | set diffopt-=closeoff |
| 1226 | call CloseoffSetup() |
| 1227 | call assert_equal(1, &diff) |
| 1228 | diffoff! |
| 1229 | enew! |
| 1230 | endfunc |
Bram Moolenaar | f4a1d1c | 2019-11-16 13:50:25 +0100 | [diff] [blame] | 1231 | |
Bram Moolenaar | 4223d43 | 2021-02-10 13:18:17 +0100 | [diff] [blame] | 1232 | func Test_diff_followwrap() |
| 1233 | new |
| 1234 | set diffopt+=followwrap |
| 1235 | set wrap |
| 1236 | diffthis |
| 1237 | call assert_equal(1, &wrap) |
| 1238 | diffoff |
| 1239 | set nowrap |
| 1240 | diffthis |
| 1241 | call assert_equal(0, &wrap) |
| 1242 | diffoff |
| 1243 | set diffopt& |
| 1244 | bwipe! |
| 1245 | endfunc |
| 1246 | |
Bram Moolenaar | f4a1d1c | 2019-11-16 13:50:25 +0100 | [diff] [blame] | 1247 | func Test_diff_maintains_change_mark() |
Sean Dewar | ccc1644 | 2021-12-29 16:44:48 +0000 | [diff] [blame] | 1248 | func DiffMaintainsChangeMark() |
| 1249 | enew! |
| 1250 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1251 | diffthis |
| 1252 | new |
| 1253 | call setline(1, ['a', 'b', 'c', 'e']) |
| 1254 | " Set '[ and '] marks |
| 1255 | 2,3yank |
| 1256 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 1257 | " Verify they aren't affected by the implicit diff |
| 1258 | diffthis |
| 1259 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 1260 | " Verify they aren't affected by an explicit diff |
| 1261 | diffupdate |
| 1262 | call assert_equal([2, 3], [line("'["), line("']")]) |
| 1263 | bwipe! |
| 1264 | bwipe! |
| 1265 | endfunc |
| 1266 | |
| 1267 | set diffopt-=internal |
| 1268 | call DiffMaintainsChangeMark() |
| 1269 | set diffopt+=internal |
| 1270 | call DiffMaintainsChangeMark() |
Bram Moolenaar | d9b74a2 | 2022-01-16 15:00:08 +0000 | [diff] [blame] | 1271 | |
Sean Dewar | ccc1644 | 2021-12-29 16:44:48 +0000 | [diff] [blame] | 1272 | set diffopt& |
Bram Moolenaar | d9b74a2 | 2022-01-16 15:00:08 +0000 | [diff] [blame] | 1273 | delfunc DiffMaintainsChangeMark |
Bram Moolenaar | f4a1d1c | 2019-11-16 13:50:25 +0100 | [diff] [blame] | 1274 | endfunc |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1275 | |
| 1276 | " Test for 'patchexpr' |
| 1277 | func Test_patchexpr() |
| 1278 | let g:patch_args = [] |
| 1279 | func TPatch() |
| 1280 | call add(g:patch_args, readfile(v:fname_in)) |
| 1281 | call add(g:patch_args, readfile(v:fname_diff)) |
| 1282 | call writefile(['output file'], v:fname_out) |
| 1283 | endfunc |
| 1284 | set patchexpr=TPatch() |
| 1285 | |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1286 | call writefile(['input file'], 'Xinput', 'D') |
| 1287 | call writefile(['diff file'], 'Xdiff', 'D') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1288 | %bwipe! |
| 1289 | edit Xinput |
| 1290 | diffpatch Xdiff |
| 1291 | call assert_equal('output file', getline(1)) |
| 1292 | call assert_equal('Xinput.new', bufname()) |
| 1293 | call assert_equal(2, winnr('$')) |
| 1294 | call assert_true(&diff) |
| 1295 | |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 1296 | " Using a script-local function |
| 1297 | func s:NewPatchExpr() |
| 1298 | endfunc |
| 1299 | set patchexpr=s:NewPatchExpr() |
| 1300 | call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr) |
| 1301 | set patchexpr=<SID>NewPatchExpr() |
| 1302 | call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr) |
| 1303 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1304 | set patchexpr& |
| 1305 | delfunc TPatch |
Yegappan Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 1306 | delfunc s:NewPatchExpr |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1307 | %bwipe! |
| 1308 | endfunc |
| 1309 | |
Bram Moolenaar | 511feec | 2020-06-18 19:15:27 +0200 | [diff] [blame] | 1310 | func Test_diff_rnu() |
| 1311 | CheckScreendump |
| 1312 | |
| 1313 | let content =<< trim END |
| 1314 | call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b']) |
| 1315 | vnew |
| 1316 | call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b']) |
| 1317 | windo diffthis |
| 1318 | setlocal number rnu foldcolumn=0 |
| 1319 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1320 | call writefile(content, 'Xtest_diff_rnu', 'D') |
Bram Moolenaar | 511feec | 2020-06-18 19:15:27 +0200 | [diff] [blame] | 1321 | let buf = RunVimInTerminal('-S Xtest_diff_rnu', {}) |
| 1322 | |
| 1323 | call VerifyScreenDump(buf, 'Test_diff_rnu_01', {}) |
| 1324 | |
| 1325 | call term_sendkeys(buf, "j") |
| 1326 | call VerifyScreenDump(buf, 'Test_diff_rnu_02', {}) |
| 1327 | call term_sendkeys(buf, "j") |
| 1328 | call VerifyScreenDump(buf, 'Test_diff_rnu_03', {}) |
| 1329 | |
| 1330 | " clean up |
| 1331 | call StopVimInTerminal(buf) |
Bram Moolenaar | 511feec | 2020-06-18 19:15:27 +0200 | [diff] [blame] | 1332 | endfunc |
| 1333 | |
Bram Moolenaar | fc838d6 | 2020-06-25 22:23:48 +0200 | [diff] [blame] | 1334 | func Test_diff_multilineconceal() |
| 1335 | new |
| 1336 | diffthis |
| 1337 | |
| 1338 | new |
| 1339 | call matchadd('Conceal', 'a\nb', 9, -1, {'conceal': 'Y'}) |
| 1340 | set cole=2 cocu=n |
| 1341 | call setline(1, ["a", "b"]) |
| 1342 | diffthis |
| 1343 | redraw |
| 1344 | endfunc |
| 1345 | |
Bram Moolenaar | 8455c5e | 2020-07-14 21:22:30 +0200 | [diff] [blame] | 1346 | func Test_diff_and_scroll() |
| 1347 | " this was causing an ml_get error |
| 1348 | set ls=2 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1349 | for i in range(winheight(0) * 2) |
| 1350 | call setline(i, i < winheight(0) - 10 ? i : i + 10) |
Bram Moolenaar | 8455c5e | 2020-07-14 21:22:30 +0200 | [diff] [blame] | 1351 | endfor |
| 1352 | vnew |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 1353 | for i in range(winheight(0)*2 + 10) |
| 1354 | call setline(i, i < winheight(0) - 10 ? 0 : i) |
Bram Moolenaar | 8455c5e | 2020-07-14 21:22:30 +0200 | [diff] [blame] | 1355 | endfor |
| 1356 | diffthis |
| 1357 | wincmd p |
| 1358 | diffthis |
| 1359 | execute 'normal ' . winheight(0) . "\<C-d>" |
| 1360 | |
| 1361 | bwipe! |
| 1362 | bwipe! |
| 1363 | set ls& |
| 1364 | endfunc |
| 1365 | |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 1366 | func Test_diff_filler_cursorcolumn() |
| 1367 | CheckScreendump |
| 1368 | |
| 1369 | let content =<< trim END |
| 1370 | call setline(1, ['aa', 'bb', 'cc']) |
| 1371 | vnew |
| 1372 | call setline(1, ['aa', 'cc']) |
| 1373 | windo diffthis |
| 1374 | wincmd p |
| 1375 | setlocal cursorcolumn foldcolumn=0 |
| 1376 | norm! gg0 |
| 1377 | redraw! |
| 1378 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1379 | call writefile(content, 'Xtest_diff_cuc', 'D') |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 1380 | let buf = RunVimInTerminal('-S Xtest_diff_cuc', {}) |
| 1381 | |
| 1382 | call VerifyScreenDump(buf, 'Test_diff_cuc_01', {}) |
| 1383 | |
| 1384 | call term_sendkeys(buf, "l") |
| 1385 | call term_sendkeys(buf, "\<C-l>") |
| 1386 | call VerifyScreenDump(buf, 'Test_diff_cuc_02', {}) |
| 1387 | call term_sendkeys(buf, "0j") |
| 1388 | call term_sendkeys(buf, "\<C-l>") |
| 1389 | call VerifyScreenDump(buf, 'Test_diff_cuc_03', {}) |
| 1390 | call term_sendkeys(buf, "l") |
| 1391 | call term_sendkeys(buf, "\<C-l>") |
| 1392 | call VerifyScreenDump(buf, 'Test_diff_cuc_04', {}) |
| 1393 | |
| 1394 | " clean up |
| 1395 | call StopVimInTerminal(buf) |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 1396 | endfunc |
| 1397 | |
Yegappan Lakshmanan | 3044324 | 2021-06-10 21:52:15 +0200 | [diff] [blame] | 1398 | " Test for adding/removing lines inside diff chunks, between diff chunks |
| 1399 | " and before diff chunks |
| 1400 | func Test_diff_modify_chunks() |
| 1401 | enew! |
| 1402 | let w2_id = win_getid() |
| 1403 | call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) |
| 1404 | new |
| 1405 | let w1_id = win_getid() |
| 1406 | call setline(1, ['a', '2', '3', 'd', 'e', 'f', '7', '8', 'i']) |
| 1407 | windo diffthis |
| 1408 | |
| 1409 | " remove a line between two diff chunks and create a new diff chunk |
| 1410 | call win_gotoid(w2_id) |
| 1411 | 5d |
| 1412 | call win_gotoid(w1_id) |
| 1413 | call diff_hlID(5, 1)->synIDattr('name')->assert_equal('DiffAdd') |
| 1414 | |
| 1415 | " add a line between two diff chunks |
| 1416 | call win_gotoid(w2_id) |
| 1417 | normal! 4Goe |
| 1418 | call win_gotoid(w1_id) |
| 1419 | call diff_hlID(4, 1)->synIDattr('name')->assert_equal('') |
| 1420 | call diff_hlID(5, 1)->synIDattr('name')->assert_equal('') |
| 1421 | |
| 1422 | " remove all the lines in a diff chunk. |
| 1423 | call win_gotoid(w2_id) |
| 1424 | 7,8d |
| 1425 | call win_gotoid(w1_id) |
| 1426 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1427 | call assert_equal(['', 'DiffText', 'DiffText', '', '', '', 'DiffAdd', |
| 1428 | \ 'DiffAdd', ''], hl) |
| 1429 | |
| 1430 | " remove lines from one diff chunk to just before the next diff chunk |
| 1431 | call win_gotoid(w2_id) |
| 1432 | call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) |
| 1433 | 2,6d |
| 1434 | call win_gotoid(w1_id) |
| 1435 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1436 | call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', 'DiffAdd', |
| 1437 | \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) |
| 1438 | |
| 1439 | " remove lines just before the top of a diff chunk |
| 1440 | call win_gotoid(w2_id) |
| 1441 | call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) |
| 1442 | 5,6d |
| 1443 | call win_gotoid(w1_id) |
| 1444 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1445 | call assert_equal(['', 'DiffText', 'DiffText', '', 'DiffText', 'DiffText', |
| 1446 | \ 'DiffAdd', 'DiffAdd', ''], hl) |
| 1447 | |
| 1448 | " remove line after the end of a diff chunk |
| 1449 | call win_gotoid(w2_id) |
| 1450 | call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) |
| 1451 | 4d |
| 1452 | call win_gotoid(w1_id) |
| 1453 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1454 | call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', '', '', 'DiffText', |
| 1455 | \ 'DiffText', ''], hl) |
| 1456 | |
| 1457 | " remove lines starting from the end of one diff chunk and ending inside |
| 1458 | " another diff chunk |
| 1459 | call win_gotoid(w2_id) |
| 1460 | call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']) |
| 1461 | 4,7d |
| 1462 | call win_gotoid(w1_id) |
| 1463 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1464 | call assert_equal(['', 'DiffText', 'DiffText', 'DiffText', 'DiffAdd', |
| 1465 | \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl) |
| 1466 | |
| 1467 | " removing the only remaining diff chunk should make the files equal |
| 1468 | call win_gotoid(w2_id) |
| 1469 | call setline(1, ['a', '2', '3', 'x', 'd', 'e', 'f', 'x', '7', '8', 'i']) |
| 1470 | 8d |
| 1471 | let hl = range(1, 10)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1472 | call assert_equal(['', '', '', 'DiffAdd', '', '', '', '', '', ''], hl) |
| 1473 | call win_gotoid(w2_id) |
| 1474 | 4d |
| 1475 | call win_gotoid(w1_id) |
| 1476 | let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')}) |
| 1477 | call assert_equal(['', '', '', '', '', '', '', '', ''], hl) |
| 1478 | |
| 1479 | %bw! |
| 1480 | endfunc |
glacambre | ad5c178 | 2021-05-24 14:20:53 +0200 | [diff] [blame] | 1481 | |
Bram Moolenaar | 06f6095 | 2021-12-28 18:30:05 +0000 | [diff] [blame] | 1482 | func Test_diff_binary() |
| 1483 | CheckScreendump |
| 1484 | |
| 1485 | let content =<< trim END |
| 1486 | call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g']) |
| 1487 | vnew |
| 1488 | call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g']) |
| 1489 | windo diffthis |
| 1490 | wincmd p |
| 1491 | norm! gg0 |
| 1492 | redraw! |
| 1493 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1494 | call writefile(content, 'Xtest_diff_bin', 'D') |
Bram Moolenaar | 06f6095 | 2021-12-28 18:30:05 +0000 | [diff] [blame] | 1495 | let buf = RunVimInTerminal('-S Xtest_diff_bin', {}) |
| 1496 | |
| 1497 | " Test using internal diff |
| 1498 | call VerifyScreenDump(buf, 'Test_diff_bin_01', {}) |
| 1499 | |
| 1500 | " Test using internal diff and case folding |
| 1501 | call term_sendkeys(buf, ":set diffopt+=icase\<cr>") |
| 1502 | call term_sendkeys(buf, "\<C-l>") |
| 1503 | call VerifyScreenDump(buf, 'Test_diff_bin_02', {}) |
| 1504 | " Test using external diff |
| 1505 | call term_sendkeys(buf, ":set diffopt=filler\<cr>") |
| 1506 | call term_sendkeys(buf, "\<C-l>") |
| 1507 | call VerifyScreenDump(buf, 'Test_diff_bin_03', {}) |
| 1508 | " Test using external diff and case folding |
| 1509 | call term_sendkeys(buf, ":set diffopt=filler,icase\<cr>") |
| 1510 | call term_sendkeys(buf, "\<C-l>") |
| 1511 | call VerifyScreenDump(buf, 'Test_diff_bin_04', {}) |
| 1512 | |
| 1513 | " clean up |
| 1514 | call StopVimInTerminal(buf) |
Bram Moolenaar | 06f6095 | 2021-12-28 18:30:05 +0000 | [diff] [blame] | 1515 | set diffopt&vim |
| 1516 | endfunc |
| 1517 | |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1518 | " Test for using the 'zi' command to invert 'foldenable' in diff windows (test |
| 1519 | " for the issue fixed by patch 6.2.317) |
| 1520 | func Test_diff_foldinvert() |
| 1521 | %bw! |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1522 | edit Xdoffile1 |
| 1523 | new Xdoffile2 |
| 1524 | new Xdoffile3 |
Yegappan Lakshmanan | b0ad2d9 | 2022-01-27 13:16:59 +0000 | [diff] [blame] | 1525 | windo diffthis |
| 1526 | " open a non-diff window |
| 1527 | botright new |
| 1528 | 1wincmd w |
| 1529 | call assert_true(getwinvar(1, '&foldenable')) |
| 1530 | call assert_true(getwinvar(2, '&foldenable')) |
| 1531 | call assert_true(getwinvar(3, '&foldenable')) |
| 1532 | normal zi |
| 1533 | call assert_false(getwinvar(1, '&foldenable')) |
| 1534 | call assert_false(getwinvar(2, '&foldenable')) |
| 1535 | call assert_false(getwinvar(3, '&foldenable')) |
| 1536 | normal zi |
| 1537 | call assert_true(getwinvar(1, '&foldenable')) |
| 1538 | call assert_true(getwinvar(2, '&foldenable')) |
| 1539 | call assert_true(getwinvar(3, '&foldenable')) |
| 1540 | |
| 1541 | " If the current window has 'noscrollbind', then 'zi' should not change |
| 1542 | " 'foldenable' in other windows. |
| 1543 | 1wincmd w |
| 1544 | set noscrollbind |
| 1545 | normal zi |
| 1546 | call assert_false(getwinvar(1, '&foldenable')) |
| 1547 | call assert_true(getwinvar(2, '&foldenable')) |
| 1548 | call assert_true(getwinvar(3, '&foldenable')) |
| 1549 | |
| 1550 | " 'zi' should not change the 'foldenable' for windows with 'noscrollbind' |
| 1551 | 1wincmd w |
| 1552 | set scrollbind |
| 1553 | normal zi |
| 1554 | call setwinvar(2, '&scrollbind', v:false) |
| 1555 | normal zi |
| 1556 | call assert_false(getwinvar(1, '&foldenable')) |
| 1557 | call assert_true(getwinvar(2, '&foldenable')) |
| 1558 | call assert_false(getwinvar(3, '&foldenable')) |
| 1559 | |
| 1560 | %bw! |
| 1561 | set scrollbind& |
| 1562 | endfunc |
| 1563 | |
Bram Moolenaar | a315ce1 | 2022-06-24 12:38:57 +0100 | [diff] [blame] | 1564 | " This was scrolling for 'cursorbind' but 'scrollbind' is more important |
| 1565 | func Test_diff_scroll() |
| 1566 | CheckScreendump |
| 1567 | |
| 1568 | let left =<< trim END |
| 1569 | line 1 |
| 1570 | line 2 |
| 1571 | line 3 |
| 1572 | line 4 |
| 1573 | |
| 1574 | // Common block |
| 1575 | // one |
| 1576 | // containing |
| 1577 | // four lines |
| 1578 | |
| 1579 | // Common block |
| 1580 | // two |
| 1581 | // containing |
| 1582 | // four lines |
| 1583 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1584 | call writefile(left, 'Xleft', 'D') |
Bram Moolenaar | a315ce1 | 2022-06-24 12:38:57 +0100 | [diff] [blame] | 1585 | let right =<< trim END |
| 1586 | line 1 |
| 1587 | line 2 |
| 1588 | line 3 |
| 1589 | line 4 |
| 1590 | |
| 1591 | Lorem |
| 1592 | ipsum |
| 1593 | dolor |
| 1594 | sit |
| 1595 | amet, |
| 1596 | consectetur |
| 1597 | adipiscing |
| 1598 | elit. |
| 1599 | Etiam |
| 1600 | luctus |
| 1601 | lectus |
| 1602 | sodales, |
| 1603 | dictum |
| 1604 | |
| 1605 | // Common block |
| 1606 | // one |
| 1607 | // containing |
| 1608 | // four lines |
| 1609 | |
| 1610 | Vestibulum |
| 1611 | tincidunt |
| 1612 | aliquet |
| 1613 | nulla. |
| 1614 | |
| 1615 | // Common block |
| 1616 | // two |
| 1617 | // containing |
| 1618 | // four lines |
| 1619 | END |
Bram Moolenaar | 5917341 | 2022-09-20 22:01:33 +0100 | [diff] [blame] | 1620 | call writefile(right, 'Xright', 'D') |
Bram Moolenaar | a315ce1 | 2022-06-24 12:38:57 +0100 | [diff] [blame] | 1621 | let buf = RunVimInTerminal('-d Xleft Xright', {'rows': 12}) |
| 1622 | call term_sendkeys(buf, "\<C-W>\<C-W>jjjj") |
| 1623 | call VerifyScreenDump(buf, 'Test_diff_scroll_1', {}) |
| 1624 | call term_sendkeys(buf, "j") |
| 1625 | call VerifyScreenDump(buf, 'Test_diff_scroll_2', {}) |
| 1626 | |
| 1627 | call StopVimInTerminal(buf) |
Bram Moolenaar | a315ce1 | 2022-06-24 12:38:57 +0100 | [diff] [blame] | 1628 | endfunc |
| 1629 | |
Bram Moolenaar | 38d867f | 2023-04-01 19:54:40 +0100 | [diff] [blame] | 1630 | " This was scrolling too many lines. |
| 1631 | func Test_diff_scroll_wrap_on() |
| 1632 | 20new |
| 1633 | 40vsplit |
| 1634 | call setline(1, map(range(1, 9), 'repeat(v:val, 200)')) |
| 1635 | setlocal number diff so=0 |
| 1636 | redraw |
| 1637 | normal! jj |
| 1638 | call assert_equal(1, winsaveview().topline) |
| 1639 | normal! j |
| 1640 | call assert_equal(2, winsaveview().topline) |
zeertzjq | 0583491 | 2023-10-04 20:12:37 +0200 | [diff] [blame] | 1641 | |
| 1642 | bwipe! |
| 1643 | bwipe! |
| 1644 | endfunc |
| 1645 | |
| 1646 | func Test_diff_scroll_many_filler() |
| 1647 | 20new |
| 1648 | vnew |
| 1649 | call setline(1, ['^^^', '^^^', '$$$', '$$$']) |
| 1650 | diffthis |
| 1651 | setlocal scrolloff=0 |
| 1652 | wincmd p |
| 1653 | call setline(1, ['^^^', '^^^'] + repeat(['###'], 41) + ['$$$', '$$$']) |
| 1654 | diffthis |
| 1655 | setlocal scrolloff=0 |
| 1656 | wincmd p |
| 1657 | redraw |
| 1658 | |
| 1659 | " Note: need a redraw after each scroll, otherwise the test always passes. |
| 1660 | normal! G |
| 1661 | redraw |
| 1662 | call assert_equal(3, winsaveview().topline) |
| 1663 | call assert_equal(18, winsaveview().topfill) |
| 1664 | exe "normal! \<C-B>" |
| 1665 | redraw |
| 1666 | call assert_equal(3, winsaveview().topline) |
| 1667 | call assert_equal(19, winsaveview().topfill) |
| 1668 | exe "normal! \<C-B>" |
| 1669 | redraw |
| 1670 | call assert_equal(2, winsaveview().topline) |
| 1671 | call assert_equal(0, winsaveview().topfill) |
| 1672 | exe "normal! \<C-B>" |
| 1673 | redraw |
| 1674 | call assert_equal(1, winsaveview().topline) |
| 1675 | call assert_equal(0, winsaveview().topfill) |
| 1676 | |
Bram Moolenaar | 38d867f | 2023-04-01 19:54:40 +0100 | [diff] [blame] | 1677 | bwipe! |
| 1678 | bwipe! |
| 1679 | endfunc |
| 1680 | |
Bram Moolenaar | cd38bb4 | 2022-06-26 14:04:07 +0100 | [diff] [blame] | 1681 | " This was trying to update diffs for a buffer being closed |
| 1682 | func Test_diff_only() |
| 1683 | silent! lfile |
| 1684 | set diff |
| 1685 | lopen |
| 1686 | norm o |
| 1687 | silent! norm o |
| 1688 | |
| 1689 | set nodiff |
| 1690 | %bwipe! |
| 1691 | endfunc |
| 1692 | |
Bram Moolenaar | c101abf | 2022-06-26 16:53:34 +0100 | [diff] [blame] | 1693 | " This was causing invalid diff block values |
| 1694 | " FIXME: somehow this causes a valgrind error when run directly but not when |
| 1695 | " run as a test. |
| 1696 | func Test_diff_manipulations() |
| 1697 | set diff |
| 1698 | split 0 |
| 1699 | sil! norm R
doobdeuR
doobdeuR
doobdeu |
| 1700 | |
| 1701 | set nodiff |
| 1702 | %bwipe! |
| 1703 | endfunc |
| 1704 | |
Bram Moolenaar | 4e677b9 | 2022-07-28 18:44:27 +0100 | [diff] [blame] | 1705 | " This was causing the line number in the diff block to go below one. |
| 1706 | " FIXME: somehow this causes a valgrind error when run directly but not when |
| 1707 | " run as a test. |
| 1708 | func Test_diff_put_and_undo() |
| 1709 | set diff |
| 1710 | next 0 |
| 1711 | split 00 |
| 1712 | sil! norm o0gguudpo0ggJuudp |
| 1713 | |
| 1714 | bwipe! |
| 1715 | bwipe! |
| 1716 | set nodiff |
| 1717 | endfunc |
| 1718 | |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1719 | " Test for the diff() function |
| 1720 | def Test_diff_func() |
| 1721 | # string is added/removed/modified at the beginning |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1722 | assert_equal("@@ -0,0 +1 @@\n+abc\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1723 | diff(['def'], ['abc', 'def'], {output: 'unified'})) |
| 1724 | assert_equal([{from_idx: 0, from_count: 0, to_idx: 0, to_count: 1}], |
| 1725 | diff(['def'], ['abc', 'def'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1726 | assert_equal("@@ -1 +0,0 @@\n-abc\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1727 | diff(['abc', 'def'], ['def'], {output: 'unified'})) |
| 1728 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 0}], |
| 1729 | diff(['abc', 'def'], ['def'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1730 | assert_equal("@@ -1 +1 @@\n-abc\n+abx\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1731 | diff(['abc', 'def'], ['abx', 'def'], {output: 'unified'})) |
| 1732 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1733 | diff(['abc', 'def'], ['abx', 'def'], {output: 'indices'})) |
| 1734 | |
| 1735 | # string is added/removed/modified at the end |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1736 | assert_equal("@@ -1,0 +2 @@\n+def\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1737 | diff(['abc'], ['abc', 'def'], {output: 'unified'})) |
| 1738 | assert_equal([{from_idx: 1, from_count: 0, to_idx: 1, to_count: 1}], |
| 1739 | diff(['abc'], ['abc', 'def'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1740 | assert_equal("@@ -2 +1,0 @@\n-def\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1741 | diff(['abc', 'def'], ['abc'], {output: 'unified'})) |
| 1742 | assert_equal([{from_idx: 1, from_count: 1, to_idx: 1, to_count: 0}], |
| 1743 | diff(['abc', 'def'], ['abc'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1744 | assert_equal("@@ -2 +2 @@\n-def\n+xef\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1745 | diff(['abc', 'def'], ['abc', 'xef'], {output: 'unified'})) |
| 1746 | assert_equal([{from_idx: 1, from_count: 1, to_idx: 1, to_count: 1}], |
| 1747 | diff(['abc', 'def'], ['abc', 'xef'], {output: 'indices'})) |
| 1748 | |
| 1749 | # string is added/removed/modified in the middle |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1750 | assert_equal("@@ -2,0 +3 @@\n+xxx\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1751 | diff(['111', '222', '333'], ['111', '222', 'xxx', '333'], {output: 'unified'})) |
| 1752 | assert_equal([{from_idx: 2, from_count: 0, to_idx: 2, to_count: 1}], |
| 1753 | diff(['111', '222', '333'], ['111', '222', 'xxx', '333'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1754 | assert_equal("@@ -3 +2,0 @@\n-333\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1755 | diff(['111', '222', '333', '444'], ['111', '222', '444'], {output: 'unified'})) |
| 1756 | assert_equal([{from_idx: 2, from_count: 1, to_idx: 2, to_count: 0}], |
| 1757 | diff(['111', '222', '333', '444'], ['111', '222', '444'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1758 | assert_equal("@@ -3 +3 @@\n-333\n+xxx\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1759 | diff(['111', '222', '333', '444'], ['111', '222', 'xxx', '444'], {output: 'unified'})) |
| 1760 | assert_equal([{from_idx: 2, from_count: 1, to_idx: 2, to_count: 1}], |
| 1761 | diff(['111', '222', '333', '444'], ['111', '222', 'xxx', '444'], {output: 'indices'})) |
| 1762 | |
| 1763 | # new strings are added to an empty List |
| 1764 | assert_equal("@@ -0,0 +1,2 @@\n+abc\n+def\n", |
| 1765 | diff([], ['abc', 'def'], {output: 'unified'})) |
| 1766 | assert_equal([{from_idx: 0, from_count: 0, to_idx: 0, to_count: 2}], |
| 1767 | diff([], ['abc', 'def'], {output: 'indices'})) |
| 1768 | |
| 1769 | # all the strings are removed from a List |
| 1770 | assert_equal("@@ -1,2 +0,0 @@\n-abc\n-def\n", |
| 1771 | diff(['abc', 'def'], [], {output: 'unified'})) |
| 1772 | assert_equal([{from_idx: 0, from_count: 2, to_idx: 0, to_count: 0}], |
| 1773 | diff(['abc', 'def'], [], {output: 'indices'})) |
| 1774 | |
| 1775 | # First character is added/removed/different |
| 1776 | assert_equal("@@ -1 +1 @@\n-abc\n+bc\n", |
| 1777 | diff(['abc'], ['bc'], {output: 'unified'})) |
| 1778 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1779 | diff(['abc'], ['bc'], {output: 'indices'})) |
| 1780 | assert_equal("@@ -1 +1 @@\n-bc\n+abc\n", |
| 1781 | diff(['bc'], ['abc'], {output: 'unified'})) |
| 1782 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1783 | diff(['bc'], ['abc'], {output: 'indices'})) |
| 1784 | assert_equal("@@ -1 +1 @@\n-abc\n+xbc\n", |
| 1785 | diff(['abc'], ['xbc'], {output: 'unified'})) |
| 1786 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1787 | diff(['abc'], ['xbc'], {output: 'indices'})) |
| 1788 | |
| 1789 | # Last character is added/removed/different |
| 1790 | assert_equal("@@ -1 +1 @@\n-abc\n+abcd\n", |
| 1791 | diff(['abc'], ['abcd'], {output: 'unified'})) |
| 1792 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1793 | diff(['abc'], ['abcd'], {output: 'indices'})) |
| 1794 | assert_equal("@@ -1 +1 @@\n-abcd\n+abc\n", |
| 1795 | diff(['abcd'], ['abc'], {output: 'unified'})) |
| 1796 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1797 | diff(['abcd'], ['abc'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1798 | var diff_unified: string = diff(['abc'], ['abx'], {output: 'unified'}) |
| 1799 | assert_equal("@@ -1 +1 @@\n-abc\n+abx\n", diff_unified) |
| 1800 | var diff_indices: list<dict<number>> = |
| 1801 | diff(['abc'], ['abx'], {output: 'indices'}) |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1802 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1803 | diff_indices) |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1804 | |
| 1805 | # partial string modification at the start and at the end. |
| 1806 | var fromlist =<< trim END |
| 1807 | one two |
| 1808 | three four |
| 1809 | five six |
| 1810 | END |
| 1811 | var tolist =<< trim END |
| 1812 | one |
| 1813 | six |
| 1814 | END |
| 1815 | assert_equal("@@ -1,3 +1,2 @@\n-one two\n-three four\n-five six\n+one\n+six\n", diff(fromlist, tolist, {output: 'unified'})) |
| 1816 | assert_equal([{from_idx: 0, from_count: 3, to_idx: 0, to_count: 2}], |
| 1817 | diff(fromlist, tolist, {output: 'indices'})) |
| 1818 | |
| 1819 | # non-contiguous modifications |
| 1820 | fromlist =<< trim END |
| 1821 | one two |
| 1822 | three four |
| 1823 | five abc six |
| 1824 | END |
| 1825 | tolist =<< trim END |
| 1826 | one abc two |
| 1827 | three four |
| 1828 | five six |
| 1829 | END |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1830 | assert_equal("@@ -1 +1 @@\n-one two\n+one abc two\n@@ -3 +3 @@\n-five abc six\n+five six\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1831 | diff(fromlist, tolist, {output: 'unified'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1832 | assert_equal([{'from_count': 1, 'to_idx': 0, 'to_count': 1, 'from_idx': 0}, |
| 1833 | {'from_count': 1, 'to_idx': 2, 'to_count': 1, 'from_idx': 2}], |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1834 | diff(fromlist, tolist, {output: 'indices'})) |
| 1835 | |
| 1836 | # add/remove blank lines |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1837 | assert_equal("@@ -2,2 +1,0 @@\n-\n-\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1838 | diff(['one', '', '', 'two'], ['one', 'two'], {output: 'unified'})) |
| 1839 | assert_equal([{from_idx: 1, from_count: 2, to_idx: 1, to_count: 0}], |
| 1840 | diff(['one', '', '', 'two'], ['one', 'two'], {output: 'indices'})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1841 | assert_equal("@@ -1,0 +2,2 @@\n+\n+\n", |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1842 | diff(['one', 'two'], ['one', '', '', 'two'], {output: 'unified'})) |
| 1843 | assert_equal([{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}], |
| 1844 | diff(['one', 'two'], ['one', '', '', 'two'], {output: 'indices'})) |
| 1845 | |
| 1846 | # diff ignoring case |
| 1847 | assert_equal('', diff(['abc', 'def'], ['ABC', 'DEF'], {icase: true, output: 'unified'})) |
| 1848 | assert_equal([], diff(['abc', 'def'], ['ABC', 'DEF'], {icase: true, output: 'indices'})) |
| 1849 | |
| 1850 | # diff ignoring all whitespace changes except leading whitespace changes |
| 1851 | assert_equal('', diff(['abc def'], ['abc def '], {iwhite: true})) |
| 1852 | assert_equal("@@ -1 +1 @@\n- abc\n+ xxx\n", diff([' abc'], [' xxx'], {iwhite: v:true})) |
| 1853 | assert_equal("@@ -1 +1 @@\n- abc\n+ xxx\n", diff([' abc'], [' xxx'], {iwhite: v:false})) |
| 1854 | assert_equal("@@ -1 +1 @@\n-abc \n+xxx \n", diff(['abc '], ['xxx '], {iwhite: v:true})) |
| 1855 | assert_equal("@@ -1 +1 @@\n-abc \n+xxx \n", diff(['abc '], ['xxx '], {iwhite: v:false})) |
| 1856 | |
| 1857 | # diff ignoring all whitespace changes |
| 1858 | assert_equal('', diff(['abc def'], [' abc def '], {iwhiteall: true})) |
| 1859 | assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", diff([' abc '], [' xxx '], {iwhiteall: v:true})) |
| 1860 | assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", diff([' abc '], [' xxx '], {iwhiteall: v:false})) |
| 1861 | |
| 1862 | # diff ignoring trailing whitespace changes |
| 1863 | assert_equal('', diff(['abc'], ['abc '], {iwhiteeol: true})) |
| 1864 | |
| 1865 | # diff ignoring blank lines |
| 1866 | assert_equal('', diff(['one', '', '', 'two'], ['one', 'two'], {iblank: true})) |
| 1867 | assert_equal('', diff(['one', 'two'], ['one', '', '', 'two'], {iblank: true})) |
| 1868 | |
| 1869 | # same string |
| 1870 | assert_equal('', diff(['abc', 'def', 'ghi'], ['abc', 'def', 'ghi'])) |
| 1871 | assert_equal('', diff([''], [''])) |
| 1872 | assert_equal('', diff([], [])) |
| 1873 | |
| 1874 | # different xdiff algorithms |
| 1875 | for algo in ['myers', 'minimal', 'patience', 'histogram'] |
| 1876 | assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", |
| 1877 | diff([' abc '], [' xxx '], {algorithm: algo, output: 'unified'})) |
| 1878 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1879 | diff([' abc '], [' xxx '], {algorithm: algo, output: 'indices'})) |
| 1880 | endfor |
| 1881 | assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", |
| 1882 | diff([' abc '], [' xxx '], {indent-heuristic: true, output: 'unified'})) |
| 1883 | assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}], |
| 1884 | diff([' abc '], [' xxx '], {indent-heuristic: true, output: 'indices'})) |
| 1885 | |
| 1886 | # identical strings |
| 1887 | assert_equal('', diff(['111', '222'], ['111', '222'], {output: 'unified'})) |
| 1888 | assert_equal([], diff(['111', '222'], ['111', '222'], {output: 'indices'})) |
| 1889 | assert_equal('', diff([], [], {output: 'unified'})) |
| 1890 | assert_equal([], diff([], [], {output: 'indices'})) |
| 1891 | |
Yegappan Lakshmanan | be156a3 | 2024-02-11 17:08:29 +0100 | [diff] [blame] | 1892 | # If 'diffexpr' is set, it should not be used for diff() |
| 1893 | def MyDiffExpr() |
| 1894 | enddef |
| 1895 | var save_diffexpr = &diffexpr |
| 1896 | :set diffexpr=MyDiffExpr() |
| 1897 | assert_equal("@@ -1 +1 @@\n-abc\n+\n", |
| 1898 | diff(['abc'], [''], {output: 'unified'})) |
| 1899 | assert_equal([{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}], |
| 1900 | diff(['abc'], [''], {output: 'indices'})) |
| 1901 | assert_equal('MyDiffExpr()', &diffexpr) |
| 1902 | &diffexpr = save_diffexpr |
| 1903 | |
| 1904 | # try different values for unified diff 'context' |
| 1905 | assert_equal("@@ -0,0 +1 @@\n+x\n", |
| 1906 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'])) |
| 1907 | assert_equal("@@ -0,0 +1 @@\n+x\n", |
| 1908 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 0})) |
| 1909 | assert_equal("@@ -1 +1,2 @@\n+x\n a\n", |
| 1910 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 1})) |
| 1911 | assert_equal("@@ -1,2 +1,3 @@\n+x\n a\n b\n", |
| 1912 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 2})) |
| 1913 | assert_equal("@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n", |
| 1914 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 3})) |
| 1915 | assert_equal("@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n", |
| 1916 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 4})) |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1917 | assert_equal("@@ -0,0 +1 @@\n+x\n", |
Yegappan Lakshmanan | be156a3 | 2024-02-11 17:08:29 +0100 | [diff] [blame] | 1918 | diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: -1})) |
| 1919 | |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1920 | # Error cases |
| 1921 | assert_fails('call diff({}, ["a"])', 'E1211:') |
| 1922 | assert_fails('call diff(["a"], {})', 'E1211:') |
| 1923 | assert_fails('call diff(["a"], ["a"], [])', 'E1206:') |
| 1924 | assert_fails('call diff(["a"], ["a"], {output: "xyz"})', 'E106: Unsupported diff output format: xyz') |
Yegappan Lakshmanan | be156a3 | 2024-02-11 17:08:29 +0100 | [diff] [blame] | 1925 | assert_fails('call diff(["a"], ["a"], {context: []})', 'E745: Using a List as a Number') |
Yegappan Lakshmanan | fa37835 | 2024-02-01 22:05:27 +0100 | [diff] [blame] | 1926 | enddef |
Bram Moolenaar | a315ce1 | 2022-06-24 12:38:57 +0100 | [diff] [blame] | 1927 | |
Yegappan Lakshmanan | a0010a1 | 2024-02-12 20:21:26 +0100 | [diff] [blame] | 1928 | " Test for using the diff() function with 'diffexpr' |
| 1929 | func Test_diffexpr_with_diff_func() |
| 1930 | CheckScreendump |
| 1931 | |
| 1932 | let lines =<< trim END |
| 1933 | def DiffFuncExpr() |
| 1934 | var in: list<string> = readfile(v:fname_in) |
| 1935 | var new: list<string> = readfile(v:fname_new) |
| 1936 | var out: string = diff(in, new) |
| 1937 | writefile(split(out, "\n"), v:fname_out) |
| 1938 | enddef |
| 1939 | set diffexpr=DiffFuncExpr() |
| 1940 | |
| 1941 | edit Xdifffunc1.txt |
| 1942 | diffthis |
| 1943 | vert split Xdifffunc2.txt |
| 1944 | diffthis |
| 1945 | END |
| 1946 | call writefile(lines, 'XsetupDiffFunc.vim', 'D') |
| 1947 | |
| 1948 | call writefile(['zero', 'one', 'two', 'three'], 'Xdifffunc1.txt', 'D') |
| 1949 | call writefile(['one', 'twox', 'three', 'four'], 'Xdifffunc2.txt', 'D') |
| 1950 | |
| 1951 | let buf = RunVimInTerminal('-S XsetupDiffFunc.vim', {'rows': 12}) |
| 1952 | call VerifyScreenDump(buf, 'Test_difffunc_diffexpr_1', {}) |
| 1953 | call StopVimInTerminal(buf) |
| 1954 | endfunc |
| 1955 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1956 | " vim: shiftwidth=2 sts=2 expandtab |