diff src/testdir/test_diffmode.vim @ 9694:5e9f63a2ac5c v7.4.2123

commit https://github.com/vim/vim/commit/42093c0ec52e6ff29e80aae65ac6a744c7de79bb Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 30 16:16:54 2016 +0200 patch 7.4.2123 Problem: No new style test for diff mode. Solution: Add a test. Check that folds are in sync.
author Christian Brabandt <cb@256bit.org>
date Sat, 30 Jul 2016 16:30:06 +0200
parents
children 103e79a0ad8d
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_diffmode.vim
@@ -0,0 +1,165 @@
+" Tests for diff mode
+
+func Test_diff_fold_sync()
+  enew!
+  let l = range(50)
+  call setline(1, l)
+  diffthis
+  let winone = win_getid()
+  new
+  let l[25] = 'diff'
+  call setline(1, l)
+  diffthis
+  let wintwo = win_getid()
+  " line 15 is inside the closed fold
+  call assert_equal(19, foldclosedend(10))
+  call win_gotoid(winone)
+  call assert_equal(19, foldclosedend(10))
+  " open the fold
+  normal zv
+  call assert_equal(-1, foldclosedend(10))
+  " fold in other window must have opened too
+  call win_gotoid(wintwo)
+  call assert_equal(-1, foldclosedend(10))
+
+  " cursor position is in sync
+  normal 23G
+  call win_gotoid(winone)
+  call assert_equal(23, getcurpos()[1])
+
+  windo diffoff
+  close!
+  set nomodified
+endfunc
+
+func Test_vert_split()
+  " Disable the title to avoid xterm keeping the wrong one.
+  set notitle noicon
+  new
+  let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee']
+  call setline(1, l)
+  w! Xtest
+  normal dd
+  $
+  put
+  normal kkrXoxxx
+  w! Xtest2
+  file Nop
+  normal ggoyyyjjjozzzz
+  set foldmethod=marker foldcolumn=4
+  call assert_equal(0, &diff)
+  call assert_equal('marker', &foldmethod)
+  call assert_equal(4, &foldcolumn)
+  call assert_equal(0, &scrollbind)
+  call assert_equal(0, &cursorbind)
+  call assert_equal(1, &wrap)
+
+  vert diffsplit Xtest
+  vert diffsplit Xtest2
+  call assert_equal(1, &diff)
+  call assert_equal('diff', &foldmethod)
+  call assert_equal(2, &foldcolumn)
+  call assert_equal(1, &scrollbind)
+  call assert_equal(1, &cursorbind)
+  call assert_equal(0, &wrap)
+
+  let diff_fdm = &fdm
+  let diff_fdc = &fdc
+  " repeat entering diff mode here to see if this saves the wrong settings
+  diffthis
+  " jump to second window for a moment to have filler line appear at start of
+  " first window
+  wincmd w
+  normal gg
+  wincmd p
+  normal gg
+  call assert_equal(2, winline())
+  normal j
+  call assert_equal(4, winline())
+  normal j
+  call assert_equal(5, winline())
+  normal j
+  call assert_equal(6, winline())
+  normal j
+  call assert_equal(8, winline())
+  normal j
+  call assert_equal(9, winline())
+
+  wincmd w
+  normal gg
+  call assert_equal(1, winline())
+  normal j
+  call assert_equal(2, winline())
+  normal j
+  call assert_equal(4, winline())
+  normal j
+  call assert_equal(5, winline())
+  normal j
+  call assert_equal(8, winline())
+
+  wincmd w
+  normal gg
+  call assert_equal(2, winline())
+  normal j
+  call assert_equal(3, winline())
+  normal j
+  call assert_equal(4, winline())
+  normal j
+  call assert_equal(5, winline())
+  normal j
+  call assert_equal(6, winline())
+  normal j
+  call assert_equal(7, winline())
+  normal j
+  call assert_equal(8, winline())
+
+  " Test diffoff
+  diffoff!
+  1wincmd 2
+  let &diff = 1
+  let &fdm = diff_fdm
+  let &fdc = diff_fdc
+  4wincmd w
+  diffoff!
+  1wincmd w
+  call assert_equal(0, &diff)
+  call assert_equal('marker', &foldmethod)
+  call assert_equal(4, &foldcolumn)
+  call assert_equal(0, &scrollbind)
+  call assert_equal(0, &cursorbind)
+  call assert_equal(1, &wrap)
+
+  wincmd w
+  call assert_equal(0, &diff)
+  call assert_equal('marker', &foldmethod)
+  call assert_equal(4, &foldcolumn)
+  call assert_equal(0, &scrollbind)
+  call assert_equal(0, &cursorbind)
+  call assert_equal(1, &wrap)
+
+  wincmd w
+  call assert_equal(0, &diff)
+  call assert_equal('marker', &foldmethod)
+  call assert_equal(4, &foldcolumn)
+  call assert_equal(0, &scrollbind)
+  call assert_equal(0, &cursorbind)
+  call assert_equal(1, &wrap)
+
+  windo bw!
+endfunc
+
+func Test_filler_lines()
+  " Test that diffing shows correct filler lines
+  enew!
+  put =range(4,10)
+  1d _
+  vnew
+  put =range(1,10)
+  1d _
+  windo diffthis
+  wincmd h
+  call assert_equal(1, line('w0'))
+  unlet! diff_fdm diff_fdc
+
+  windo bw!
+endfunc