aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/buffer_spec.lua123
-rw-r--r--test/functional/legacy/assert_spec.lua12
-rw-r--r--test/functional/legacy/memory_usage_spec.lua46
-rw-r--r--test/functional/lua/buffer_updates_spec.lua67
-rw-r--r--test/functional/provider/define_spec.lua8
-rw-r--r--test/functional/ui/mouse_spec.lua22
-rw-r--r--test/functional/ui/screen.lua13
7 files changed, 251 insertions, 40 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/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua
index d48b8882af..515d6d91b8 100644
--- a/test/functional/legacy/assert_spec.lua
+++ b/test/functional/legacy/assert_spec.lua
@@ -242,9 +242,9 @@ describe('assert function:', function()
-- assert_fails({cmd}, [, {error}])
describe('assert_fails', function()
it('should change v:errors when error does not match v:errmsg', function()
- eq(1, eval([[assert_fails('xxx', {})]]))
- command([[call assert_match("Expected {} but got 'E731:", v:errors[0])]])
- expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"})
+ eq(1, eval([[assert_fails('xxx', 'E12345')]]))
+ command([[call assert_match("Expected 'E12345' but got 'E492:", v:errors[0])]])
+ expected_errors({"Expected 'E12345' but got 'E492: Not an editor command: xxx': xxx"})
end)
it('should not change v:errors when cmd errors', function()
@@ -258,9 +258,9 @@ describe('assert function:', function()
end)
it('can specify and get a message about what failed', function()
- eq(1, eval([[assert_fails('xxx', {}, 'stupid')]]))
- command([[call assert_match("stupid: Expected {} but got 'E731:", v:errors[0])]])
- expected_errors({"stupid: Expected {} but got 'E731: using Dictionary as a String'"})
+ eq(1, eval([[assert_fails('xxx', 'E9876', 'stupid')]]))
+ command([[call assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0])]])
+ expected_errors({"stupid: Expected 'E9876' but got 'E492: Not an editor command: xxx': stupid"})
end)
it('can specify and get a message even when cmd succeeds', function()
diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua
index fb0bacc2d2..5f7bbd887f 100644
--- a/test/functional/legacy/memory_usage_spec.lua
+++ b/test/functional/legacy/memory_usage_spec.lua
@@ -10,6 +10,29 @@ local source = helpers.source
local poke_eventloop = helpers.poke_eventloop
local uname = helpers.uname
local load_adjust = helpers.load_adjust
+local isCI = helpers.isCI
+
+local function isasan()
+ local version = eval('execute("version")')
+ return version:match('-fsanitize=[a-z,]*address')
+end
+
+clear()
+if isasan() then
+ pending('ASAN build is difficult to estimate memory usage', function() end)
+ return
+elseif iswin() then
+ if isCI('github') then
+ pending('Windows runners in Github Actions do not have a stable environment to estimate memory usage', function() end)
+ return
+ elseif eval("executable('wmic')") == 0 then
+ pending('missing "wmic" command', function() end)
+ return
+ end
+elseif eval("executable('ps')") == 0 then
+ pending('missing "ps" command', function() end)
+ return
+end
local monitor_memory_usage = {
memory_usage = function(self)
@@ -71,11 +94,6 @@ describe('memory usage', function()
end
end
- local function isasan()
- local version = eval('execute("version")')
- return version:match('-fsanitize=[a-z,]*address')
- end
-
before_each(clear)
--[[
@@ -83,15 +101,6 @@ describe('memory usage', function()
just after it finishes.
]]--
it('function capture vargs', function()
- if isasan() then
- pending('ASAN build is difficult to estimate memory usage')
- end
- if iswin() and eval("executable('wmic')") == 0 then
- pending('missing "wmic" command')
- elseif eval("executable('ps')") == 0 then
- pending('missing "ps" command')
- end
-
local pid = eval('getpid()')
local before = monitor_memory_usage(pid)
source([[
@@ -125,15 +134,6 @@ describe('memory usage', function()
increase so much even when rerun Xtest.vim since system memory caches.
]]--
it('function capture lvars', function()
- if isasan() then
- pending('ASAN build is difficult to estimate memory usage')
- end
- if iswin() and eval("executable('wmic')") == 0 then
- pending('missing "wmic" command')
- elseif eval("executable('ps')") == 0 then
- pending('missing "ps" command')
- end
-
local pid = eval('getpid()')
local before = monitor_memory_usage(pid)
local fname = source([[
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 9f2b1b6e52..67dc5f5a16 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -288,7 +288,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- TODO: while we are brewing the real strong coffe,
-- verify should check buf_get_offset after every check_events
if verify then
- meths.buf_get_offset(0, meths.buf_line_count(0))
+ local len = meths.buf_get_offset(0, meths.buf_line_count(0))
+ eq(len == -1 and 1 or len, string.len(shadowbytes))
end
exec_lua("return test_register(...)", 0, "test1", false, false, true)
meths.buf_get_changedtick(0)
@@ -510,6 +511,70 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 };
}
end)
+
+ it('nvim_buf_set_text insert', function()
+ local check_events = setup_eventcheck(verify, {"bastext"})
+ meths.buf_set_text(0, 0, 3, 0, 3, {"fiol","kontra"})
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 };
+ }
+
+ meths.buf_set_text(0, 1, 6, 1, 6, {"punkt","syntgitarr","övnings"})
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 };
+ }
+
+ eq({ "basfiol", "kontrapunkt", "syntgitarr", "övningstext" },
+ meths.buf_get_lines(0, 0, -1, true))
+ end)
+
+ it('nvim_buf_set_text replace', function()
+ local check_events = setup_eventcheck(verify, origlines)
+
+ meths.buf_set_text(0, 2, 3, 2, 8, {"very text"})
+ check_events {
+ { "test1", "bytes", 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 };
+ }
+
+ meths.buf_set_text(0, 3, 5, 3, 7, {" splitty","line "})
+ check_events {
+ { "test1", "bytes", 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 };
+ }
+
+ meths.buf_set_text(0, 0, 8, 1, 2, {"JOINY"})
+ check_events {
+ { "test1", "bytes", 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 };
+ }
+
+ meths.buf_set_text(0, 4, 0, 6, 0, {"was 5,6",""})
+ check_events {
+ { "test1", "bytes", 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 };
+ }
+
+ eq({ "originalJOINYiginal line 2", "orivery text line 3", "origi splitty",
+ "line l line 4", "was 5,6", " indented line" },
+ meths.buf_get_lines(0, 0, -1, true))
+
+ end)
+
+ it('nvim_buf_set_text delete', function()
+ local check_events = setup_eventcheck(verify, origlines)
+
+ -- really {""} but accepts {} as a shorthand
+ meths.buf_set_text(0, 0, 0, 1, 0, {})
+ check_events {
+ { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 };
+ }
+
+ -- TODO(bfredl): this works but is not as convenient as set_lines
+ meths.buf_set_text(0, 4, 15, 5, 17, {""})
+ check_events {
+ { "test1", "bytes", 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 };
+ }
+ eq({ "original line 2", "original line 3", "original line 4",
+ "original line 5", "original line 6" },
+ meths.buf_get_lines(0, 0, -1, true))
+ end)
end
describe('(with verify) handles', function()
diff --git a/test/functional/provider/define_spec.lua b/test/functional/provider/define_spec.lua
index 1d50ce0a56..12efbec326 100644
--- a/test/functional/provider/define_spec.lua
+++ b/test/functional/provider/define_spec.lua
@@ -136,7 +136,7 @@ local function command_specs_for(fn, sync, first_arg_factory, init)
end)
it('with nargs/count', function()
- call(fn, args..', {"nargs": "1", "range": "5"}')
+ call(fn, args..', {"nargs": "1", "count": "5"}')
local function on_setup()
command('5RpcCommand arg')
end
@@ -152,7 +152,7 @@ local function command_specs_for(fn, sync, first_arg_factory, init)
end)
it('with nargs/count/bang', function()
- call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}')
+ call(fn, args..', {"nargs": "1", "count": "5", "bang": ""}')
local function on_setup()
command('5RpcCommand! arg')
end
@@ -169,7 +169,7 @@ local function command_specs_for(fn, sync, first_arg_factory, init)
end)
it('with nargs/count/bang/register', function()
- call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'..
+ call(fn, args..', {"nargs": "1", "count": "5", "bang": "",'..
' "register": ""}')
local function on_setup()
command('5RpcCommand! b arg')
@@ -188,7 +188,7 @@ local function command_specs_for(fn, sync, first_arg_factory, init)
end)
it('with nargs/count/bang/register/eval', function()
- call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'..
+ call(fn, args..', {"nargs": "1", "count": "5", "bang": "",'..
' "register": "", "eval": "@<reg>"}')
local function on_setup()
command('let @b = "regb"')
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
index a741136111..7bca741ae3 100644
--- a/test/functional/ui/mouse_spec.lua
+++ b/test/functional/ui/mouse_spec.lua
@@ -45,13 +45,33 @@ describe('ui/mouse/input', function()
it('single left click moves cursor', function()
feed('<LeftMouse><2,1>')
- screen:expect([[
+ screen:expect{grid=[[
testing |
mo^use |
support and selection |
{0:~ }|
|
+ ]], mouse_enabled=true}
+ feed('<LeftMouse><0,0>')
+ screen:expect([[
+ ^testing |
+ mouse |
+ support and selection |
+ {0:~ }|
+ |
]])
+ end)
+
+ it("in external ui works with unset 'mouse'", function()
+ meths.set_option('mouse', '')
+ feed('<LeftMouse><2,1>')
+ screen:expect{grid=[[
+ testing |
+ mo^use |
+ support and selection |
+ {0:~ }|
+ |
+ ]], mouse_enabled=false}
feed('<LeftMouse><0,0>')
screen:expect([[
^testing |
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 8fa9fcc42f..fcf6926433 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -170,7 +170,7 @@ function Screen.new(width, height)
ruler = {},
hl_groups = {},
_default_attr_ids = nil,
- _mouse_enabled = true,
+ mouse_enabled = true,
_attrs = {},
_hl_info = {[0]={}},
_attr_table = {[0]={{},{}}},
@@ -318,7 +318,7 @@ function Screen:expect(expected, attr_ids, ...)
assert(next({...}) == nil, "invalid args to expect()")
if type(expected) == "table" then
assert(not (attr_ids ~= nil))
- local is_key = {grid=true, attr_ids=true, condition=true,
+ local is_key = {grid=true, attr_ids=true, condition=true, mouse_enabled=true,
any=true, mode=true, unchanged=true, intermediate=true,
reset=true, timeout=true, request_cb=true, hl_groups=true}
for _, v in ipairs(ext_keys) do
@@ -422,12 +422,15 @@ screen:redraw_debug() to show all intermediate screen states. ]])
if expected.mode ~= nil then
extstate.mode = self.mode
end
+ if expected.mouse_enabled ~= nil then
+ extstate.mouse_enabled = self.mouse_enabled
+ end
if expected.win_viewport == nil then
extstate.win_viewport = nil
end
-- Convert assertion errors into invalid screen state descriptions.
- for _, k in ipairs(concat_tables(ext_keys, {'mode'})) do
+ for _, k in ipairs(concat_tables(ext_keys, {'mode', 'mouse_enabled'})) do
-- Empty states are considered the default and need not be mentioned.
if (not (expected[k] == nil and isempty(extstate[k]))) then
local status, res = pcall(eq, expected[k], extstate[k], k)
@@ -799,11 +802,11 @@ function Screen:_handle_busy_stop()
end
function Screen:_handle_mouse_on()
- self._mouse_enabled = true
+ self.mouse_enabled = true
end
function Screen:_handle_mouse_off()
- self._mouse_enabled = false
+ self.mouse_enabled = false
end
function Screen:_handle_mode_change(mode, idx)