diff options
Diffstat (limited to 'test/functional/api')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 18 | ||||
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 9 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 161 |
3 files changed, 168 insertions, 20 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 01fcfab543..a0c97804b7 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -711,46 +711,46 @@ describe('api/buf', function() describe('nvim_buf_set_mark', function() it('works with buffer local marks', function() curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) - eq(true, curbufmeths.set_mark('z', 1, 1)) + eq(true, curbufmeths.set_mark('z', 1, 1, {})) eq({1, 1}, curbufmeths.get_mark('z')) end) it('works with file/uppercase marks', function() curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) - eq(true, curbufmeths.set_mark('Z', 3, 1)) + eq(true, curbufmeths.set_mark('Z', 3, 1, {})) eq({3, 1}, curbufmeths.get_mark('Z')) end) it('fails when invalid marks names are used', function() - eq(false, pcall(curbufmeths.set_mark, '!', 1, 0)) - eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0)) + eq(false, pcall(curbufmeths.set_mark, '!', 1, 0, {})) + eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0, {})) end) it('fails when invalid buffer number is used', function() - eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1)) + eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1, {})) end) end) describe('nvim_buf_del_mark', function() it('works with buffer local marks', function() curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) - curbufmeths.set_mark('z', 3, 1) + curbufmeths.set_mark('z', 3, 1, {}) eq(true, curbufmeths.del_mark('z')) eq({0, 0}, curbufmeths.get_mark('z')) end) it('works with file/uppercase marks', function() curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) - curbufmeths.set_mark('Z', 3, 3) + curbufmeths.set_mark('Z', 3, 3, {}) eq(true, curbufmeths.del_mark('Z')) eq({0, 0}, curbufmeths.get_mark('Z')) end) it('returns false in marks not set in this buffer', function() local abuf = meths.create_buf(false,true) bufmeths.set_lines(abuf, -1, -1, true, {'a', 'bit of', 'text'}) - bufmeths.set_mark(abuf, 'A', 2, 2) + bufmeths.set_mark(abuf, 'A', 2, 2, {}) eq(false, curbufmeths.del_mark('A')) eq({2, 2}, bufmeths.get_mark(abuf, 'A')) end) it('returns false if mark was not deleted', function() curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'}) - curbufmeths.set_mark('z', 3, 1) + curbufmeths.set_mark('z', 3, 1, {}) eq(true, curbufmeths.del_mark('z')) eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted end) diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index e408890906..309d9084c8 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -278,8 +278,9 @@ describe('server -> client', function() local nvim_argv = merge_args(helpers.nvim_argv, {'--headless'}) local function connect_test(server, mode, address) local serverpid = funcs.getpid() - local client = spawn(nvim_argv) - set_session(client, true) + local client = spawn(nvim_argv, false, nil, true) + set_session(client) + local clientpid = funcs.getpid() neq(serverpid, clientpid) local id = funcs.sockconnect(mode, address, {rpc=true}) @@ -288,7 +289,7 @@ describe('server -> client', function() funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1] - set_session(server, true) + set_session(server) eq(serverpid, funcs.getpid()) eq('hello', meths.get_current_line()) @@ -296,7 +297,7 @@ describe('server -> client', function() funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1]) - set_session(client, true) + set_session(client) eq(clientpid, funcs.getpid()) eq('howdy!', meths.get_current_line()) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d8914a3ab7..21de4925b5 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -22,6 +22,7 @@ local source = helpers.source local next_msg = helpers.next_msg local tmpname = helpers.tmpname local write_file = helpers.write_file +local exec_lua = helpers.exec_lua local pcall_err = helpers.pcall_err local format_string = helpers.format_string @@ -1689,7 +1690,7 @@ describe('API', function() end) local it_maybe_pending = it - if (helpers.isCI('appveyor') and os.getenv('CONFIGURATION') == 'MSVC_32') then + if helpers.isCI() and os.getenv('CONFIGURATION') == 'MSVC_32' then -- For "works with &opt" (flaky on MSVC_32), but not easy to skip alone. #10241 it_maybe_pending = pending end @@ -2264,6 +2265,9 @@ describe('API', function() [2] = {background = tonumber('0xffff40'), bg_indexed = true}; [3] = {background = Screen.colors.Plum1, fg_indexed = true, foreground = tonumber('0x00e000')}; [4] = {bold = true, reverse = true, background = Screen.colors.Plum1}; + [5] = {foreground = Screen.colors.Blue, background = Screen.colors.LightMagenta, bold = true}; + [6] = {bold = true}; + [7] = {reverse = true, background = Screen.colors.LightMagenta}; }) end) @@ -2311,13 +2315,81 @@ describe('API', function() | ]]} end) + + it('can handle input', function() + screen:try_resize(50, 10) + eq({3, 2}, exec_lua [[ + buf = vim.api.nvim_create_buf(1,1) + + stream = '' + do_the_echo = false + function input(_,t1,b1,data) + stream = stream .. data + _G.vals = {t1, b1} + if do_the_echo then + vim.api.nvim_chan_send(t1, data) + end + end + + term = vim.api.nvim_open_term(buf, {on_input=input}) + vim.api.nvim_open_win(buf, true, {width=40, height=5, row=1, col=1, relative='editor'}) + return {term, buf} + ]]) + + screen:expect{grid=[[ + | + {0:~}{1:^ }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]} + + feed 'iba<c-x>bla' + screen:expect{grid=[[ + | + {0:~}{7: }{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:-- TERMINAL --} | + ]]} + + eq('ba\024bla', exec_lua [[ return stream ]]) + eq({3,2}, exec_lua [[ return vals ]]) + + exec_lua [[ do_the_echo = true ]] + feed 'herrejösses!' + + screen:expect{grid=[[ + | + {0:~}{1:herrejösses!}{7: }{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~}{1: }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {6:-- TERMINAL --} | + ]]} + eq('ba\024blaherrejösses!', exec_lua [[ return stream ]]) + end) end) describe('nvim_del_mark', function() it('works', function() local buf = meths.create_buf(false,true) meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'}) - eq(true, meths.buf_set_mark(buf, 'F', 2, 2)) + eq(true, meths.buf_set_mark(buf, 'F', 2, 2, {})) eq(true, meths.del_mark('F')) eq({0, 0}, meths.buf_get_mark(buf, 'F')) end) @@ -2331,9 +2403,9 @@ describe('API', function() it('works', function() local buf = meths.create_buf(false,true) meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'}) - meths.buf_set_mark(buf, 'F', 2, 2) + meths.buf_set_mark(buf, 'F', 2, 2, {}) meths.buf_set_name(buf, "mybuf") - local mark = meths.get_mark('F') + local mark = meths.get_mark('F', {}) -- Compare the path tail ony assert(string.find(mark[4], "mybuf$")) eq({2, 2, buf.id, mark[4]}, mark) @@ -2345,7 +2417,7 @@ describe('API', function() end) it('returns the expected when mark is not set', function() eq(true, meths.del_mark('A')) - eq({0, 0, 0, ''}, meths.get_mark('A')) + eq({0, 0, 0, ''}, meths.get_mark('A', {})) end) it('works with deleted buffers', function() local fname = tmpname() @@ -2353,12 +2425,12 @@ describe('API', function() nvim("command", "edit " .. fname) local buf = meths.get_current_buf() - meths.buf_set_mark(buf, 'F', 2, 2) + meths.buf_set_mark(buf, 'F', 2, 2, {}) nvim("command", "new") -- Create new buf to avoid :bd failing nvim("command", "bd! " .. buf.id) os.remove(fname) - local mark = meths.get_mark('F') + local mark = meths.get_mark('F', {}) -- To avoid comparing relative vs absolute path local mfname = mark[4] local tail_patt = [[[\/][^\/]*$]] @@ -2367,4 +2439,79 @@ describe('API', function() eq({2, 2, buf.id, mark[4]}, mark) end) end) + describe('nvim_eval_statusline', function() + it('works', function() + eq({ + str = '%StatusLineStringWithHighlights', + width = 31 + }, + meths.eval_statusline( + '%%StatusLineString%#WarningMsg#WithHighlights', + {})) + end) + it('doesn\'t exceed maxwidth', function() + eq({ + str = 'Should be trun>', + width = 15 + }, + meths.eval_statusline( + 'Should be truncated%<', + { maxwidth = 15 })) + end) + describe('highlight parsing', function() + it('works', function() + eq({ + str = "TextWithWarningHighlightTextWithUserHighlight", + width = 45, + highlights = { + { start = 0, group = 'WarningMsg' }, + { start = 24, group = 'User1' } + }, + }, + meths.eval_statusline( + '%#WarningMsg#TextWithWarningHighlight%1*TextWithUserHighlight', + { highlights = true })) + end) + it('works with no highlight', function() + eq({ + str = "TextWithNoHighlight", + width = 19, + highlights = { + { start = 0, group = 'StatusLine' }, + }, + }, + meths.eval_statusline( + 'TextWithNoHighlight', + { highlights = true })) + end) + it('works with inactive statusline', function() + command('split') + + eq({ + str = 'TextWithNoHighlightTextWithWarningHighlight', + width = 43, + highlights = { + { start = 0, group = 'StatusLineNC' }, + { start = 19, group = 'WarningMsg' } + } + }, + meths.eval_statusline( + 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', + { winid = meths.list_wins()[2].id, highlights = true })) + end) + it('works with tabline', function() + eq({ + str = 'TextWithNoHighlightTextWithWarningHighlight', + width = 43, + highlights = { + { start = 0, group = 'TabLineFill' }, + { start = 19, group = 'WarningMsg' } + } + }, + meths.eval_statusline( + 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight', + { use_tabline = true, highlights = true })) + end) + end) + end) end) |