aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/eval/input_spec.lua38
-rw-r--r--test/functional/eval/match_functions_spec.lua15
-rw-r--r--test/functional/ex_cmds/dict_notifications_spec.lua67
3 files changed, 102 insertions, 18 deletions
diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua
new file mode 100644
index 0000000000..393fc10175
--- /dev/null
+++ b/test/functional/eval/input_spec.lua
@@ -0,0 +1,38 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+
+local feed = helpers.feed
+local clear = helpers.clear
+local command = helpers.command
+
+local screen
+
+before_each(function()
+ clear()
+ screen = Screen.new(25, 5)
+ screen:attach()
+end)
+
+describe('input()', function()
+ it('works correctly with multiline prompts', function()
+ feed([[:call input("Test\nFoo")<CR>]])
+ screen:expect([[
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ Test |
+ Foo^ |
+ ]], {{bold=true, foreground=Screen.colors.Blue}})
+ end)
+ it('works correctly with multiline prompts and :echohl', function()
+ command('hi Test ctermfg=Red guifg=Red term=bold')
+ feed([[:echohl Test | call input("Test\nFoo")<CR>]])
+ screen:expect([[
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2:Test} |
+ {2:Foo}^ |
+ ]], {{bold=true, foreground=Screen.colors.Blue}, {foreground=Screen.colors.Red}})
+ end)
+end)
diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua
index f6bad59c66..3150d89f62 100644
--- a/test/functional/eval/match_functions_spec.lua
+++ b/test/functional/eval/match_functions_spec.lua
@@ -44,3 +44,18 @@ describe('setmatches()', function()
eq({}, funcs.getmatches())
end)
end)
+
+describe('matchadd()', function()
+ it('correctly works when first two arguments and conceal are numbers at once',
+ function()
+ command('hi def link 1 PreProc')
+ eq(4, funcs.matchadd(1, 2, 3, 4, {conceal=5}))
+ eq({{
+ group='1',
+ pattern='2',
+ priority=3,
+ id=4,
+ conceal='5',
+ }}, funcs.getmatches())
+ end)
+end)
diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua
index 057245db1c..8cc717483e 100644
--- a/test/functional/ex_cmds/dict_notifications_spec.lua
+++ b/test/functional/ex_cmds/dict_notifications_spec.lua
@@ -9,7 +9,7 @@ local eval = helpers.eval
describe('dictionary change notifications', function()
local channel
- setup(function()
+ before_each(function()
clear()
channel = nvim('get_api_info')[1]
nvim('set_var', 'channel', channel)
@@ -18,19 +18,15 @@ describe('dictionary change notifications', function()
-- the same set of tests are applied to top-level dictionaries(g:, b:, w: and
-- t:) and a dictionary variable, so we generate them in the following
-- function.
- local function gentests(dict_expr, dict_expr_suffix, dict_init)
- if not dict_expr_suffix then
- dict_expr_suffix = ''
- end
-
+ local function gentests(dict_expr, dict_init)
local function update(opval, key)
if not key then
key = 'watched'
end
if opval == '' then
- nvim('command', "unlet "..dict_expr..dict_expr_suffix..key)
+ command(('unlet %s[\'%s\']'):format(dict_expr, key))
else
- nvim('command', "let "..dict_expr..dict_expr_suffix..key.." "..opval)
+ command(('let %s[\'%s\'] %s'):format(dict_expr, key, opval))
end
end
@@ -50,7 +46,7 @@ describe('dictionary change notifications', function()
describe(dict_expr .. ' watcher', function()
if dict_init then
- setup(function()
+ before_each(function()
source(dict_init)
end)
end
@@ -143,6 +139,32 @@ describe('dictionary change notifications', function()
]])
end)
+ it('is triggered for empty keys', function()
+ command([[
+ call dictwatcheradd(]]..dict_expr..[[, "", "g:Changed")
+ ]])
+ update('= 1', '')
+ verify_value({new = 1}, '')
+ update('= 2', '')
+ verify_value({old = 1, new = 2}, '')
+ command([[
+ call dictwatcherdel(]]..dict_expr..[[, "", "g:Changed")
+ ]])
+ end)
+
+ it('is triggered for empty keys when using catch-all *', function()
+ command([[
+ call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed")
+ ]])
+ update('= 1', '')
+ verify_value({new = 1}, '')
+ update('= 2', '')
+ verify_value({old = 1, new = 2}, '')
+ command([[
+ call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed")
+ ]])
+ end)
+
-- test a sequence of updates of different types to ensure proper memory
-- management(with ASAN)
local function test_updates(tests)
@@ -190,10 +212,10 @@ describe('dictionary change notifications', function()
gentests('b:')
gentests('w:')
gentests('t:')
- gentests('g:dict_var', '.', 'let g:dict_var = {}')
+ gentests('g:dict_var', 'let g:dict_var = {}')
describe('multiple watchers on the same dict/key', function()
- setup(function()
+ before_each(function()
source([[
function! g:Watcher1(dict, key, value)
call rpcnotify(g:channel, '1', a:key, a:value)
@@ -213,6 +235,9 @@ describe('dictionary change notifications', function()
end)
it('only removes watchers that fully match dict, key and callback', function()
+ nvim('command', 'let g:key = "value"')
+ eq({'notification', '1', {'key', {new = 'value'}}}, next_msg())
+ eq({'notification', '2', {'key', {new = 'value'}}}, next_msg())
nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")')
nvim('command', 'let g:key = "v2"')
eq({'notification', '2', {'key', {old = 'value', new = 'v2'}}}, next_msg())
@@ -220,6 +245,17 @@ describe('dictionary change notifications', function()
end)
describe('errors', function()
+ before_each(function()
+ source([[
+ function! g:Watcher1(dict, key, value)
+ call rpcnotify(g:channel, '1', a:key, a:value)
+ endfunction
+ function! g:Watcher2(dict, key, value)
+ call rpcnotify(g:channel, '2', a:key, a:value)
+ endfunction
+ ]])
+ end)
+
-- WARNING: This suite depends on the above tests
it('fails to remove if no watcher with matching callback is found', function()
eq("Vim(call):Couldn't find a watcher matching key and callback",
@@ -236,15 +272,10 @@ describe('dictionary change notifications', function()
command('call dictwatcherdel(g:, "key", "g:InvalidCb")')
end)
- it('fails with empty keys', function()
- eq("Vim(call):E713: Cannot use empty key for Dictionary",
- exc_exec('call dictwatcheradd(g:, "", "g:Watcher1")'))
- eq("Vim(call):E713: Cannot use empty key for Dictionary",
- exc_exec('call dictwatcherdel(g:, "", "g:Watcher1")'))
- end)
-
it('does not fail to replace a watcher function', function()
source([[
+ let g:key = 'v2'
+ call dictwatcheradd(g:, "key", "g:Watcher2")
function! g:ReplaceWatcher2()
function! g:Watcher2(dict, key, value)
call rpcnotify(g:channel, '2b', a:key, a:value)