|
| 1 | +" Tests for diff mode |
| 2 | + |
| 3 | +func Test_diff_fold_sync() |
| 4 | + enew! |
| 5 | + let l = range(50) |
| 6 | + call setline(1, l) |
| 7 | + diffthis |
| 8 | + let winone = win_getid() |
| 9 | + new |
| 10 | + let l[25] = 'diff' |
| 11 | + call setline(1, l) |
| 12 | + diffthis |
| 13 | + let wintwo = win_getid() |
| 14 | + " line 15 is inside the closed fold |
| 15 | + call assert_equal(19, foldclosedend(10)) |
| 16 | + call win_gotoid(winone) |
| 17 | + call assert_equal(19, foldclosedend(10)) |
| 18 | + " open the fold |
| 19 | + normal zv |
| 20 | + call assert_equal(-1, foldclosedend(10)) |
| 21 | + " fold in other window must have opened too |
| 22 | + call win_gotoid(wintwo) |
| 23 | + call assert_equal(-1, foldclosedend(10)) |
| 24 | + |
| 25 | + " cursor position is in sync |
| 26 | + normal 23G |
| 27 | + call win_gotoid(winone) |
| 28 | + call assert_equal(23, getcurpos()[1]) |
| 29 | + |
| 30 | + windo diffoff |
| 31 | + close! |
| 32 | + set nomodified |
| 33 | +endfunc |
| 34 | + |
| 35 | +func Test_vert_split() |
| 36 | + " Disable the title to avoid xterm keeping the wrong one. |
| 37 | + set notitle noicon |
| 38 | + new |
| 39 | + let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee'] |
| 40 | + call setline(1, l) |
| 41 | + w! Xtest |
| 42 | + normal dd |
| 43 | + $ |
| 44 | + put |
| 45 | + normal kkrXoxxx |
| 46 | + w! Xtest2 |
| 47 | + file Nop |
| 48 | + normal ggoyyyjjjozzzz |
| 49 | + set foldmethod=marker foldcolumn=4 |
| 50 | + call assert_equal(0, &diff) |
| 51 | + call assert_equal('marker', &foldmethod) |
| 52 | + call assert_equal(4, &foldcolumn) |
| 53 | + call assert_equal(0, &scrollbind) |
| 54 | + call assert_equal(0, &cursorbind) |
| 55 | + call assert_equal(1, &wrap) |
| 56 | + |
| 57 | + vert diffsplit Xtest |
| 58 | + vert diffsplit Xtest2 |
| 59 | + call assert_equal(1, &diff) |
| 60 | + call assert_equal('diff', &foldmethod) |
| 61 | + call assert_equal(2, &foldcolumn) |
| 62 | + call assert_equal(1, &scrollbind) |
| 63 | + call assert_equal(1, &cursorbind) |
| 64 | + call assert_equal(0, &wrap) |
| 65 | + |
| 66 | + let diff_fdm = &fdm |
| 67 | + let diff_fdc = &fdc |
| 68 | + " repeat entering diff mode here to see if this saves the wrong settings |
| 69 | + diffthis |
| 70 | + " jump to second window for a moment to have filler line appear at start of |
| 71 | + " first window |
| 72 | + wincmd w |
| 73 | + normal gg |
| 74 | + wincmd p |
| 75 | + normal gg |
| 76 | + call assert_equal(2, winline()) |
| 77 | + normal j |
| 78 | + call assert_equal(4, winline()) |
| 79 | + normal j |
| 80 | + call assert_equal(5, winline()) |
| 81 | + normal j |
| 82 | + call assert_equal(6, winline()) |
| 83 | + normal j |
| 84 | + call assert_equal(8, winline()) |
| 85 | + normal j |
| 86 | + call assert_equal(9, winline()) |
| 87 | + |
| 88 | + wincmd w |
| 89 | + normal gg |
| 90 | + call assert_equal(1, winline()) |
| 91 | + normal j |
| 92 | + call assert_equal(2, winline()) |
| 93 | + normal j |
| 94 | + call assert_equal(4, winline()) |
| 95 | + normal j |
| 96 | + call assert_equal(5, winline()) |
| 97 | + normal j |
| 98 | + call assert_equal(8, winline()) |
| 99 | + |
| 100 | + wincmd w |
| 101 | + normal gg |
| 102 | + call assert_equal(2, winline()) |
| 103 | + normal j |
| 104 | + call assert_equal(3, winline()) |
| 105 | + normal j |
| 106 | + call assert_equal(4, winline()) |
| 107 | + normal j |
| 108 | + call assert_equal(5, winline()) |
| 109 | + normal j |
| 110 | + call assert_equal(6, winline()) |
| 111 | + normal j |
| 112 | + call assert_equal(7, winline()) |
| 113 | + normal j |
| 114 | + call assert_equal(8, winline()) |
| 115 | + |
| 116 | + " Test diffoff |
| 117 | + diffoff! |
| 118 | + 1wincmd 2 |
| 119 | + let &diff = 1 |
| 120 | + let &fdm = diff_fdm |
| 121 | + let &fdc = diff_fdc |
| 122 | + 4wincmd w |
| 123 | + diffoff! |
| 124 | + 1wincmd w |
| 125 | + call assert_equal(0, &diff) |
| 126 | + call assert_equal('marker', &foldmethod) |
| 127 | + call assert_equal(4, &foldcolumn) |
| 128 | + call assert_equal(0, &scrollbind) |
| 129 | + call assert_equal(0, &cursorbind) |
| 130 | + call assert_equal(1, &wrap) |
| 131 | + |
| 132 | + wincmd w |
| 133 | + call assert_equal(0, &diff) |
| 134 | + call assert_equal('marker', &foldmethod) |
| 135 | + call assert_equal(4, &foldcolumn) |
| 136 | + call assert_equal(0, &scrollbind) |
| 137 | + call assert_equal(0, &cursorbind) |
| 138 | + call assert_equal(1, &wrap) |
| 139 | + |
| 140 | + wincmd w |
| 141 | + call assert_equal(0, &diff) |
| 142 | + call assert_equal('marker', &foldmethod) |
| 143 | + call assert_equal(4, &foldcolumn) |
| 144 | + call assert_equal(0, &scrollbind) |
| 145 | + call assert_equal(0, &cursorbind) |
| 146 | + call assert_equal(1, &wrap) |
| 147 | + |
| 148 | + windo bw! |
| 149 | +endfunc |
| 150 | + |
| 151 | +func Test_filler_lines() |
| 152 | + " Test that diffing shows correct filler lines |
| 153 | + enew! |
| 154 | + put =range(4,10) |
| 155 | + 1d _ |
| 156 | + vnew |
| 157 | + put =range(1,10) |
| 158 | + 1d _ |
| 159 | + windo diffthis |
| 160 | + wincmd h |
| 161 | + call assert_equal(1, line('w0')) |
| 162 | + unlet! diff_fdm diff_fdc |
| 163 | + |
| 164 | + windo bw! |
| 165 | +endfunc |
0 commit comments