From 67cc2ea8e4f6e1772ef89da74f68ae241e20c7b5 Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:01:18 -0700 Subject: [PATCH 1/6] Rename lightline#gitdiff#algorithm to LightlineGitDiffAlgorithm --- autoload/lightline/gitdiff.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/lightline/gitdiff.vim b/autoload/lightline/gitdiff.vim index c1ec1c3..5cdd315 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -37,7 +37,7 @@ function! lightline#gitdiff#write_calculation_to_cache(buffer, soft) abort return endif - let l:indicator_values = get(g:, 'lightline#gitdiff#algorithm', + let l:indicator_values = get(g:, 'LightlineGitDiffAlgorithm', \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) })(a:buffer) " If the user doesn't want to show empty indicators, @@ -73,7 +73,7 @@ endfunction " " In fact, an arbitrary number of changes can be supported. This depends on " the algorithm that is used for calculation -" (`g:lightline#gitdiff#algorithm`). However, this function takes only these +" (`g:LightlineGitDiffAlgorithm`). However, this function takes only these " types of changes into account b/c it only provides default indicators for " these types. If an algorithm does not support a particular type, this is not " an issue; if it supports more types than this function, the additional types From 1ac663a6a5c496cb1bd8f07be20c5c214c3f71ce Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:07:32 -0700 Subject: [PATCH 2/6] Add more show_empty_indicators tests --- test/lightline-gitdiff.vader | 190 +++++++++++++++++++++++++++++++++-- 1 file changed, 181 insertions(+), 9 deletions(-) diff --git a/test/lightline-gitdiff.vader b/test/lightline-gitdiff.vader index fc926ff..c909ae3 100644 --- a/test/lightline-gitdiff.vader +++ b/test/lightline-gitdiff.vader @@ -1,22 +1,194 @@ Include (Algorithms): algorithm/parse_indicator_group.vader Include (Utils): utils/group_at.vader -Execute(write_calculation_to_cache(): given no show_empty_indicators variable): +Before : + if exists('g:LightlineGitDiffAlgorithm') + unlet g:LightlineGitDiffAlgorithm + endif + +" no show_empty_indicators +Execute(write_calculation_to_cache(): given no show_empty_indicators variable and an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } call g:lightline#gitdiff#write_calculation_to_cache(1, 0) let actual = get(g:, 'lightline#gitdiff#cache')[1] Then (should return no empty indicators): AssertEqual {}, actual -Execute(write_calculation_to_cache(): given g:lightline#gitdiff#show_empty_indicators == 0): +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'A'): + AssertEqual { 'A': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'D'): + AssertEqual { 'D': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'M'): + AssertEqual { 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'D' indicator): + AssertEqual { 'A': 3, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'A' indicator): + AssertEqual { 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'M' indicator): + AssertEqual { 'A': 4, 'D': 5 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should not remove any indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual + +" show_empty_indicators variable == 0 +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } let g:lightline#gitdiff#show_empty_indicators = 0 - call lightline#gitdiff#write_calculation_to_cache(2, 0) - let actual = get(g:, 'lightline#gitdiff#cache')[2] + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] Then (should return no empty indicators): AssertEqual {}, actual -Execute(write_calculation_to_cache(): given g:lightline#gitdiff#show_empty_indicators == 1): +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'A'): + AssertEqual { 'A': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'D'): + AssertEqual { 'D': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'M'): + AssertEqual { 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'D' indicator): + AssertEqual { 'A': 3, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'A' indicator): + AssertEqual { 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'M' indicator): + AssertEqual { 'A': 4, 'D': 5 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should not remove any indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual + +" show_empty_indicators variable == 1 +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } let g:lightline#gitdiff#show_empty_indicators = 1 - call lightline#gitdiff#write_calculation_to_cache(2, 0) - let actual = get(g:, 'lightline#gitdiff#cache')[2] -Then (should return all empty indicators): - AssertEqual {'A': 0, 'D': 0, 'M': 0}, actual + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 0, 'M':0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators): + AssertEqual { 'A': 1, 'D': 0, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 1, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 0, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 3, 'D': 0, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 4, 'D': 5, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual From 3af337641c65dad051da6b4106812d0d35d0e1d3 Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:09:29 -0700 Subject: [PATCH 3/6] Change lightline#gitdiff#algorithm to LightlineGitDiffAlgorithm in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab17561..8330bb5 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ By default, the latter one is used because it allows to display modified lines. This resembles the default: ```vim -let g:lightline#gitdiff#algorithm = +let g:LightlineGitDiffAlgorithm = \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) } ``` From 2a3bd79cd5a30d6c79b7251461dac041b119d463 Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:13:56 -0700 Subject: [PATCH 4/6] Update numstat algorithm --- autoload/lightline/gitdiff/algorithms/numstat.vim | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/autoload/lightline/gitdiff/algorithms/numstat.vim b/autoload/lightline/gitdiff/algorithms/numstat.vim index 4fed527..6c36f2c 100644 --- a/autoload/lightline/gitdiff/algorithms/numstat.vim +++ b/autoload/lightline/gitdiff/algorithms/numstat.vim @@ -17,17 +17,5 @@ function! lightline#gitdiff#algorithms#numstat#calculate(buffer) abort return {} endif - let l:ret = {} - - " lines added - if l:stats[0] !=# '0' - let l:ret['A'] = l:stats[0] - endif - - " lines deleted - if l:stats[1] !=# '0' - let l:ret['D'] = l:stats[1] - endif - - return l:ret + return return { 'A': l:stats[0], 'D': l:stats[1] } endfunction From 33dcb622041d92dda69a008b2a0706237a9a99fc Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:25:30 -0700 Subject: [PATCH 5/6] Fix double return --- autoload/lightline/gitdiff/algorithms/numstat.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/lightline/gitdiff/algorithms/numstat.vim b/autoload/lightline/gitdiff/algorithms/numstat.vim index 6c36f2c..ae665c3 100644 --- a/autoload/lightline/gitdiff/algorithms/numstat.vim +++ b/autoload/lightline/gitdiff/algorithms/numstat.vim @@ -17,5 +17,5 @@ function! lightline#gitdiff#algorithms#numstat#calculate(buffer) abort return {} endif - return return { 'A': l:stats[0], 'D': l:stats[1] } + return { 'A': l:stats[0], 'D': l:stats[1] } endfunction From f592e8545d56314090fae72141a982a9b85452dd Mon Sep 17 00:00:00 2001 From: Greg Block Date: Tue, 16 Jun 2020 21:27:29 -0700 Subject: [PATCH 6/6] Cleanup comment --- test/lightline-gitdiff.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lightline-gitdiff.vader b/test/lightline-gitdiff.vader index c909ae3..b09c653 100644 --- a/test/lightline-gitdiff.vader +++ b/test/lightline-gitdiff.vader @@ -6,7 +6,7 @@ Before : unlet g:LightlineGitDiffAlgorithm endif -" no show_empty_indicators +" no show_empty_indicators variable Execute(write_calculation_to_cache(): given no show_empty_indicators variable and an empty result): let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } call g:lightline#gitdiff#write_calculation_to_cache(1, 0)