more tests

This commit is contained in:
Daniel Hahler 2019-12-02 13:38:58 +01:00 committed by Jan Edmund Lazo
parent d6cac809b0
commit 1c5e347b8c
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15

View File

@ -397,4 +397,53 @@ describe('VimL dictionary notifications', function()
eq("Vim(call):Couldn't find a watcher matching key and callback", eval('g:exc'))
end)
it('does not call watcher added in callback', function()
source([[
let g:d = {}
let g:calls = []
function! W1(...) abort
call add(g:calls, 'W1')
call dictwatcheradd(g:d, '*', function('W2'))
endfunction
function! W2(...) abort
call add(g:calls, 'W2')
endfunction
call dictwatcheradd(g:d, '*', function('W1'))
let g:d.foo = 23
]])
eq(23, eval('g:d.foo'))
eq({"W1"}, eval('g:calls'))
end)
it('calls watcher deleted in callback', function()
source([[
let g:d = {}
let g:calls = []
function! W1(...) abort
call add(g:calls, "W1")
call dictwatcherdel(g:d, '*', function('W2'))
endfunction
function! W2(...) abort
call add(g:calls, "W2")
endfunction
call dictwatcheradd(g:d, '*', function('W1'))
call dictwatcheradd(g:d, '*', function('W2'))
let g:d.foo = 123
unlet g:d
let g:d = {}
call dictwatcheradd(g:d, '*', function('W2'))
call dictwatcheradd(g:d, '*', function('W1'))
let g:d.foo = 123
]])
eq(123, eval('g:d.foo'))
eq({"W1", "W2", "W2", "W1"}, eval('g:calls'))
end)
end)