aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/buffer_spec.lua123
-rw-r--r--test/functional/api/keymap_spec.lua5
-rw-r--r--test/functional/api/server_notifications_spec.lua16
-rw-r--r--test/functional/api/vim_spec.lua81
4 files changed, 225 insertions, 0 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 8ed642b43e..fb8ed6a9d7 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -392,6 +392,129 @@ describe('api/buf', function()
end)
end)
+ describe('nvim_buf_get_lines, nvim_buf_set_text', function()
+ local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text
+
+ it('works', function()
+ insert([[
+ hello foo!
+ text
+ ]])
+
+ eq({'hello foo!'}, get_lines(0, 1, true))
+
+
+ -- can replace a single word
+ set_text(0, 6, 0, 9, {'world'})
+ eq({'hello world!', 'text'}, get_lines(0, 2, true))
+
+ -- can insert text
+ set_text(0, 0, 0, 0, {'well '})
+ eq({'well hello world!', 'text'}, get_lines(0, 2, true))
+
+ -- can delete text
+ set_text(0, 0, 0, 5, {''})
+ eq({'hello world!', 'text'}, get_lines(0, 2, true))
+
+ -- can replace with multiple lines
+ set_text(0, 6, 0, 11, {'foo', 'wo', 'more'})
+ eq({'hello foo', 'wo', 'more!', 'text'}, get_lines(0, 4, true))
+
+ -- will join multiple lines if needed
+ set_text(0, 6, 3, 4, {'bar'})
+ eq({'hello bar'}, get_lines(0, 1, true))
+ end)
+
+ it('works with undo', function()
+ insert([[
+ hello world!
+ foo bar
+ ]])
+
+ -- setting text
+ set_text(0, 0, 0, 0, {'well '})
+ feed('u')
+ eq({'hello world!'}, get_lines(0, 1, true))
+
+ -- deleting text
+ set_text(0, 0, 0, 6, {''})
+ feed('u')
+ eq({'hello world!'}, get_lines(0, 1, true))
+
+ -- inserting newlines
+ set_text(0, 0, 0, 0, {'hello', 'mr '})
+ feed('u')
+ eq({'hello world!'}, get_lines(0, 1, true))
+
+ -- deleting newlines
+ set_text(0, 0, 1, 4, {'hello'})
+ feed('u')
+ eq({'hello world!'}, get_lines(0, 1, true))
+ end)
+
+ it('updates the cursor position', function()
+ insert([[
+ hello world!
+ ]])
+
+ -- position the cursor on `!`
+ curwin('set_cursor', {1, 11})
+ -- replace 'world' with 'foo'
+ set_text(0, 6, 0, 11, {'foo'})
+ eq('hello foo!', curbuf_depr('get_line', 0))
+ -- cursor should be moved left by two columns (replacement is shorter by 2 chars)
+ eq({1, 9}, curwin('get_cursor'))
+ end)
+
+ it('can handle NULs', function()
+ set_text(0, 0, 0, 0, {'ab\0cd'})
+ eq('ab\0cd', curbuf_depr('get_line', 0))
+ end)
+
+ it('adjusts extmarks', function()
+ local ns = request('nvim_create_namespace', "my-fancy-plugin")
+ insert([[
+ foo bar
+ baz
+ ]])
+ local id1 = curbufmeths.set_extmark(ns, 0, 1, {})
+ local id2 = curbufmeths.set_extmark(ns, 0, 7, {})
+ local id3 = curbufmeths.set_extmark(ns, 1, 1, {})
+ set_text(0, 4, 0, 7, {"q"})
+
+ eq({'foo q', 'baz'}, get_lines(0, 2, true))
+ -- mark before replacement point is unaffected
+ eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ -- mark gets shifted back because the replacement was shorter
+ eq({0, 5}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ -- mark on the next line is unaffected
+ eq({1, 1}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+
+ -- replacing the text spanning two lines will adjust the mark on the next line
+ set_text(0, 3, 1, 3, {"qux"})
+ eq({'fooqux', ''}, get_lines(0, 2, true))
+ eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ -- but mark before replacement point is still unaffected
+ eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ -- and the mark in the middle was shifted to the end of the insertion
+ eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+
+ -- marks should be put back into the same place after undoing
+ set_text(0, 0, 0, 2, {''})
+ feed('u')
+ eq({0, 1}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({0, 6}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+
+ -- marks should be shifted over by the correct number of bytes for multibyte
+ -- chars
+ set_text(0, 0, 0, 0, {'Ø'})
+ eq({0, 3}, curbufmeths.get_extmark_by_id(ns, id1, {}))
+ eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id2, {}))
+ eq({0, 8}, curbufmeths.get_extmark_by_id(ns, id3, {}))
+ end)
+ end)
+
describe('nvim_buf_get_offset', function()
local get_offset = curbufmeths.get_offset
it('works', function()
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index d8a9c3b411..4194945645 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -809,4 +809,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
command('normal lhs')
eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1))
end)
+
+ it("does not crash when setting keymap in a non-existing buffer #13541", function()
+ pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
+ helpers.assert_alive()
+ end)
end)
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua
index 29cd38ef0d..9ee2570798 100644
--- a/test/functional/api/server_notifications_spec.lua
+++ b/test/functional/api/server_notifications_spec.lua
@@ -3,6 +3,8 @@ local eq, clear, eval, command, nvim, next_msg =
helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim,
helpers.next_msg
local meths = helpers.meths
+local exec_lua = helpers.exec_lua
+local retry = helpers.retry
describe('notify', function()
local channel
@@ -72,4 +74,18 @@ describe('notify', function()
nvim('unsubscribe', 'event1')
eq(2, eval('1+1')) -- Still alive?
end)
+
+ it('cancels stale events on channel close', function()
+ if helpers.pending_win32(pending) then return end
+ local catchan = eval("jobstart(['cat'], {'rpc': v:true})")
+ eq({id=catchan, stream='job', mode='rpc', client = {}}, exec_lua ([[
+ vim.rpcnotify(..., "nvim_call_function", 'chanclose', {..., 'rpc'})
+ vim.rpcnotify(..., "nvim_subscribe", "daily_rant")
+ return vim.api.nvim_get_chan_info(...)
+ ]], catchan))
+ eq(2, eval('1+1')) -- Still alive?
+ eq({false, 'Invalid channel: '..catchan},
+ exec_lua ([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan))
+ retry(nil, 3000, function() eq({}, meths.get_chan_info(catchan)) end) -- cat be dead :(
+ end)
end)
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index eb5fd7eca7..30128e9c40 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -972,6 +972,12 @@ describe('API', function()
nvim("input", "gu")
eq({mode='no', blocking=false}, nvim("get_mode"))
end)
+
+ it("at '-- More --' prompt returns blocking=true #11899", function()
+ command('set more')
+ feed(':digraphs<cr>')
+ eq({mode='rm', blocking=true}, nvim("get_mode"))
+ end)
end)
describe('RPC (K_EVENT) #6166', function()
@@ -1921,4 +1927,79 @@ describe('API', function()
eq({}, meths.get_runtime_file("foobarlang/", true))
end)
end)
+
+ describe('nvim_get_all_options_info', function()
+ it('should have key value pairs of option names', function()
+ local options_info = meths.get_all_options_info()
+ neq(nil, options_info.listchars)
+ neq(nil, options_info.tabstop)
+
+ eq(meths.get_option_info'winhighlight', options_info.winhighlight)
+ end)
+ end)
+
+ describe('nvim_get_option_info', function()
+ it('should error for unknown options', function()
+ eq("no such option: 'bogus'", pcall_err(meths.get_option_info, 'bogus'))
+ end)
+
+ it('should return the same options for short and long name', function()
+ eq(meths.get_option_info'winhl', meths.get_option_info'winhighlight')
+ end)
+
+ it('should have information about window options', function()
+ eq({
+ commalist = false;
+ default = "";
+ flaglist = false;
+ global_local = false;
+ last_set_chan = 0;
+ last_set_linenr = 0;
+ last_set_sid = 0;
+ name = "winhighlight";
+ scope = "win";
+ shortname = "winhl";
+ type = "string";
+ was_set = false;
+ }, meths.get_option_info'winhl')
+ end)
+
+ it('should have information about buffer options', function()
+ eq({
+ commalist = false,
+ default = "",
+ flaglist = false,
+ global_local = false,
+ last_set_chan = 0,
+ last_set_linenr = 0,
+ last_set_sid = 0,
+ name = "filetype",
+ scope = "buf",
+ shortname = "ft",
+ type = "string",
+ was_set = false
+ }, meths.get_option_info'filetype')
+ end)
+
+ it('should have information about global options', function()
+ -- precondition: the option was changed from its default
+ -- in test setup.
+ eq(false, meths.get_option'showcmd')
+
+ eq({
+ commalist = false,
+ default = true,
+ flaglist = false,
+ global_local = false,
+ last_set_chan = 0,
+ last_set_linenr = 0,
+ last_set_sid = -2,
+ name = "showcmd",
+ scope = "global",
+ shortname = "sc",
+ type = "boolean",
+ was_set = true
+ }, meths.get_option_info'showcmd')
+ end)
+ end)
end)