1" Tests for diff mode 2 3func 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 33endfunc 34 35func 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 call delete('Xtest') 149 call delete('Xtest2') 150 windo bw! 151endfunc 152 153func Test_filler_lines() 154 " Test that diffing shows correct filler lines 155 enew! 156 put =range(4,10) 157 1d _ 158 vnew 159 put =range(1,10) 160 1d _ 161 windo diffthis 162 wincmd h 163 call assert_equal(1, line('w0')) 164 unlet! diff_fdm diff_fdc 165 windo diffoff 166 bwipe! 167 enew! 168endfunc 169 170func Test_diffget_diffput() 171 enew! 172 let l = range(50) 173 call setline(1, l) 174 call assert_fails('diffget', 'E99:') 175 diffthis 176 call assert_fails('diffget', 'E100:') 177 new 178 let l[10] = 'one' 179 let l[20] = 'two' 180 let l[30] = 'three' 181 let l[40] = 'four' 182 call setline(1, l) 183 diffthis 184 call assert_equal('one', getline(11)) 185 11diffget 186 call assert_equal('10', getline(11)) 187 21diffput 188 wincmd w 189 call assert_equal('two', getline(21)) 190 normal 31Gdo 191 call assert_equal('three', getline(31)) 192 call assert_equal('40', getline(41)) 193 normal 41Gdp 194 wincmd w 195 call assert_equal('40', getline(41)) 196 new 197 diffthis 198 call assert_fails('diffget', 'E101:') 199 200 windo diffoff 201 bwipe! 202 bwipe! 203 enew! 204endfunc 205 206func Test_diffoff() 207 enew! 208 call setline(1, ['Two', 'Three']) 209 let normattr = screenattr(1, 1) 210 diffthis 211 botright vert new 212 call setline(1, ['One', '', 'Two', 'Three']) 213 diffthis 214 redraw 215 diffoff! 216 redraw 217 call assert_equal(normattr, screenattr(1, 1)) 218 bwipe! 219 bwipe! 220endfunc 221