1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
" MIT (c) Wenxuan Zhang
" MIT (c) Zach Nielsen 2021
" Git tests
function! s:minimap_test_git_multiline()
" Multiline Changes
let git_line = '@@ -97,97 +97,97 @@'
let expected_dictionary = { 'start': 33, 'end': 65, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 201, 67)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Multiline Deletions
let git_line = '@@ -97,97 +97,0 @@'
let expected_dictionary = { 'start': 33, 'end': 33, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 201, 67)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Multiline Additions
let git_line = '@@ -97,0 +97,97 @@'
let expected_dictionary = { 'start': 33, 'end': 65, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 201, 67)
call testify#assert#equals(actual_dictionary, expected_dictionary)
endfunction
function! s:minimap_test_git_short_file()
" Very short file, change
let git_line = '@@ -0 +0 @@'
let expected_dictionary = { 'start': 0, 'end': 1, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1, 1)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very short file, deletion
let git_line = '@@ -1 +0,0 @@'
let expected_dictionary = { 'start': 0, 'end': 0, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1, 1)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very short file, addition
let git_line = '@@ -0,0 +0 @@'
let expected_dictionary = { 'start': 0, 'end': 1, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1, 1)
call testify#assert#equals(actual_dictionary, expected_dictionary)
endfunction
function! s:minimap_test_git_long_file()
" Very long file, change at beginning
let git_line = '@@ -0 +0 @@'
let expected_dictionary = { 'start': 1, 'end': 1, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, delete at beginning
let git_line = '@@ -0 +0,0 @@'
let expected_dictionary = { 'start': 1, 'end': 1, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, add at beginning
let git_line = '@@ -0,0 +0 @@'
let expected_dictionary = { 'start': 1, 'end': 1, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, change at middle
let git_line = '@@ -5000 +5000 @@'
let expected_dictionary = { 'start': 49, 'end': 49, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, delete at middle
let git_line = '@@ -5000 +5000,0 @@'
let expected_dictionary = { 'start': 49, 'end': 49, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, add at middle
let git_line = '@@ -5000,0 +5000 @@'
let expected_dictionary = { 'start': 49, 'end': 49, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, change at end
let git_line = '@@ -10000 +10000 @@'
let expected_dictionary = { 'start': 97, 'end': 98, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, remove at end
let git_line = '@@ -10000 +10000,0 @@'
let expected_dictionary = { 'start': 97, 'end': 97, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Very long file, add at end
let git_line = '@@ -10000,0 +10000 @@'
let expected_dictionary = { 'start': 97, 'end': 98, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 10000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
endfunction
function! s:minimap_test_git_span_mm_border()
" Do two lines, one line apart, but spanning a minimap line increment. We
" should get 2 minimap lines in this case.
let git_line = '@@ -51,2 51,2 @@'
let expected_dictionary = { 'start': 5, 'end': 6, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
let git_line = '@@ -51,0 +51,2 @@'
let expected_dictionary = { 'start': 5, 'end': 6, 'color': g:minimap_diffadd_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
" Removals are always one line, since the content of the file is altered.
let git_line = '@@ -51,2 +51,0 @@'
let expected_dictionary = { 'start': 5, 'end': 5, 'color': g:minimap_diffremove_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
endfunction
function! s:minimap_test_git_string_extras()
" Test that what goes after the @@ does not need to be formattted
let git_line = '@@ -533,74 +533,6 @@ It should not matter, @@ what goes after the @@'
let expected_dictionary = { 'start': 52, 'end': 53, 'color': g:minimap_diff_color }
let actual_dictionary = minimap#vim#MinimapParseGitDiffLine(git_line, 1000, 97)
call testify#assert#equals(actual_dictionary, expected_dictionary)
endfunction
call testify#it('Git - Multiline diff', function('s:minimap_test_git_multiline'))
call testify#it('Git - Short file diff', function('s:minimap_test_git_short_file'))
call testify#it('Git - Long file diff', function('s:minimap_test_git_long_file'))
call testify#it('Git - Diff spans minimap lines', function('s:minimap_test_git_span_mm_border'))
call testify#it('Git - Extras in string are ignored', function('s:minimap_test_git_string_extras'))
|