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.lua35
-rw-r--r--test/functional/api/buffer_updates_spec.lua26
-rw-r--r--test/functional/api/vim_spec.lua22
-rw-r--r--test/functional/api/window_spec.lua37
4 files changed, 114 insertions, 6 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index d9412f0f13..93599c04f1 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -1,7 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer
local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq
local curbufmeths, ok = helpers.curbufmeths, helpers.ok
+local meths = helpers.meths
local funcs = helpers.funcs
local request = helpers.request
local exc_exec = helpers.exc_exec
@@ -11,6 +13,7 @@ local NIL = helpers.NIL
local meth_pcall = helpers.meth_pcall
local command = helpers.command
local bufmeths = helpers.bufmeths
+local feed = helpers.feed
describe('api/buf', function()
before_each(clear)
@@ -299,6 +302,38 @@ describe('api/buf', function()
local retval = exc_exec("call nvim_buf_set_lines(1, 0, 1, v:false, ['test'])")
eq(0, retval)
end)
+
+ it("set_lines of invisible buffer doesn't move cursor in current window", function()
+ local screen = Screen.new(20, 5)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ [2] = {bold = true},
+ })
+ screen:attach()
+
+ insert([[
+ Who would win?
+ A real window
+ with proper text]])
+ local buf = meths.create_buf(false,true)
+ screen:expect([[
+ Who would win? |
+ A real window |
+ with proper tex^t |
+ {1:~ }|
+ |
+ ]])
+
+ meths.buf_set_lines(buf, 0, -1, true, {'or some', 'scratchy text'})
+ feed('i') -- provoke redraw
+ screen:expect([[
+ Who would win? |
+ A real window |
+ with proper tex^t |
+ {1:~ }|
+ {2:-- INSERT --} |
+ ]])
+ end)
end)
describe('get_offset', function()
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index b54d9e1f6e..b894d2facd 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -678,6 +678,32 @@ describe('API: buffer events:', function()
expectn('Hello There', {})
end)
+ it(':edit! (reload) causes detach #9642', function()
+ local b, tick = editoriginal(true, {'AAA', 'BBB'})
+ command('set undoreload=1')
+
+ command('normal! x')
+ tick = tick + 1
+ expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
+
+ command('edit!')
+ expectn('nvim_buf_detach_event', {b})
+ end)
+
+ it(':enew! does not detach hidden buffer', function()
+ local b, tick = editoriginal(true, {'AAA', 'BBB'})
+ local channel = nvim('get_api_info')[1]
+
+ command('set undoreload=1 hidden')
+ command('normal! x')
+ tick = tick + 1
+ expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
+
+ command('enew!')
+ eval('rpcnotify('..channel..', "Hello There")')
+ expectn('Hello There', {})
+ end)
+
it('stays attached if the buffer is hidden', function()
local b, tick = editoriginal(true, {'AAA'})
local channel = nvim('get_api_info')[1]
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index b10076c6da..75b9fb71c9 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -1359,6 +1359,9 @@ describe('API', function()
eq({id=1}, meths.get_current_buf())
local screen = Screen.new(20, 4)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ })
screen:attach()
--
@@ -1373,7 +1376,7 @@ describe('API', function()
end
--
- -- Visiting a scratch-buffer DOES change its properties.
+ -- Visiting a scratch-buffer DOES NOT change its properties.
--
meths.set_current_buf(edited_buf)
screen:expect([[
@@ -1381,12 +1384,19 @@ describe('API', function()
{1:~ }|
{1:~ }|
|
- ]], {
- [1] = {bold = true, foreground = Screen.colors.Blue1},
- })
- eq('', meths.buf_get_option(edited_buf, 'buftype'))
- eq('', meths.buf_get_option(edited_buf, 'bufhidden'))
+ ]])
+ eq('nofile', meths.buf_get_option(edited_buf, 'buftype'))
+ eq('hide', meths.buf_get_option(edited_buf, 'bufhidden'))
eq(false, meths.buf_get_option(edited_buf, 'swapfile'))
+
+ -- scratch buffer can be wiped without error
+ command('bwipe')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
end)
end)
end)
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 4496e1f644..4ff299cd18 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -286,4 +286,41 @@ describe('API/win', function()
ok(not window('is_valid', win))
end)
end)
+
+ describe('close', function()
+ it('can close current window', function()
+ local oldwin = meths.get_current_win()
+ command('split')
+ local newwin = meths.get_current_win()
+ meths.win_close(newwin,false)
+ eq({oldwin}, meths.list_wins())
+ end)
+
+ it('can close noncurrent window', function()
+ local oldwin = meths.get_current_win()
+ command('split')
+ local newwin = meths.get_current_win()
+ meths.win_close(oldwin,false)
+ eq({newwin}, meths.list_wins())
+ end)
+
+ it('handles changed buffer', function()
+ local oldwin = meths.get_current_win()
+ insert('text')
+ command('new')
+ local newwin = meths.get_current_win()
+ eq({false,"Vim:E37: No write since last change (add ! to override)"},
+ meth_pcall(meths.win_close, oldwin,false))
+ eq({newwin,oldwin}, meths.list_wins())
+ end)
+
+ it('handles changed buffer with force', function()
+ local oldwin = meths.get_current_win()
+ insert('text')
+ command('new')
+ local newwin = meths.get_current_win()
+ meths.win_close(oldwin,true)
+ eq({newwin}, meths.list_wins())
+ end)
+ end)
end)