Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 1 | " Tests for diff mode |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 2 | source shared.vim |
| 3 | source screendump.vim |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 4 | |
| 5 | func Test_diff_fold_sync() |
| 6 | enew! |
Bram Moolenaar | e8fa05b | 2018-09-16 15:48:06 +0200 | [diff] [blame] | 7 | let g:update_count = 0 |
| 8 | au DiffUpdated * let g:update_count += 1 |
| 9 | |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 10 | let l = range(50) |
| 11 | call setline(1, l) |
| 12 | diffthis |
| 13 | let winone = win_getid() |
| 14 | new |
| 15 | let l[25] = 'diff' |
| 16 | call setline(1, l) |
| 17 | diffthis |
| 18 | let wintwo = win_getid() |
| 19 | " line 15 is inside the closed fold |
| 20 | call assert_equal(19, foldclosedend(10)) |
| 21 | call win_gotoid(winone) |
| 22 | call assert_equal(19, foldclosedend(10)) |
| 23 | " open the fold |
| 24 | normal zv |
| 25 | call assert_equal(-1, foldclosedend(10)) |
| 26 | " fold in other window must have opened too |
| 27 | call win_gotoid(wintwo) |
| 28 | call assert_equal(-1, foldclosedend(10)) |
| 29 | |
| 30 | " cursor position is in sync |
| 31 | normal 23G |
| 32 | call win_gotoid(winone) |
| 33 | call assert_equal(23, getcurpos()[1]) |
| 34 | |
Bram Moolenaar | e8fa05b | 2018-09-16 15:48:06 +0200 | [diff] [blame] | 35 | call assert_equal(1, g:update_count) |
| 36 | au! DiffUpdated |
| 37 | |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 38 | windo diffoff |
| 39 | close! |
| 40 | set nomodified |
| 41 | endfunc |
| 42 | |
| 43 | func Test_vert_split() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 44 | set diffopt=filler |
| 45 | call Common_vert_split() |
| 46 | set diffopt& |
| 47 | endfunc |
| 48 | |
| 49 | func Test_vert_split_internal() |
| 50 | set diffopt=internal,filler |
| 51 | call Common_vert_split() |
| 52 | set diffopt& |
| 53 | endfunc |
| 54 | |
| 55 | func Common_vert_split() |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 56 | " Disable the title to avoid xterm keeping the wrong one. |
| 57 | set notitle noicon |
| 58 | new |
| 59 | let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee'] |
| 60 | call setline(1, l) |
| 61 | w! Xtest |
| 62 | normal dd |
| 63 | $ |
| 64 | put |
| 65 | normal kkrXoxxx |
| 66 | w! Xtest2 |
| 67 | file Nop |
| 68 | normal ggoyyyjjjozzzz |
| 69 | set foldmethod=marker foldcolumn=4 |
| 70 | call assert_equal(0, &diff) |
| 71 | call assert_equal('marker', &foldmethod) |
| 72 | call assert_equal(4, &foldcolumn) |
| 73 | call assert_equal(0, &scrollbind) |
| 74 | call assert_equal(0, &cursorbind) |
| 75 | call assert_equal(1, &wrap) |
| 76 | |
| 77 | vert diffsplit Xtest |
| 78 | vert diffsplit Xtest2 |
| 79 | call assert_equal(1, &diff) |
| 80 | call assert_equal('diff', &foldmethod) |
| 81 | call assert_equal(2, &foldcolumn) |
| 82 | call assert_equal(1, &scrollbind) |
| 83 | call assert_equal(1, &cursorbind) |
| 84 | call assert_equal(0, &wrap) |
| 85 | |
| 86 | let diff_fdm = &fdm |
| 87 | let diff_fdc = &fdc |
| 88 | " repeat entering diff mode here to see if this saves the wrong settings |
| 89 | diffthis |
| 90 | " jump to second window for a moment to have filler line appear at start of |
| 91 | " first window |
| 92 | wincmd w |
| 93 | normal gg |
| 94 | wincmd p |
| 95 | normal gg |
| 96 | call assert_equal(2, winline()) |
| 97 | normal j |
| 98 | call assert_equal(4, winline()) |
| 99 | normal j |
| 100 | call assert_equal(5, winline()) |
| 101 | normal j |
| 102 | call assert_equal(6, winline()) |
| 103 | normal j |
| 104 | call assert_equal(8, winline()) |
| 105 | normal j |
| 106 | call assert_equal(9, winline()) |
| 107 | |
| 108 | wincmd w |
| 109 | normal gg |
| 110 | call assert_equal(1, winline()) |
| 111 | normal j |
| 112 | call assert_equal(2, winline()) |
| 113 | normal j |
| 114 | call assert_equal(4, winline()) |
| 115 | normal j |
| 116 | call assert_equal(5, winline()) |
| 117 | normal j |
| 118 | call assert_equal(8, winline()) |
| 119 | |
| 120 | wincmd w |
| 121 | normal gg |
| 122 | call assert_equal(2, winline()) |
| 123 | normal j |
| 124 | call assert_equal(3, winline()) |
| 125 | normal j |
| 126 | call assert_equal(4, winline()) |
| 127 | normal j |
| 128 | call assert_equal(5, winline()) |
| 129 | normal j |
| 130 | call assert_equal(6, winline()) |
| 131 | normal j |
| 132 | call assert_equal(7, winline()) |
| 133 | normal j |
| 134 | call assert_equal(8, winline()) |
| 135 | |
| 136 | " Test diffoff |
| 137 | diffoff! |
| 138 | 1wincmd 2 |
| 139 | let &diff = 1 |
| 140 | let &fdm = diff_fdm |
| 141 | let &fdc = diff_fdc |
| 142 | 4wincmd w |
| 143 | diffoff! |
| 144 | 1wincmd w |
| 145 | call assert_equal(0, &diff) |
| 146 | call assert_equal('marker', &foldmethod) |
| 147 | call assert_equal(4, &foldcolumn) |
| 148 | call assert_equal(0, &scrollbind) |
| 149 | call assert_equal(0, &cursorbind) |
| 150 | call assert_equal(1, &wrap) |
| 151 | |
| 152 | wincmd w |
| 153 | call assert_equal(0, &diff) |
| 154 | call assert_equal('marker', &foldmethod) |
| 155 | call assert_equal(4, &foldcolumn) |
| 156 | call assert_equal(0, &scrollbind) |
| 157 | call assert_equal(0, &cursorbind) |
| 158 | call assert_equal(1, &wrap) |
| 159 | |
| 160 | wincmd w |
| 161 | call assert_equal(0, &diff) |
| 162 | call assert_equal('marker', &foldmethod) |
| 163 | call assert_equal(4, &foldcolumn) |
| 164 | call assert_equal(0, &scrollbind) |
| 165 | call assert_equal(0, &cursorbind) |
| 166 | call assert_equal(1, &wrap) |
| 167 | |
Bram Moolenaar | 623cf88 | 2016-07-30 16:36:01 +0200 | [diff] [blame] | 168 | call delete('Xtest') |
| 169 | call delete('Xtest2') |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 170 | windo bw! |
| 171 | endfunc |
| 172 | |
| 173 | func Test_filler_lines() |
| 174 | " Test that diffing shows correct filler lines |
| 175 | enew! |
| 176 | put =range(4,10) |
| 177 | 1d _ |
| 178 | vnew |
| 179 | put =range(1,10) |
| 180 | 1d _ |
| 181 | windo diffthis |
| 182 | wincmd h |
| 183 | call assert_equal(1, line('w0')) |
| 184 | unlet! diff_fdm diff_fdc |
Bram Moolenaar | 90d121f | 2016-07-30 19:11:25 +0200 | [diff] [blame] | 185 | windo diffoff |
| 186 | bwipe! |
| 187 | enew! |
| 188 | endfunc |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 189 | |
Bram Moolenaar | 90d121f | 2016-07-30 19:11:25 +0200 | [diff] [blame] | 190 | func Test_diffget_diffput() |
| 191 | enew! |
| 192 | let l = range(50) |
| 193 | call setline(1, l) |
| 194 | call assert_fails('diffget', 'E99:') |
| 195 | diffthis |
| 196 | call assert_fails('diffget', 'E100:') |
| 197 | new |
| 198 | let l[10] = 'one' |
| 199 | let l[20] = 'two' |
| 200 | let l[30] = 'three' |
| 201 | let l[40] = 'four' |
| 202 | call setline(1, l) |
| 203 | diffthis |
| 204 | call assert_equal('one', getline(11)) |
| 205 | 11diffget |
| 206 | call assert_equal('10', getline(11)) |
| 207 | 21diffput |
| 208 | wincmd w |
| 209 | call assert_equal('two', getline(21)) |
| 210 | normal 31Gdo |
| 211 | call assert_equal('three', getline(31)) |
| 212 | call assert_equal('40', getline(41)) |
| 213 | normal 41Gdp |
| 214 | wincmd w |
| 215 | call assert_equal('40', getline(41)) |
| 216 | new |
| 217 | diffthis |
| 218 | call assert_fails('diffget', 'E101:') |
| 219 | |
| 220 | windo diffoff |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 221 | %bwipe! |
| 222 | endfunc |
| 223 | |
Bram Moolenaar | 5f57bdc | 2018-10-25 17:52:23 +0200 | [diff] [blame] | 224 | " Test putting two changes from one buffer to another |
| 225 | func Test_diffput_two() |
| 226 | new a |
| 227 | let win_a = win_getid() |
| 228 | call setline(1, range(1, 10)) |
| 229 | diffthis |
| 230 | new b |
| 231 | let win_b = win_getid() |
| 232 | call setline(1, range(1, 10)) |
| 233 | 8del |
| 234 | 5del |
| 235 | diffthis |
| 236 | call win_gotoid(win_a) |
| 237 | %diffput |
| 238 | call win_gotoid(win_b) |
| 239 | call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$')) |
| 240 | bwipe! a |
| 241 | bwipe! b |
| 242 | endfunc |
| 243 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 244 | func Test_dp_do_buffer() |
| 245 | e! one |
| 246 | let bn1=bufnr('%') |
| 247 | let l = range(60) |
| 248 | call setline(1, l) |
| 249 | diffthis |
| 250 | |
| 251 | new two |
| 252 | let l[10] = 'one' |
| 253 | let l[20] = 'two' |
| 254 | let l[30] = 'three' |
| 255 | let l[40] = 'four' |
| 256 | let l[50] = 'five' |
| 257 | call setline(1, l) |
| 258 | diffthis |
| 259 | |
| 260 | " dp and do with invalid buffer number. |
| 261 | 11 |
| 262 | call assert_fails('norm 99999dp', 'E102:') |
| 263 | call assert_fails('norm 99999do', 'E102:') |
| 264 | call assert_fails('diffput non_existing_buffer', 'E94:') |
| 265 | call assert_fails('diffget non_existing_buffer', 'E94:') |
| 266 | |
| 267 | " dp and do with valid buffer number. |
| 268 | call assert_equal('one', getline('.')) |
| 269 | exe 'norm ' . bn1 . 'do' |
| 270 | call assert_equal('10', getline('.')) |
| 271 | 21 |
| 272 | call assert_equal('two', getline('.')) |
| 273 | diffget one |
| 274 | call assert_equal('20', getline('.')) |
| 275 | |
| 276 | 31 |
| 277 | exe 'norm ' . bn1 . 'dp' |
| 278 | 41 |
| 279 | diffput one |
| 280 | wincmd w |
| 281 | 31 |
| 282 | call assert_equal('three', getline('.')) |
| 283 | 41 |
| 284 | call assert_equal('four', getline('.')) |
| 285 | |
| 286 | " dp and do with buffer number which is not in diff mode. |
| 287 | new not_in_diff_mode |
| 288 | let bn3=bufnr('%') |
| 289 | wincmd w |
| 290 | 51 |
| 291 | call assert_fails('exe "norm" . bn3 . "dp"', 'E103:') |
| 292 | call assert_fails('exe "norm" . bn3 . "do"', 'E103:') |
| 293 | call assert_fails('diffput not_in_diff_mode', 'E94:') |
| 294 | call assert_fails('diffget not_in_diff_mode', 'E94:') |
| 295 | |
| 296 | windo diffoff |
| 297 | %bwipe! |
Bram Moolenaar | 42093c0 | 2016-07-30 16:16:54 +0200 | [diff] [blame] | 298 | endfunc |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 299 | |
Bram Moolenaar | df77cef | 2018-10-07 17:46:42 +0200 | [diff] [blame] | 300 | func Test_do_lastline() |
| 301 | e! one |
| 302 | call setline(1, ['1','2','3','4','5','6']) |
| 303 | diffthis |
| 304 | |
| 305 | new two |
| 306 | call setline(1, ['2','4','5']) |
| 307 | diffthis |
| 308 | |
| 309 | 1 |
| 310 | norm dp]c |
| 311 | norm dp]c |
| 312 | wincmd w |
| 313 | call assert_equal(4, line('$')) |
| 314 | norm G |
| 315 | norm do |
| 316 | call assert_equal(3, line('$')) |
| 317 | |
| 318 | windo diffoff |
| 319 | %bwipe! |
| 320 | endfunc |
| 321 | |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 322 | func Test_diffoff() |
| 323 | enew! |
| 324 | call setline(1, ['Two', 'Three']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 325 | redraw |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 326 | let normattr = screenattr(1, 1) |
| 327 | diffthis |
| 328 | botright vert new |
| 329 | call setline(1, ['One', '', 'Two', 'Three']) |
| 330 | diffthis |
| 331 | redraw |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 332 | call assert_notequal(normattr, screenattr(1, 1)) |
Bram Moolenaar | e67d546 | 2016-08-27 22:40:42 +0200 | [diff] [blame] | 333 | diffoff! |
| 334 | redraw |
| 335 | call assert_equal(normattr, screenattr(1, 1)) |
| 336 | bwipe! |
| 337 | bwipe! |
| 338 | endfunc |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 339 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 340 | func Common_icase_test() |
| 341 | edit one |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 342 | call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 343 | redraw |
| 344 | let normattr = screenattr(1, 1) |
| 345 | diffthis |
| 346 | |
| 347 | botright vert new two |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 348 | call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 349 | diffthis |
| 350 | |
| 351 | redraw |
| 352 | call assert_equal(normattr, screenattr(1, 1)) |
| 353 | call assert_equal(normattr, screenattr(2, 1)) |
| 354 | call assert_notequal(normattr, screenattr(3, 1)) |
| 355 | call assert_equal(normattr, screenattr(4, 1)) |
| 356 | |
Bram Moolenaar | da22b8c | 2017-09-02 18:01:50 +0200 | [diff] [blame] | 357 | let dtextattr = screenattr(5, 3) |
| 358 | call assert_notequal(dtextattr, screenattr(5, 1)) |
| 359 | call assert_notequal(dtextattr, screenattr(5, 5)) |
| 360 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 361 | diffoff! |
| 362 | %bwipe! |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 363 | endfunc |
| 364 | |
| 365 | func Test_diffopt_icase() |
| 366 | set diffopt=icase,foldcolumn:0 |
| 367 | call Common_icase_test() |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 368 | set diffopt& |
| 369 | endfunc |
| 370 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 371 | func Test_diffopt_icase_internal() |
| 372 | set diffopt=icase,foldcolumn:0,internal |
| 373 | call Common_icase_test() |
| 374 | set diffopt& |
| 375 | endfunc |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 376 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 377 | func Common_iwhite_test() |
| 378 | edit one |
| 379 | " Difference in trailing spaces and amount of spaces should be ignored, |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 380 | " but not other space differences. |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 381 | call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 382 | redraw |
| 383 | let normattr = screenattr(1, 1) |
| 384 | diffthis |
| 385 | |
| 386 | botright vert new two |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 387 | call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 388 | diffthis |
| 389 | |
| 390 | redraw |
| 391 | call assert_equal(normattr, screenattr(1, 1)) |
| 392 | call assert_equal(normattr, screenattr(2, 1)) |
| 393 | call assert_equal(normattr, screenattr(3, 1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 394 | call assert_equal(normattr, screenattr(4, 1)) |
| 395 | call assert_notequal(normattr, screenattr(5, 1)) |
| 396 | call assert_notequal(normattr, screenattr(6, 1)) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 397 | |
| 398 | diffoff! |
| 399 | %bwipe! |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 400 | endfunc |
| 401 | |
| 402 | func Test_diffopt_iwhite() |
| 403 | set diffopt=iwhite,foldcolumn:0 |
| 404 | call Common_iwhite_test() |
| 405 | set diffopt& |
| 406 | endfunc |
| 407 | |
| 408 | func Test_diffopt_iwhite_internal() |
| 409 | set diffopt=internal,iwhite,foldcolumn:0 |
| 410 | call Common_iwhite_test() |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 411 | set diffopt& |
| 412 | endfunc |
| 413 | |
| 414 | func Test_diffopt_context() |
| 415 | enew! |
| 416 | call setline(1, ['1', '2', '3', '4', '5', '6', '7']) |
| 417 | diffthis |
| 418 | new |
| 419 | call setline(1, ['1', '2', '3', '4', '5x', '6', '7']) |
| 420 | diffthis |
| 421 | |
| 422 | set diffopt=context:2 |
| 423 | call assert_equal('+-- 2 lines: 1', foldtextresult(1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 424 | set diffopt=internal,context:2 |
| 425 | call assert_equal('+-- 2 lines: 1', foldtextresult(1)) |
| 426 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 427 | set diffopt=context:1 |
| 428 | call assert_equal('+-- 3 lines: 1', foldtextresult(1)) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 429 | set diffopt=internal,context:1 |
| 430 | call assert_equal('+-- 3 lines: 1', foldtextresult(1)) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 431 | |
| 432 | diffoff! |
| 433 | %bwipe! |
| 434 | set diffopt& |
| 435 | endfunc |
| 436 | |
| 437 | func Test_diffopt_horizontal() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 438 | set diffopt=internal,horizontal |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 439 | diffsplit |
| 440 | |
| 441 | call assert_equal(&columns, winwidth(1)) |
| 442 | call assert_equal(&columns, winwidth(2)) |
| 443 | call assert_equal(&lines, winheight(1) + winheight(2) + 3) |
| 444 | call assert_inrange(0, 1, winheight(1) - winheight(2)) |
| 445 | |
| 446 | set diffopt& |
| 447 | diffoff! |
| 448 | %bwipe |
| 449 | endfunc |
| 450 | |
| 451 | func Test_diffopt_vertical() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 452 | set diffopt=internal,vertical |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 453 | diffsplit |
| 454 | |
| 455 | call assert_equal(&lines - 2, winheight(1)) |
| 456 | call assert_equal(&lines - 2, winheight(2)) |
| 457 | call assert_equal(&columns, winwidth(1) + winwidth(2) + 1) |
| 458 | call assert_inrange(0, 1, winwidth(1) - winwidth(2)) |
| 459 | |
| 460 | set diffopt& |
| 461 | diffoff! |
| 462 | %bwipe |
| 463 | endfunc |
| 464 | |
Bram Moolenaar | 97ce419 | 2017-12-01 20:35:58 +0100 | [diff] [blame] | 465 | func Test_diffopt_hiddenoff() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 466 | set diffopt=internal,filler,foldcolumn:0,hiddenoff |
Bram Moolenaar | 97ce419 | 2017-12-01 20:35:58 +0100 | [diff] [blame] | 467 | e! one |
| 468 | call setline(1, ['Two', 'Three']) |
| 469 | redraw |
| 470 | let normattr = screenattr(1, 1) |
| 471 | diffthis |
| 472 | botright vert new two |
| 473 | call setline(1, ['One', 'Four']) |
| 474 | diffthis |
| 475 | redraw |
| 476 | call assert_notequal(normattr, screenattr(1, 1)) |
| 477 | set hidden |
| 478 | close |
| 479 | redraw |
| 480 | " should not diffing with hidden buffer two while 'hiddenoff' is enabled |
| 481 | call assert_equal(normattr, screenattr(1, 1)) |
| 482 | |
| 483 | bwipe! |
| 484 | bwipe! |
| 485 | set hidden& diffopt& |
| 486 | endfunc |
| 487 | |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 488 | func Test_diffoff_hidden() |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 489 | set diffopt=internal,filler,foldcolumn:0 |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 490 | e! one |
| 491 | call setline(1, ['Two', 'Three']) |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 492 | redraw |
Bram Moolenaar | 25ea054 | 2017-02-03 23:16:28 +0100 | [diff] [blame] | 493 | let normattr = screenattr(1, 1) |
| 494 | diffthis |
| 495 | botright vert new two |
| 496 | call setline(1, ['One', 'Four']) |
| 497 | diffthis |
| 498 | redraw |
| 499 | call assert_notequal(normattr, screenattr(1, 1)) |
| 500 | set hidden |
| 501 | close |
| 502 | redraw |
| 503 | " diffing with hidden buffer two |
| 504 | call assert_notequal(normattr, screenattr(1, 1)) |
| 505 | diffoff |
| 506 | redraw |
| 507 | call assert_equal(normattr, screenattr(1, 1)) |
| 508 | diffthis |
| 509 | redraw |
| 510 | " still diffing with hidden buffer two |
| 511 | call assert_notequal(normattr, screenattr(1, 1)) |
| 512 | diffoff! |
| 513 | redraw |
| 514 | call assert_equal(normattr, screenattr(1, 1)) |
| 515 | diffthis |
| 516 | redraw |
| 517 | " no longer diffing with hidden buffer two |
| 518 | call assert_equal(normattr, screenattr(1, 1)) |
| 519 | |
| 520 | bwipe! |
| 521 | bwipe! |
| 522 | set hidden& diffopt& |
| 523 | endfunc |
| 524 | |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 525 | func Test_setting_cursor() |
| 526 | new Xtest1 |
| 527 | put =range(1,90) |
| 528 | wq |
| 529 | new Xtest2 |
| 530 | put =range(1,100) |
| 531 | wq |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 532 | |
Bram Moolenaar | 025e3e0 | 2016-10-18 14:50:18 +0200 | [diff] [blame] | 533 | tabe Xtest2 |
| 534 | $ |
| 535 | diffsp Xtest1 |
| 536 | tabclose |
| 537 | |
| 538 | call delete('Xtest1') |
| 539 | call delete('Xtest2') |
| 540 | endfunc |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 541 | |
| 542 | func Test_diff_move_to() |
| 543 | new |
| 544 | call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
| 545 | diffthis |
| 546 | vnew |
| 547 | call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x']) |
| 548 | diffthis |
| 549 | norm ]c |
| 550 | call assert_equal(2, line('.')) |
| 551 | norm 3]c |
| 552 | call assert_equal(9, line('.')) |
| 553 | norm 10]c |
| 554 | call assert_equal(11, line('.')) |
| 555 | norm [c |
| 556 | call assert_equal(9, line('.')) |
| 557 | norm 2[c |
| 558 | call assert_equal(5, line('.')) |
| 559 | norm 10[c |
| 560 | call assert_equal(2, line('.')) |
| 561 | %bwipe! |
| 562 | endfunc |
| 563 | |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 564 | func Test_diffexpr() |
| 565 | if !executable('diff') |
| 566 | return |
| 567 | endif |
| 568 | |
| 569 | func DiffExpr() |
Bram Moolenaar | 3b8defd | 2018-09-13 13:03:11 +0200 | [diff] [blame] | 570 | " Prepent some text to check diff type detection |
| 571 | call writefile(['warning', ' message'], v:fname_out) |
| 572 | silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out |
Bram Moolenaar | 79a213d | 2017-05-16 13:15:18 +0200 | [diff] [blame] | 573 | endfunc |
| 574 | set diffexpr=DiffExpr() |
| 575 | set diffopt=foldcolumn:0 |
| 576 | |
| 577 | enew! |
| 578 | call setline(1, ['one', 'two', 'three']) |
| 579 | redraw |
| 580 | let normattr = screenattr(1, 1) |
| 581 | diffthis |
| 582 | |
| 583 | botright vert new |
| 584 | call setline(1, ['one', 'two', 'three.']) |
| 585 | diffthis |
| 586 | |
| 587 | redraw |
| 588 | call assert_equal(normattr, screenattr(1, 1)) |
| 589 | call assert_equal(normattr, screenattr(2, 1)) |
| 590 | call assert_notequal(normattr, screenattr(3, 1)) |
| 591 | |
| 592 | diffoff! |
| 593 | %bwipe! |
| 594 | set diffexpr& diffopt& |
| 595 | endfunc |
| 596 | |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 597 | func Test_diffpatch() |
| 598 | " The patch program on MS-Windows may fail or hang. |
| 599 | if !executable('patch') || !has('unix') |
| 600 | return |
| 601 | endif |
| 602 | new |
| 603 | insert |
| 604 | *************** |
| 605 | *** 1,3 **** |
| 606 | 1 |
| 607 | ! 2 |
| 608 | 3 |
| 609 | --- 1,4 ---- |
| 610 | 1 |
| 611 | ! 2x |
| 612 | 3 |
| 613 | + 4 |
| 614 | . |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 615 | saveas! Xpatch |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 616 | bwipe! |
| 617 | new |
| 618 | call assert_fails('diffpatch Xpatch', 'E816:') |
Bram Moolenaar | 1ef73e3 | 2017-03-09 19:21:30 +0100 | [diff] [blame] | 619 | |
Bram Moolenaar | a95ab32 | 2017-03-11 19:21:53 +0100 | [diff] [blame] | 620 | for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch'] |
Bram Moolenaar | 1ef73e3 | 2017-03-09 19:21:30 +0100 | [diff] [blame] | 621 | call setline(1, ['1', '2', '3']) |
| 622 | if name != 'Xpatch' |
| 623 | call rename('Xpatch', name) |
| 624 | endif |
| 625 | exe 'diffpatch ' . escape(name, '$') |
| 626 | call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) |
| 627 | if name != 'Xpatch' |
| 628 | call rename(name, 'Xpatch') |
| 629 | endif |
| 630 | bwipe! |
| 631 | endfor |
| 632 | |
Bram Moolenaar | aeb661e | 2017-02-26 19:59:59 +0100 | [diff] [blame] | 633 | call delete('Xpatch') |
| 634 | bwipe! |
| 635 | endfunc |
| 636 | |
| 637 | func Test_diff_too_many_buffers() |
| 638 | for i in range(1, 8) |
| 639 | exe "new Xtest" . i |
| 640 | diffthis |
| 641 | endfor |
| 642 | new Xtest9 |
| 643 | call assert_fails('diffthis', 'E96:') |
| 644 | %bwipe! |
| 645 | endfunc |
| 646 | |
| 647 | func Test_diff_nomodifiable() |
| 648 | new |
| 649 | call setline(1, [1, 2, 3, 4]) |
| 650 | setl nomodifiable |
| 651 | diffthis |
| 652 | vnew |
| 653 | call setline(1, ['1x', 2, 3, 3, 4]) |
| 654 | diffthis |
| 655 | call assert_fails('norm dp', 'E793:') |
| 656 | setl nomodifiable |
| 657 | call assert_fails('norm do', 'E21:') |
| 658 | %bwipe! |
| 659 | endfunc |
Bram Moolenaar | f58a847 | 2017-03-05 18:03:04 +0100 | [diff] [blame] | 660 | |
Bram Moolenaar | 97fbc40 | 2017-09-26 19:41:46 +0200 | [diff] [blame] | 661 | func Test_diff_hlID() |
| 662 | new |
| 663 | call setline(1, [1, 2, 3]) |
| 664 | diffthis |
| 665 | vnew |
| 666 | call setline(1, ['1x', 2, 'x', 3]) |
| 667 | diffthis |
| 668 | redraw |
| 669 | |
| 670 | call assert_equal(synIDattr(diff_hlID(-1, 1), "name"), "") |
| 671 | |
| 672 | call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") |
| 673 | call assert_equal(synIDattr(diff_hlID(1, 2), "name"), "DiffText") |
| 674 | call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") |
| 675 | call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "DiffAdd") |
| 676 | call assert_equal(synIDattr(diff_hlID(4, 1), "name"), "") |
| 677 | |
| 678 | wincmd w |
| 679 | call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") |
| 680 | call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") |
| 681 | call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "") |
| 682 | |
| 683 | %bwipe! |
| 684 | endfunc |
| 685 | |
| 686 | func Test_diff_filler() |
| 687 | new |
| 688 | call setline(1, [1, 2, 3, 'x', 4]) |
| 689 | diffthis |
| 690 | vnew |
| 691 | call setline(1, [1, 2, 'y', 'y', 3, 4]) |
| 692 | diffthis |
| 693 | redraw |
| 694 | |
| 695 | call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)')) |
| 696 | wincmd w |
| 697 | call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) |
| 698 | |
| 699 | %bwipe! |
| 700 | endfunc |
| 701 | |
Bram Moolenaar | f58a847 | 2017-03-05 18:03:04 +0100 | [diff] [blame] | 702 | func Test_diff_lastline() |
| 703 | enew! |
| 704 | only! |
| 705 | call setline(1, ['This is a ', 'line with five ', 'rows']) |
| 706 | diffthis |
| 707 | botright vert new |
| 708 | call setline(1, ['This is', 'a line with ', 'four rows']) |
| 709 | diffthis |
| 710 | 1 |
| 711 | call feedkeys("Je a\<CR>", 'tx') |
| 712 | call feedkeys("Je a\<CR>", 'tx') |
| 713 | let w1lines = winline() |
| 714 | wincmd w |
| 715 | $ |
| 716 | let w2lines = winline() |
| 717 | call assert_equal(w2lines, w1lines) |
| 718 | bwipe! |
| 719 | bwipe! |
| 720 | endfunc |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 721 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 722 | func WriteDiffFiles(buf, list1, list2) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 723 | call writefile(a:list1, 'Xfile1') |
| 724 | call writefile(a:list2, 'Xfile2') |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 725 | if a:buf |
| 726 | call term_sendkeys(a:buf, ":checktime\<CR>") |
| 727 | endif |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 728 | endfunc |
| 729 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 730 | " Verify a screendump with both the internal and external diff. |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 731 | func VerifyBoth(buf, dumpfile, extra) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 732 | " trailing : for leaving the cursor on the command line |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 733 | 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] | 734 | call term_sendkeys(a:buf, cmd) |
| 735 | if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external') |
| 736 | break " don't let the next iteration overwrite the "failed" file. |
| 737 | endif |
| 738 | endfor |
| 739 | endfunc |
| 740 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 741 | " Verify a screendump with the internal diff only. |
| 742 | func VerifyInternal(buf, dumpfile, extra) |
| 743 | call term_sendkeys(a:buf, ":diffupdate!\<CR>") |
| 744 | " trailing : for leaving the cursor on the command line |
| 745 | call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:") |
| 746 | call VerifyScreenDump(a:buf, a:dumpfile, {}) |
| 747 | endfunc |
| 748 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 749 | func Test_diff_screen() |
| 750 | if !CanRunVimInTerminal() || !has('menu') |
| 751 | return |
| 752 | endif |
| 753 | " clean up already existing swap files, just in case |
| 754 | call delete('.Xfile1.swp') |
| 755 | call delete('.Xfile2.swp') |
| 756 | |
| 757 | " Test 1: Add a line in beginning of file 2 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 758 | 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 | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 759 | let buf = RunVimInTerminal('-d Xfile1 Xfile2', {}) |
| 760 | " Set autoread mode, ,so that Vim won't complain once we re-write the test |
| 761 | " files |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 762 | 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] | 763 | |
| 764 | call VerifyBoth(buf, 'Test_diff_01', '') |
| 765 | |
| 766 | " Test 2: Add a line in beginning of file 1 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 767 | 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] | 768 | call VerifyBoth(buf, 'Test_diff_02', '') |
| 769 | |
| 770 | " Test 3: Add a line at the end of file 2 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 771 | 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] | 772 | call VerifyBoth(buf, 'Test_diff_03', '') |
| 773 | |
| 774 | " Test 4: Add a line at the end of file 1 |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 775 | 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] | 776 | call VerifyBoth(buf, 'Test_diff_04', '') |
| 777 | |
| 778 | " 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] | 779 | 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] | 780 | call VerifyBoth(buf, 'Test_diff_05', '') |
| 781 | |
| 782 | " 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] | 783 | 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] | 784 | call VerifyBoth(buf, 'Test_diff_06', '') |
| 785 | |
| 786 | " Test 7 - 9: Test normal/patience/histogram diff algorithm |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 787 | 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] | 788 | \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");', |
| 789 | \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {', |
| 790 | \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)', |
| 791 | \ '{', ' frobnitz(fact(10));', '}'], |
| 792 | \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {', |
| 793 | \ ' return fib(n-1) + fib(n-2);', ' }', ' return 1;', '}', '', '// Frobs foo heartily', |
| 794 | \ 'int frobnitz(int foo)', '{', ' int i;', ' for(i = 0; i < 10; i++)', ' {', |
| 795 | \ ' printf("%d\n", foo);', ' }', '}', '', |
| 796 | \ 'int main(int argc, char **argv)', '{', ' frobnitz(fib(10));', '}']) |
| 797 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 798 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 799 | call VerifyScreenDump(buf, 'Test_diff_07', {}) |
| 800 | |
| 801 | call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>") |
| 802 | call VerifyScreenDump(buf, 'Test_diff_08', {}) |
| 803 | |
| 804 | call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>") |
| 805 | call VerifyScreenDump(buf, 'Test_diff_09', {}) |
| 806 | |
| 807 | " Test 10-11: normal/indent-heuristic |
| 808 | call term_sendkeys(buf, ":set diffopt&vim\<cr>") |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 809 | 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] | 810 | \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '', |
| 811 | \ ' values.each do |v|', ' v.finalize', ' end']) |
| 812 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 813 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 814 | call VerifyScreenDump(buf, 'Test_diff_10', {}) |
| 815 | |
| 816 | call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>") |
| 817 | call VerifyScreenDump(buf, 'Test_diff_11', {}) |
| 818 | |
| 819 | " Test 12: diff the same file |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 820 | 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] | 821 | call VerifyBoth(buf, 'Test_diff_12', '') |
| 822 | |
| 823 | " Test 13: diff an empty file |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 824 | call WriteDiffFiles(buf, [], []) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 825 | call VerifyBoth(buf, 'Test_diff_13', '') |
| 826 | |
| 827 | " Test 14: test diffopt+=icase |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 828 | call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe']) |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 829 | call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase") |
| 830 | |
| 831 | " Test 15-16: test diffopt+=iwhite |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 832 | call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'], |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 833 | \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}']) |
| 834 | call term_sendkeys(buf, ":diffupdate!\<cr>") |
| 835 | call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>") |
| 836 | call VerifyScreenDump(buf, 'Test_diff_15', {}) |
| 837 | call term_sendkeys(buf, ":set diffopt+=internal\<cr>") |
| 838 | call VerifyScreenDump(buf, 'Test_diff_16', {}) |
| 839 | |
Bram Moolenaar | 785fc65 | 2018-09-15 19:17:38 +0200 | [diff] [blame] | 840 | " Test 17: test diffopt+=iblank |
| 841 | call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy']) |
| 842 | call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank") |
| 843 | |
| 844 | " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol |
| 845 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite") |
| 846 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall") |
| 847 | call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol") |
| 848 | |
| 849 | " Test 19: test diffopt+=iwhiteeol |
| 850 | call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar']) |
| 851 | call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol") |
| 852 | |
| 853 | " Test 19: test diffopt+=iwhiteall |
| 854 | call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall") |
| 855 | |
Bram Moolenaar | e828b76 | 2018-09-10 17:51:58 +0200 | [diff] [blame] | 856 | " clean up |
| 857 | call StopVimInTerminal(buf) |
| 858 | call delete('Xfile1') |
| 859 | call delete('Xfile2') |
| 860 | endfunc |
| 861 | |
Bram Moolenaar | 4a5abbd | 2018-10-02 18:26:10 +0200 | [diff] [blame] | 862 | func Test_diff_with_cursorline() |
| 863 | if !CanRunVimInTerminal() |
| 864 | return |
| 865 | endif |
| 866 | |
| 867 | call writefile([ |
| 868 | \ 'hi CursorLine ctermbg=red ctermfg=white', |
| 869 | \ 'set cursorline', |
| 870 | \ 'call setline(1, ["foo","foo","foo","bar"])', |
| 871 | \ 'vnew', |
| 872 | \ 'call setline(1, ["bee","foo","foo","baz"])', |
| 873 | \ 'windo diffthis', |
| 874 | \ '2wincmd w', |
| 875 | \ ], 'Xtest_diff_cursorline') |
| 876 | let buf = RunVimInTerminal('-S Xtest_diff_cursorline', {}) |
| 877 | |
| 878 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_01', {}) |
| 879 | call term_sendkeys(buf, "j") |
| 880 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_02', {}) |
| 881 | call term_sendkeys(buf, "j") |
| 882 | call VerifyScreenDump(buf, 'Test_diff_with_cursorline_03', {}) |
| 883 | |
| 884 | " clean up |
| 885 | call StopVimInTerminal(buf) |
| 886 | call delete('Xtest_diff_cursorline') |
| 887 | endfunc |