Skip to content

Commit

Permalink
Improve/stringify neomake#utils#diff_dict (neomake#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed authored Feb 15, 2018
1 parent 83f4f7f commit b43b8b5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
4 changes: 1 addition & 3 deletions autoload/neomake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,8 @@ function! s:AddExprCallback(jobinfo, prev_list) abort
if debug
call neomake#utils#DebugMessage(printf(
\ 'Modified list entry (postprocess): %s.',
\ join(values(map(neomake#utils#diff_dict(before, entry)[0],
\ "v:key.': '.string(v:val[0]).' => '.string(v:val[1])")))),
\ string(neomake#utils#diff_dict(before, entry))),
\ a:jobinfo)

endif
endif

Expand Down
27 changes: 18 additions & 9 deletions autoload/neomake/utils.vim
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,25 @@ function! neomake#utils#hook(event, context, ...) abort
endif
endfunction

function! neomake#utils#diff_dict(d1, d2) abort
let diff = [{}, {}, {}]
let keys = keys(a:d1) + keys(a:d2)
function! neomake#utils#diff_dict(old, new) abort
let diff = {}
let keys = keys(a:old) + keys(a:new)
for k in keys
if !has_key(a:d2, k)
let diff[1][k] = a:d1[k]
elseif !has_key(a:d1, k)
let diff[2][k] = a:d2[k]
elseif type(a:d1[k]) !=# type(a:d2[k]) || a:d1[k] !=# a:d2[k]
let diff[0][k] = [a:d1[k], a:d2[k]]
if !has_key(a:new, k)
if !has_key(diff, 'removed')
let diff['removed'] = {}
endif
let diff['removed'][k] = a:old[k]
elseif !has_key(a:old, k)
if !has_key(diff, 'added')
let diff['added'] = {}
endif
let diff['added'][k] = a:new[k]
elseif type(a:old[k]) !=# type(a:new[k]) || a:old[k] !=# a:new[k]
if !has_key(diff, 'changed')
let diff['changed'] = {}
endif
let diff['changed'][k] = [a:old[k], a:new[k]]
endif
endfor
return diff
Expand Down
2 changes: 1 addition & 1 deletion tests/lists.vader
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Execute (AddExprCallback with changed windows inbetween):
wincmd k
AssertEqual map(getloclist(0), 'v:val.text'), ['2 SUFFIX:1']
bwipe
AssertNeomakeMessage "Modified list entry (postprocess): text: '2' => '2 SUFFIX:1'."
AssertNeomakeMessage "Modified list entry (postprocess): {'changed': {'text': ['2', '2 SUFFIX:1']}}."
endif

Execute (Goes back to original window after opening list):
Expand Down
2 changes: 1 addition & 1 deletion tests/tempfiles.vader
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Execute (Temporary buffer is not wiped if opened):
exe 'bwipe' unlisted_bufnr

AssertNeomakeMessage '\v^Setting bufnr according to tempfile for entry: .* ''bufnr'': '.tempfile_bufnr
AssertNeomakeMessage 'Modified list entry (postprocess): bufnr: '.tempfile_bufnr.' => '.bufnr.'.'
AssertNeomakeMessage printf("Modified list entry (postprocess): {'changed': {'bufnr': [%d, %d]}}.", tempfile_bufnr, bufnr)
AssertNeomakeMessage 'WARN: seen entries with bufnr different from jobinfo.bufnr ('.bufnr.'): {'''.unlisted_bufnr.''': 1}, current bufnr: '.bufnr.'.'

Execute (unlisted buffers created for tempfiles get wiped):
Expand Down
12 changes: 6 additions & 6 deletions tests/utils.vader
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,18 @@ Execute (neomake#utils#ExpandArgs):
bwipe

Execute (neomake#utils#diff_dict):
AssertEqual neomake#utils#diff_dict({}, {}), [{}, {}, {}]
AssertEqual neomake#utils#diff_dict({}, {}), {}
AssertEqual neomake#utils#diff_dict({'a': 1}, {'a': 2}),
\ [{'a': [1, 2]}, {}, {}]
\ {'changed': {'a': [1, 2]}}
AssertEqual neomake#utils#diff_dict({'a': 1}, {'b': 2}),
\ [{}, {'a': 1}, {'b': 2}]
\ {'removed': {'a': 1}, 'added': {'b': 2}}
AssertEqual neomake#utils#diff_dict({'a': 1}, {'a': 1, 'b': 2}),
\ [{}, {}, {'b': 2}]
\ {'added': {'b': 2}}

AssertEqual neomake#utils#diff_dict({'a': '1'}, {'a': 1}),
\ [{'a': ['1', 1]}, {}, {}]
\ {'changed': {'a': ['1', 1]}}
AssertEqual neomake#utils#diff_dict({'a': []}, {'a': {}}),
\ [{'a': [[], {}]}, {}, {}]
\ {'changed': {'a': [[], {}]}}

Execute (neomake#utils#wstrpart):
AssertEqual neomake#utils#wstrpart('123', 0, 0), ''
Expand Down

0 comments on commit b43b8b5

Please sign in to comment.