Add test for clean/smudge filter

See #796.
This commit is contained in:
Andy Stewart
2023-06-05 10:52:10 +01:00
parent a202921235
commit e2056e54c5
4 changed files with 41 additions and 1 deletions

1
test/.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.foo filter=reverse diff=reverse

6
test/.gitconfig Normal file
View File

@@ -0,0 +1,6 @@
[filter "reverse"]
clean = "rev"
smudge = "rev"
[diff "reverse"]
textconv = "cat"

4
test/fixture.foo Normal file
View File

@@ -0,0 +1,4 @@
one
two
three
four

View File

@@ -54,6 +54,9 @@ endfunction
function SetUp() function SetUp()
call system("git init ".s:test_repo. call system("git init ".s:test_repo.
\ " && cd ".s:test_repo. \ " && cd ".s:test_repo.
\ " && cp ../.gitconfig .".
\ " && cp ../.gitattributes .".
\ " && cp ../fixture.foo .".
\ " && cp ../fixture.txt .". \ " && cp ../fixture.txt .".
\ " && cp ../fixture_dos.txt .". \ " && cp ../fixture_dos.txt .".
\ " && git add . && git commit -m 'initial'". \ " && git add . && git commit -m 'initial'".
@@ -76,7 +79,7 @@ function TearDown()
silent! execute s:bufnr+1.',$bdelete!' silent! execute s:bufnr+1.',$bdelete!'
execute ':cd' s:current_dir execute ':cd' s:current_dir
call system("rm -rf ".s:test_repo) " call system("rm -rf ".s:test_repo)
endfunction endfunction
" "
@@ -1179,3 +1182,29 @@ function Test_assume_unchanged()
call s:trigger_gitgutter() call s:trigger_gitgutter()
call s:assert_signs([], 'fixture.txt') call s:assert_signs([], 'fixture.txt')
endfunction endfunction
function Test_clean_smudge_filter()
call system("git config --local include.path ../.gitconfig")
call system("rm fixture.foo && git checkout fixture.foo")
func Answer(char)
call feedkeys(a:char."\<CR>")
endfunc
edit fixture.foo
call setline(2, ['A'])
call setline(4, ['B'])
call s:trigger_gitgutter()
normal! 2G
call timer_start(100, {-> Answer('y')} )
GitGutterStageHunk
call s:trigger_gitgutter()
let expected = [
\ {'lnum': 2, 'id': 23, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'},
\ {'lnum': 4, 'id': 24, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'}
\ ]
" call s:assert_signs(expected, 'fixture.foo')
call s:assert_signs([], 'fixture.foo')
endfunction