diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/buffer_spec.lua | 75 | ||||
-rw-r--r-- | test/functional/ex_cmds/map_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/fixtures/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/vimscript/screenchar_spec.lua | 69 | ||||
-rw-r--r-- | test/helpers.lua | 3 |
6 files changed, 145 insertions, 30 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index dd3af8c28f..dc668e7201 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -227,8 +227,8 @@ describe('api/buf', function() it('can get a single line with strict indexing', function() set_lines(0, 1, true, {'line1.a'}) eq(1, line_count()) -- sanity - eq(false, pcall(get_lines, 1, 2, true)) - eq(false, pcall(get_lines, -3, -2, true)) + eq('Index out of bounds', pcall_err(get_lines, 1, 2, true)) + eq('Index out of bounds', pcall_err(get_lines, -3, -2, true)) end) it('can get a single line with non-strict indexing', function() @@ -240,11 +240,11 @@ describe('api/buf', function() it('can set and delete a single line with strict indexing', function() set_lines(0, 1, true, {'line1.a'}) - eq(false, pcall(set_lines, 1, 2, true, {'line1.b'})) - eq(false, pcall(set_lines, -3, -2, true, {'line1.c'})) + eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {'line1.b'})) + eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {'line1.c'})) eq({'line1.a'}, get_lines(0, -1, true)) - eq(false, pcall(set_lines, 1, 2, true, {})) - eq(false, pcall(set_lines, -3, -2, true, {})) + eq('Index out of bounds', pcall_err(set_lines, 1, 2, true, {})) + eq('Index out of bounds', pcall_err(set_lines, -3, -2, true, {})) eq({'line1.a'}, get_lines(0, -1, true)) end) @@ -302,9 +302,9 @@ describe('api/buf', function() set_lines(0, -1, true, {'a', 'b', 'c'}) eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity - eq(false, pcall(get_lines, 3, 4, true)) - eq(false, pcall(get_lines, 3, 10, true)) - eq(false, pcall(get_lines, -5, -5, true)) + eq('Index out of bounds', pcall_err(get_lines, 3, 4, true)) + eq('Index out of bounds', pcall_err(get_lines, 3, 10, true)) + eq('Index out of bounds', pcall_err(get_lines, -5, -5, true)) -- empty or inverted ranges are not errors eq({}, get_lines(3, -1, true)) eq({}, get_lines(-3, -4, true)) @@ -316,10 +316,10 @@ describe('api/buf', function() eq({'c'}, get_lines(-2, 5, false)) eq({'a', 'b', 'c'}, get_lines(0, 6, false)) - eq(false, pcall(set_lines, 4, 6, true, {'d'})) + eq('Index out of bounds', pcall_err(set_lines, 4, 6, true, {'d'})) set_lines(4, 6, false, {'d'}) eq({'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) - eq(false, pcall(set_lines, -6, -6, true, {'e'})) + eq('Index out of bounds', pcall_err(set_lines, -6, -6, true, {'e'})) set_lines(-6, -6, false, {'e'}) eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true)) end) @@ -392,7 +392,7 @@ describe('api/buf', function() end) end) - describe('nvim_buf_get_lines, nvim_buf_set_text', function() + describe('nvim_buf_set_text', function() local get_lines, set_text = curbufmeths.get_lines, curbufmeths.set_text it('works', function() @@ -430,6 +430,10 @@ describe('api/buf', function() set_text(-1, 0, -1, 0, {'text'}) eq({'goodbye bar', 'text'}, get_lines(0, 2, true)) + + -- can append to a line + set_text(1, 4, -1, 4, {' and', 'more'}) + eq({'goodbye bar', 'text and', 'more'}, get_lines(0, 3, true)) end) it('works with undo', function() @@ -513,12 +517,12 @@ describe('api/buf', function() 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, {})) + -- 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) it("correctly marks changed region for redraw #13890", function() @@ -540,18 +544,39 @@ describe('api/buf', function() | ]]) + end) + it('errors on out-of-range', function() + insert([[ + hello foo! + text]]) + eq('start_row out of bounds', pcall_err(set_text, 2, 0, 3, 0, {})) + eq('start_row out of bounds', pcall_err(set_text, -3, 0, 0, 0, {})) + eq('end_row out of bounds', pcall_err(set_text, 0, 0, 2, 0, {})) + eq('end_row out of bounds', pcall_err(set_text, 0, 0, -3, 0, {})) + eq('start_col out of bounds', pcall_err(set_text, 1, 5, 1, 5, {})) + eq('end_col out of bounds', pcall_err(set_text, 1, 0, 1, 5, {})) + end) + + it('errors when start is greater than end', function() + insert([[ + hello foo! + text]]) + eq('start is higher than end', pcall_err(set_text, 1, 0, 0, 0, {})) + eq('start is higher than end', pcall_err(set_text, 0, 1, 0, 0, {})) end) end) describe('nvim_buf_get_text', function() local get_text = curbufmeths.get_text - it('works', function() + before_each(function() insert([[ hello foo! text]]) + end) + it('works', function() eq({'hello'}, get_text(0, 0, 0, 5, {})) eq({'hello foo!'}, get_text(0, 0, 0, 42, {})) eq({'foo!'}, get_text(0, 6, 0, 10, {})) @@ -562,13 +587,17 @@ describe('api/buf', function() end) it('errors on out-of-range', function() - eq(false, pcall(get_text, 2, 0, 3, 0, {})) - eq(false, pcall(get_text, 0, 0, 4, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 2, 0, 3, 0, {})) + eq('Index out of bounds', pcall_err(get_text, -3, 0, 0, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, 2, 0, {})) + eq('Index out of bounds', pcall_err(get_text, 0, 0, -3, 0, {})) + -- no ml_get errors should happen #19017 + eq('', meths.get_vvar('errmsg')) end) it('errors when start is greater than end', function() - eq(false, pcall(get_text, 1, 0, 0, 0, {})) - eq(false, pcall(get_text, 0, 1, 0, 0, {})) + eq('start is higher than end', pcall_err(get_text, 1, 0, 0, 0, {})) + eq('start_col must be less than end_col', pcall_err(get_text, 0, 1, 0, 0, {})) end) end) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index eae36b9ae9..c6bdd017bd 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -86,7 +86,7 @@ n asdf1 qwert end) end) -describe(':*map cursor and redrawing', function() +describe('Screen', function() local screen before_each(function() clear() @@ -149,6 +149,18 @@ describe(':*map cursor and redrawing', function() ]]) end) + it('cursor position does not move after empty-string :cmap <expr> #19046', function() + command([[cnoremap <expr> <F2> '']]) + feed(':<F2>') + screen:expect([[ + | + ~ | + ~ | + ~ | + :^ | + ]]) + end) + it('cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336', function() exec([[ call setline(1, ['one', 'two', 'three']) @@ -157,12 +169,12 @@ describe(':*map cursor and redrawing', function() hi! link StatusLine ErrorMsg noremap <expr> <C-B> Func() func Func() - let g:on = !get(g:, 'on', 0) - redraws - return '' + let g:on = !get(g:, 'on', 0) + redraws + return '' endfunc func Status() - return get(g:, 'on', 0) ? '[on]' : '' + return get(g:, 'on', 0) ? '[on]' : '' endfunc set stl=%{Status()} ]]) diff --git a/test/functional/fixtures/CMakeLists.txt b/test/functional/fixtures/CMakeLists.txt index 270540de2e..6010fcaf1e 100644 --- a/test/functional/fixtures/CMakeLists.txt +++ b/test/functional/fixtures/CMakeLists.txt @@ -4,7 +4,7 @@ target_link_libraries(tty-test ${LIBUV_LIBRARIES}) add_executable(shell-test EXCLUDE_FROM_ALL shell-test.c) add_executable(printargs-test EXCLUDE_FROM_ALL printargs-test.c) add_executable(printenv-test EXCLUDE_FROM_ALL printenv-test.c) -if(WIN32) +if(MINGW) set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode) endif() diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index dfbcbbe688..883e0e373b 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1400,6 +1400,8 @@ describe('lua stdlib', function() pcall_err(exec_lua, 'return vim.bo.nosuchopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) + matches("Invalid buffer id: %-1$", + pcall_err(exec_lua, 'return vim.bo[-1].filetype')) end) it('vim.wo', function() @@ -1419,6 +1421,8 @@ describe('lua stdlib', function() pcall_err(exec_lua, 'return vim.wo.notanopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.wo[0][0].list')) + matches("Invalid window id: %-1$", + pcall_err(exec_lua, 'return vim.wo[-1].list')) eq(2, funcs.luaeval "vim.wo[1000].cole") exec_lua [[ vim.wo[1000].cole = 0 diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua new file mode 100644 index 0000000000..767e3c57ef --- /dev/null +++ b/test/functional/vimscript/screenchar_spec.lua @@ -0,0 +1,69 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq +local command, meths, funcs = helpers.command, helpers.meths, helpers.funcs +local tbl_deep_extend = helpers.tbl_deep_extend + +-- Set up two overlapping floating windows +local setup_floating_windows = function() + local base_opts = { + relative = 'editor', + height = 1, + width = 2, + anchor = 'NW', + style = 'minimal', + border = 'none', + } + + local bufnr_1 = meths.create_buf(false, true) + meths.buf_set_lines(bufnr_1, 0, -1, true, { 'aa' }) + local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts) + meths.open_win(bufnr_1, false, opts_1) + + local bufnr_2 = meths.create_buf(false, true) + meths.buf_set_lines(bufnr_2, 0, -1, true, { 'bb' }) + local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts) + meths.open_win(bufnr_2, false, opts_2) + + command('redraw') +end + +describe('screenchar() and family respect floating windows', function() + before_each(function() + clear() + -- These commands result into visible text `aabc`. + -- `aab` - from floating windows, `c` - from text in regular window. + meths.buf_set_lines(0, 0, -1, true, { 'cccc' }) + setup_floating_windows() + end) + + it('screenattr()', function() + local attr_1 = funcs.screenattr(1, 1) + local attr_2 = funcs.screenattr(1, 2) + local attr_3 = funcs.screenattr(1, 3) + local attr_4 = funcs.screenattr(1, 4) + eq(attr_1, attr_2) + eq(attr_1, attr_3) + neq(attr_1, attr_4) + end) + + it('screenchar()', function() + eq(97, funcs.screenchar(1, 1)) + eq(97, funcs.screenchar(1, 2)) + eq(98, funcs.screenchar(1, 3)) + eq(99, funcs.screenchar(1, 4)) + end) + + it('screenchars()', function() + eq({ 97 }, funcs.screenchars(1, 1)) + eq({ 97 }, funcs.screenchars(1, 2)) + eq({ 98 }, funcs.screenchars(1, 3)) + eq({ 99 }, funcs.screenchars(1, 4)) + end) + + it('screenstring()', function() + eq('a', funcs.screenstring(1, 1)) + eq('a', funcs.screenstring(1, 2)) + eq('b', funcs.screenstring(1, 3)) + eq('c', funcs.screenstring(1, 4)) + end) +end) diff --git a/test/helpers.lua b/test/helpers.lua index a3482d1b46..a1c3dfacd2 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -291,7 +291,8 @@ module.tmpname = (function() if tmpdir_is_local(tmpdir) then -- Cannot control os.tmpname() dir, so hack our own tmpname() impl. seq = seq + 1 - local fname = tmpdir..'/nvim-test-lua-'..seq + -- "…/Xtest_tmpdir/T42.7" + local fname = ('%s/%s.%d'):format(tmpdir, (_G._nvim_test_id or 'nvim-test'), seq) io.open(fname, 'w'):close() return fname else |