@@ -7,6 +7,16 @@ local function flush(ms)
77 child .api .nvim_eval (" 1" )
88end
99
10+ -- Returns the registered command's name, or nil if not registered. Filters
11+ -- server-side so the function-valued `callback` field (present on 0.12+)
12+ -- does not cross the MiniTest msgpack boundary.
13+ local function cmd_registered_name (name )
14+ return child .lua_get (string.format (
15+ " (vim.api.nvim_get_commands({})[%q] or {}).name" ,
16+ name
17+ ))
18+ end
19+
1020local function setup_test_environment ()
1121 child .lua ([[
1222 local Eca = require('eca')
100110T [" EcaChatAddFile" ] = MiniTest .new_set ()
101111
102112T [" EcaChatAddFile" ][" command is registered" ] = function ()
103- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
104- eq (type (commands .EcaChatAddFile ), " table" )
105- eq (commands .EcaChatAddFile .name , " EcaChatAddFile" )
113+ eq (cmd_registered_name (" EcaChatAddFile" ), " EcaChatAddFile" )
106114end
107115
108116T [" EcaChatAddFile" ][" adds current file as context when no args" ] = function ()
140148T [" EcaAddFile" ] = MiniTest .new_set ()
141149
142150T [" EcaAddFile" ][" command is registered" ] = function ()
143- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
144- eq (type (commands .EcaAddFile ), " table" )
145- eq (commands .EcaAddFile .name , " EcaAddFile" )
151+ eq (cmd_registered_name (" EcaAddFile" ), " EcaAddFile" )
146152end
147153
148154T [" EcaAddFile" ][" shows deprecation notice when called" ] = function ()
160166T [" EcaChatRemoveFile" ] = MiniTest .new_set ()
161167
162168T [" EcaChatRemoveFile" ][" command is registered" ] = function ()
163- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
164- eq (type (commands .EcaChatRemoveFile ), " table" )
165- eq (commands .EcaChatRemoveFile .name , " EcaChatRemoveFile" )
169+ eq (cmd_registered_name (" EcaChatRemoveFile" ), " EcaChatRemoveFile" )
166170end
167171
168172T [" EcaChatRemoveFile" ][" removes current file context when no args" ] = function ()
197201T [" EcaRemoveContext" ] = MiniTest .new_set ()
198202
199203T [" EcaRemoveContext" ][" command is registered" ] = function ()
200- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
201- eq (type (commands .EcaRemoveContext ), " table" )
202- eq (commands .EcaRemoveContext .name , " EcaRemoveContext" )
204+ eq (cmd_registered_name (" EcaRemoveContext" ), " EcaRemoveContext" )
203205end
204206
205207T [" EcaRemoveContext" ][" shows deprecation notice when called" ] = function ()
215217T [" EcaChatAddSelection" ] = MiniTest .new_set ()
216218
217219T [" EcaChatAddSelection" ][" command is registered" ] = function ()
218- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
219- eq (type (commands .EcaChatAddSelection ), " table" )
220- eq (commands .EcaChatAddSelection .name , " EcaChatAddSelection" )
220+ eq (cmd_registered_name (" EcaChatAddSelection" ), " EcaChatAddSelection" )
221221end
222222
223223T [" EcaChatAddSelection" ][" adds a ranged file context based on visual selection" ] = function ()
250250T [" EcaAddSelection" ] = MiniTest .new_set ()
251251
252252T [" EcaAddSelection" ][" command is registered" ] = function ()
253- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
254- eq (type (commands .EcaAddSelection ), " table" )
255- eq (commands .EcaAddSelection .name , " EcaAddSelection" )
253+ eq (cmd_registered_name (" EcaAddSelection" ), " EcaAddSelection" )
256254end
257255
258256T [" EcaAddSelection" ][" shows deprecation notice when called" ] = function ()
268266T [" EcaChatAddUrl" ] = MiniTest .new_set ()
269267
270268T [" EcaChatAddUrl" ][" command is registered" ] = function ()
271- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
272- eq (type (commands .EcaChatAddUrl ), " table" )
273- eq (commands .EcaChatAddUrl .name , " EcaChatAddUrl" )
269+ eq (cmd_registered_name (" EcaChatAddUrl" ), " EcaChatAddUrl" )
274270end
275271
276272T [" EcaChatAddUrl" ][" adds web context and truncates name based on config" ] = function ()
329325T [" EcaChatListContexts" ] = MiniTest .new_set ()
330326
331327T [" EcaChatListContexts" ][" command is registered" ] = function ()
332- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
333- eq (type (commands .EcaChatListContexts ), " table" )
334- eq (commands .EcaChatListContexts .name , " EcaChatListContexts" )
328+ eq (cmd_registered_name (" EcaChatListContexts" ), " EcaChatListContexts" )
335329end
336330
337331T [" EcaChatListContexts" ][" runs without modifying contexts" ] = function ()
352346T [" EcaListContexts" ] = MiniTest .new_set ()
353347
354348T [" EcaListContexts" ][" command is registered" ] = function ()
355- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
356- eq (type (commands .EcaListContexts ), " table" )
357- eq (commands .EcaListContexts .name , " EcaListContexts" )
349+ eq (cmd_registered_name (" EcaListContexts" ), " EcaListContexts" )
358350end
359351
360352T [" EcaListContexts" ][" shows deprecation notice when called" ] = function ()
372364T [" EcaChatClearContexts" ] = MiniTest .new_set ()
373365
374366T [" EcaChatClearContexts" ][" command is registered" ] = function ()
375- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
376- eq (type (commands .EcaChatClearContexts ), " table" )
377- eq (commands .EcaChatClearContexts .name , " EcaChatClearContexts" )
367+ eq (cmd_registered_name (" EcaChatClearContexts" ), " EcaChatClearContexts" )
378368end
379369
380370T [" EcaChatClearContexts" ][" clears all contexts" ] = function ()
395385T [" EcaClearContexts" ] = MiniTest .new_set ()
396386
397387T [" EcaClearContexts" ][" command is registered" ] = function ()
398- local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
399- eq (type (commands .EcaClearContexts ), " table" )
400- eq (commands .EcaClearContexts .name , " EcaClearContexts" )
388+ eq (cmd_registered_name (" EcaClearContexts" ), " EcaClearContexts" )
401389end
402390
403391T [" EcaClearContexts" ][" shows deprecation notice when called" ] = function ()
0 commit comments