mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -31,6 +31,10 @@ function s:git_diff_staged()
|
||||
return split(system('git diff -U0 --staged fixture.txt'), '\n')
|
||||
endfunction
|
||||
|
||||
function s:trigger_gitgutter()
|
||||
doautocmd CursorHold
|
||||
endfunction
|
||||
|
||||
|
||||
"
|
||||
" SetUp / TearDown
|
||||
@ -40,7 +44,8 @@ function SetUp()
|
||||
call system("git init ".s:test_repo.
|
||||
\ " && cd ".s:test_repo.
|
||||
\ " && cp ../fixture.txt .".
|
||||
\ " && git add . && git commit -m 'initial'")
|
||||
\ " && git add . && git commit -m 'initial'".
|
||||
\ " && git config diff.mnemonicPrefix false")
|
||||
execute ':cd' s:test_repo
|
||||
edit! fixture.txt
|
||||
call gitgutter#sign#reset()
|
||||
@ -64,7 +69,7 @@ endfunction
|
||||
|
||||
function Test_add_lines()
|
||||
normal ggo*
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=2 id=3000 name=GitGutterLineAdded"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -76,7 +81,7 @@ function Test_add_lines_fish()
|
||||
set shell=/usr/local/bin/fish
|
||||
|
||||
normal ggo*
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=2 id=3000 name=GitGutterLineAdded"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -87,7 +92,7 @@ endfunction
|
||||
|
||||
function Test_modify_lines()
|
||||
normal ggi*
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=1 id=3000 name=GitGutterLineModified"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -96,7 +101,7 @@ endfunction
|
||||
|
||||
function Test_remove_lines()
|
||||
execute '5d'
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=4 id=3000 name=GitGutterLineRemoved"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -105,7 +110,7 @@ endfunction
|
||||
|
||||
function Test_remove_first_lines()
|
||||
execute '1d'
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=1 id=3000 name=GitGutterLineRemovedFirstLine"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -115,7 +120,7 @@ endfunction
|
||||
function Test_edit_file_with_same_name_as_a_branch()
|
||||
normal 5Gi*
|
||||
call system('git checkout -b fixture.txt')
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=5 id=3000 name=GitGutterLineModified"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
@ -127,7 +132,7 @@ function Test_file_added_to_git()
|
||||
call system('touch '.tmpfile.' && git add '.tmpfile)
|
||||
execute 'edit '.tmpfile
|
||||
normal ihello
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=1 id=3000 name=GitGutterLineAdded"]
|
||||
call assert_equal(expected, s:signs('fileAddedToGit.tmp'))
|
||||
@ -138,7 +143,7 @@ function Test_filename_with_equals()
|
||||
call system('touch =fixture=.txt && git add =fixture=.txt')
|
||||
edit =fixture=.txt
|
||||
normal ggo*
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = [
|
||||
\ 'line=1 id=3000 name=GitGutterLineAdded',
|
||||
@ -152,7 +157,7 @@ function Test_filename_with_square_brackets()
|
||||
call system('touch fix[tu]re.txt && git add fix[tu]re.txt')
|
||||
edit fix[tu]re.txt
|
||||
normal ggo*
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = [
|
||||
\ 'line=1 id=3000 name=GitGutterLineAdded',
|
||||
@ -168,7 +173,7 @@ function Test_follow_symlink()
|
||||
call system('ln -nfs fixture.txt '.tmp)
|
||||
execute 'edit '.tmp
|
||||
6d
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ['line=5 id=3000 name=GitGutterLineRemoved']
|
||||
call assert_equal(expected, s:signs('symlink'))
|
||||
@ -183,7 +188,7 @@ function Test_keep_alt()
|
||||
call assert_equal('', bufname('#'))
|
||||
|
||||
normal ggx
|
||||
doautocmd CursorHold
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal('', bufname('#'))
|
||||
endfunction
|
||||
@ -193,7 +198,7 @@ function Test_keep_modified()
|
||||
normal 5Go*
|
||||
call assert_equal(1, getbufvar('', '&modified'))
|
||||
|
||||
doautocmd CursorHold
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal(1, getbufvar('', '&modified'))
|
||||
endfunction
|
||||
@ -204,7 +209,7 @@ function Test_keep_op_marks()
|
||||
call assert_equal([0,6,1,0], getpos("'["))
|
||||
call assert_equal([0,6,2,0], getpos("']"))
|
||||
|
||||
doautocmd CursorHold
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([0,6,1,0], getpos("'["))
|
||||
call assert_equal([0,6,2,0], getpos("']"))
|
||||
@ -218,26 +223,15 @@ endfunction
|
||||
|
||||
function Test_orphaned_signs()
|
||||
execute "normal 5GoX\<CR>Y"
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
6d
|
||||
write
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ['line=6 id=3001 name=GitGutterLineAdded']
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_sign_column_always()
|
||||
let g:gitgutter_sign_column_always=1
|
||||
write
|
||||
|
||||
let expected = ['line=9999 id=2999 name=GitGutterDummy']
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
|
||||
let g:gitgutter_sign_column_always=0
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_untracked_file_outside_repo()
|
||||
let tmp = tempname()
|
||||
call system('touch '.tmp)
|
||||
@ -252,7 +246,7 @@ function Test_untracked_file_within_repo()
|
||||
call system('touch '.tmp)
|
||||
execute 'edit '.tmp
|
||||
normal ggo*
|
||||
doautocmd CursorHold
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs(tmp))
|
||||
|
||||
@ -265,7 +259,7 @@ function Test_untracked_file_square_brackets_within_repo()
|
||||
call system('touch '.tmp)
|
||||
execute 'edit '.tmp
|
||||
normal ggo*
|
||||
doautocmd CursorHold
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs(tmp))
|
||||
|
||||
@ -301,8 +295,19 @@ function Test_hunk_stage()
|
||||
|
||||
call assert_equal([], s:signs('fixture.txt'))
|
||||
|
||||
call assert_equal([], s:git_diff())
|
||||
" Buffer is unsaved
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index ae8e546..f5c6aff 100644',
|
||||
\ '--- a/fixture.txt',
|
||||
\ '+++ b/fixture.txt',
|
||||
\ '@@ -5 +5 @@ d',
|
||||
\ '-*e',
|
||||
\ '+e'
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff())
|
||||
|
||||
" Index has been updated
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index f5c6aff..ae8e546 100644',
|
||||
@ -313,6 +318,11 @@ function Test_hunk_stage()
|
||||
\ '+*e'
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff_staged())
|
||||
|
||||
" Save the buffer
|
||||
write
|
||||
|
||||
call assert_equal([], s:git_diff())
|
||||
endfunction
|
||||
|
||||
|
||||
@ -329,6 +339,31 @@ function Test_hunk_stage_nearby_hunk()
|
||||
\ ]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
|
||||
" Buffer is unsaved
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index 53b13df..f5c6aff 100644',
|
||||
\ '--- a/fixture.txt',
|
||||
\ '+++ b/fixture.txt',
|
||||
\ '@@ -3,0 +4 @@ c',
|
||||
\ '+d',
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff())
|
||||
|
||||
" Index has been updated
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index f5c6aff..53b13df 100644',
|
||||
\ '--- a/fixture.txt',
|
||||
\ '+++ b/fixture.txt',
|
||||
\ '@@ -4 +3,0 @@ c',
|
||||
\ '-d',
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff_staged())
|
||||
|
||||
" Save the buffer
|
||||
write
|
||||
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index 53b13df..8fdfda7 100644',
|
||||
@ -340,16 +375,6 @@ function Test_hunk_stage_nearby_hunk()
|
||||
\ '+z',
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff())
|
||||
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index f5c6aff..53b13df 100644',
|
||||
\ '--- a/fixture.txt',
|
||||
\ '+++ b/fixture.txt',
|
||||
\ '@@ -4 +3,0 @@ c',
|
||||
\ '-d',
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff_staged())
|
||||
endfunction
|
||||
|
||||
|
||||
@ -359,7 +384,6 @@ function Test_hunk_undo()
|
||||
|
||||
normal 5Gi*
|
||||
GitGutterUndoHunk
|
||||
write " write file so we can verify git diff (--staged)
|
||||
|
||||
call assert_equal('foo', &shell)
|
||||
let &shell = _shell
|
||||
@ -374,8 +398,9 @@ function Test_undo_nearby_hunk()
|
||||
execute "normal! 2Gox\<CR>y\<CR>z"
|
||||
normal 2jdd
|
||||
normal k
|
||||
call s:trigger_gitgutter()
|
||||
GitGutterUndoHunk
|
||||
write " write file so we can verify git diff (--staged)
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = [
|
||||
\ 'line=3 id=3000 name=GitGutterLineAdded',
|
||||
@ -384,6 +409,13 @@ function Test_undo_nearby_hunk()
|
||||
\ ]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
|
||||
call assert_equal([], s:git_diff())
|
||||
|
||||
call assert_equal([], s:git_diff_staged())
|
||||
|
||||
" Save the buffer
|
||||
write
|
||||
|
||||
let expected = [
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index f5c6aff..3fbde56 100644',
|
||||
@ -396,5 +428,148 @@ function Test_undo_nearby_hunk()
|
||||
\ ]
|
||||
call assert_equal(expected, s:git_diff())
|
||||
|
||||
call assert_equal([], s:git_diff_staged())
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_write_option()
|
||||
set nowrite
|
||||
|
||||
normal ggo*
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
let expected = ["line=2 id=3000 name=GitGutterLineAdded"]
|
||||
call assert_equal(expected, s:signs('fixture.txt'))
|
||||
|
||||
set write
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_inner_text_object()
|
||||
execute "normal! 2Gox\<CR>y\<CR>z\<CR>\<CR>"
|
||||
call s:trigger_gitgutter()
|
||||
normal dic
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs('fixture.txt'))
|
||||
call assert_equal(readfile('fixture.txt'), getline(1,'$'))
|
||||
|
||||
" Excludes trailing lines
|
||||
normal 9Gi*
|
||||
normal 10Gi*
|
||||
call s:trigger_gitgutter()
|
||||
execute "normal vic\<Esc>"
|
||||
call assert_equal([9, 10], [line("'<"), line("'>")])
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_around_text_object()
|
||||
execute "normal! 2Gox\<CR>y\<CR>z\<CR>\<CR>"
|
||||
call s:trigger_gitgutter()
|
||||
normal dac
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs('fixture.txt'))
|
||||
call assert_equal(readfile('fixture.txt'), getline(1,'$'))
|
||||
|
||||
" Includes trailing lines
|
||||
normal 9Gi*
|
||||
normal 10Gi*
|
||||
call s:trigger_gitgutter()
|
||||
execute "normal vac\<Esc>"
|
||||
call assert_equal([9, 11], [line("'<"), line("'>")])
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_user_autocmd()
|
||||
autocmd User GitGutter let s:autocmd_user = g:gitgutter_hook_context.bufnr
|
||||
|
||||
" Verify not fired when nothing changed.
|
||||
let s:autocmd_user = 0
|
||||
call s:trigger_gitgutter()
|
||||
call assert_equal(0, s:autocmd_user)
|
||||
|
||||
" Verify fired when there was a change.
|
||||
normal ggo*
|
||||
let bufnr = bufnr('')
|
||||
call s:trigger_gitgutter()
|
||||
call assert_equal(bufnr, s:autocmd_user)
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_fix_file_references()
|
||||
" No special characters
|
||||
let hunk_diff = join([
|
||||
\ 'diff --git a/fixture.txt b/fixture.txt',
|
||||
\ 'index f5c6aff..3fbde56 100644',
|
||||
\ '--- a/fixture.txt',
|
||||
\ '+++ b/fixture.txt',
|
||||
\ '@@ -2,0 +3,1 @@ b',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
let filepath = 'blah.txt'
|
||||
|
||||
let expected = join([
|
||||
\ 'diff --git a/blah.txt b/blah.txt',
|
||||
\ 'index f5c6aff..3fbde56 100644',
|
||||
\ '--- a/blah.txt',
|
||||
\ '+++ b/blah.txt',
|
||||
\ '@@ -2,0 +3,1 @@ b',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
|
||||
" diff.mnemonicPrefix; spaces in filename
|
||||
let hunk_diff = join([
|
||||
\ 'diff --git i/x/cat dog w/x/cat dog',
|
||||
\ 'index f5c6aff..3fbde56 100644',
|
||||
\ '--- i/x/cat dog',
|
||||
\ '+++ w/x/cat dog',
|
||||
\ '@@ -2,0 +3,1 @@ b',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
let filepath = 'blah.txt'
|
||||
|
||||
let expected = join([
|
||||
\ 'diff --git i/blah.txt w/blah.txt',
|
||||
\ 'index f5c6aff..3fbde56 100644',
|
||||
\ '--- i/blah.txt',
|
||||
\ '+++ w/blah.txt',
|
||||
\ '@@ -2,0 +3,1 @@ b',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
|
||||
" Backslashes in filename; quotation marks
|
||||
let hunk_diff = join([
|
||||
\ 'diff --git "a/C:\\Users\\FOO~1.PAR\\AppData\\Local\\Temp\\nvimJcmSv9\\11.1.vim" "b/C:\\Users\\FOO~1.PAR\\AppData\\Local\\Temp\\nvimJcmSv9\\12.1.vim"',
|
||||
\ 'index f42aeb0..4930403 100644',
|
||||
\ '--- "a/C:\\Users\\FOO~1.PAR\\AppData\\Local\\Temp\\nvimJcmSv9\\11.1.vim"',
|
||||
\ '+++ "b/C:\\Users\\FOO~1.PAR\\AppData\\Local\\Temp\\nvimJcmSv9\\12.1.vim"',
|
||||
\ '@@ -172,0 +173 @@ stuff',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
let filepath = 'init.vim'
|
||||
|
||||
let expected = join([
|
||||
\ 'diff --git "a/init.vim" "b/init.vim"',
|
||||
\ 'index f42aeb0..4930403 100644',
|
||||
\ '--- "a/init.vim"',
|
||||
\ '+++ "b/init.vim"',
|
||||
\ '@@ -172,0 +173 @@ stuff',
|
||||
\ '+x'
|
||||
\ ], "\n")."\n"
|
||||
|
||||
call assert_equal(expected, gitgutter#hunk#fix_file_references(filepath, hunk_diff))
|
||||
endfunction
|
||||
|
||||
|
||||
function Test_encoding()
|
||||
call system('cp ../cp932.txt . && git add cp932.txt')
|
||||
edit ++enc=cp932 cp932.txt
|
||||
|
||||
call s:trigger_gitgutter()
|
||||
|
||||
call assert_equal([], s:signs('cp932.txt'))
|
||||
endfunction
|
||||
|
Reference in New Issue
Block a user