diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/terminal/mouse_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/terminal/window_split_tab_spec.lua | 91 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 132 |
3 files changed, 135 insertions, 116 deletions
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 29c62d7be7..5e5558ee0a 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -101,7 +101,7 @@ describe('terminal mouse', function() line28 |line28 | line29 |line29 | line30 |line30 | - rows: 5, cols: 25 |rows: 5, cols: 25 | + rows: 5, cols: 24 |rows: 5, cols: 24 | {2:^ } |{2: } | ========== ========== | :vsp | @@ -111,7 +111,7 @@ describe('terminal mouse', function() {7: 1 }^ |line28 | {4:~ }|line29 | {4:~ }|line30 | - {4:~ }|rows: 5, cols: 25 | + {4:~ }|rows: 5, cols: 24 | {4:~ }|{2: } | ========== ========== | :enew | set number | @@ -121,16 +121,16 @@ describe('terminal mouse', function() {7: 27 }line |line28 | {7: 28 }line |line29 | {7: 29 }line |line30 | - {7: 30 }line |rows: 5, cols: 25 | + {7: 30 }line |rows: 5, cols: 24 | {7: 31 }^ |{2: } | ========== ========== | | ]]) feed('<c-w>li') screen:expect([[ - {7: 27 }line |line29 | - {7: 28 }line |line30 | - {7: 29 }line |rows: 5, cols: 25 | + {7: 27 }line |line28 | + {7: 28 }line |line29 | + {7: 29 }line |line30 | {7: 30 }line |rows: 5, cols: 24 | {7: 31 } |{1: } | ========== ========== | @@ -140,8 +140,8 @@ describe('terminal mouse', function() thelpers.enable_mouse() thelpers.feed_data('mouse enabled\n') screen:expect([[ - {7: 27 }line |line30 | - {7: 28 }line |rows: 5, cols: 25 | + {7: 27 }line |line29 | + {7: 28 }line |line30 | {7: 29 }line |rows: 5, cols: 24 | {7: 30 }line |mouse enabled | {7: 31 } |{1: } | @@ -153,8 +153,8 @@ describe('terminal mouse', function() it('wont lose focus if another window is scrolled', function() feed('<ScrollWheelUp><0,0><ScrollWheelUp><0,0>') screen:expect([[ - {7: 21 }line |line30 | - {7: 22 }line |rows: 5, cols: 25 | + {7: 21 }line |line29 | + {7: 22 }line |line30 | {7: 23 }line |rows: 5, cols: 24 | {7: 24 }line |mouse enabled | {7: 25 }line |{1: } | @@ -163,8 +163,8 @@ describe('terminal mouse', function() ]]) feed('<S-ScrollWheelDown><0,0>') screen:expect([[ - {7: 26 }line |line30 | - {7: 27 }line |rows: 5, cols: 25 | + {7: 26 }line |line29 | + {7: 27 }line |line30 | {7: 28 }line |rows: 5, cols: 24 | {7: 29 }line |mouse enabled | {7: 30 }line |{1: } | @@ -176,8 +176,8 @@ describe('terminal mouse', function() it('will lose focus if another window is clicked', function() feed('<LeftMouse><5,1>') screen:expect([[ - {7: 27 }line |line30 | - {7: 28 }l^ine |rows: 5, cols: 25 | + {7: 27 }line |line29 | + {7: 28 }l^ine |line30 | {7: 29 }line |rows: 5, cols: 24 | {7: 30 }line |mouse enabled | {7: 31 } |{2: } | diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index c5199f620e..714c2476ce 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -3,6 +3,9 @@ local thelpers = require('test.functional.terminal.helpers') local clear = helpers.clear local feed, nvim = helpers.feed, helpers.nvim local feed_command = helpers.feed_command +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval describe('terminal', function() local screen @@ -22,72 +25,66 @@ describe('terminal', function() screen:detach() end) - it('resets its size when entering terminal window', function() + it('next to a closing window', function() + command('split') + command('terminal') + command('vsplit foo') + eq(3, eval("winnr('$')")) + feed('ZQ') -- Close split, should not crash. #7538 + eq(2, eval("1+1")) -- Still alive? + end) + + it('does not change size on WinEnter', function() if helpers.pending_win32(pending) then return end feed('<c-\\><c-n>') feed_command('2split') screen:expect([[ - rows: 2, cols: 50 | - {2:^ } | - ========== | - rows: 2, cols: 50 | - {2: } | - {4:~ }| - {4:~ }| - {4:~ }| - ========== | - :2split | - ]]) - feed_command('wincmd p') - screen:expect([[ tty ready | - rows: 2, cols: 50 | + ^rows: 5, cols: 50 | ========== | tty ready | - rows: 2, cols: 50 | rows: 5, cols: 50 | {2: } | - ^ | + | + | ========== | - :wincmd p | + :2split | ]]) feed_command('wincmd p') screen:expect([[ - rows: 2, cols: 50 | - {2:^ } | + tty ready | + rows: 5, cols: 50 | ========== | - rows: 2, cols: 50 | + tty ready | + ^rows: 5, cols: 50 | {2: } | - {4:~ }| - {4:~ }| - {4:~ }| + | + | ========== | :wincmd p | ]]) end) - describe('when the screen is resized', function() - it('will forward a resize request to the program', function() - feed([[<C-\><C-N>:]]) -- Go to cmdline-mode, so cursor is at bottom. - screen:try_resize(screen._width - 3, screen._height - 2) - screen:expect([[ - tty ready | - rows: 7, cols: 47 | - {2: } | - | - | - | - | - :^ | - ]]) - screen:try_resize(screen._width - 6, screen._height - 3) - screen:expect([[ - tty ready | - rows: 7, cols: 47 | - rows: 4, cols: 41 | - {2: } | - :^ | - ]]) - end) + it('forwards resize request to the program', function() + feed([[<C-\><C-N>:]]) -- Go to cmdline-mode, so cursor is at bottom. + screen:try_resize(screen._width - 3, screen._height - 2) + screen:expect([[ + tty ready | + rows: 7, cols: 47 | + {2: } | + | + | + | + | + :^ | + ]]) + screen:try_resize(screen._width - 6, screen._height - 3) + screen:expect([[ + tty ready | + rows: 7, cols: 47 | + rows: 4, cols: 41 | + {2: } | + :^ | + ]]) end) end) diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index befb204d0a..ed597eaed7 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -366,134 +366,156 @@ describe('path.c', function() end) describe('vim_FullName', function() - local function vim_FullName(filename, buf, len, force) - filename = to_cstr(filename) - return cimp.vim_FullName(filename, buf, len, force) + local function vim_FullName(filename, buflen, do_expand) + local buf = cstr(buflen, '') + local result = cimp.vim_FullName(to_cstr(filename), buf, buflen, do_expand) + return buf, result end - before_each(function() - -- Create empty string buffer which will contain the resulting path. - length = (string.len(lfs.currentdir())) + 33 - buffer = cstr(length, '') - end) + local function get_buf_len(s, t) + return math.max(string.len(s), string.len(t)) + 1 + end itp('fails if given filename is NULL', function() - local force_expansion = 1 - local result = cimp.vim_FullName(NULL, buffer, length, force_expansion) + local do_expand = 1 + local buflen = 10 + local buf = cstr(buflen, '') + local result = cimp.vim_FullName(NULL, buf, buflen, do_expand) eq(FAIL, result) end) itp('fails safely if given length is wrong #5737', function() - local force_expansion = 1 local filename = 'foo/bar/bazzzzzzz/buz/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a' local too_short_len = 8 local buf = cstr(too_short_len, '') - local result = cimp.vim_FullName(filename, buf, too_short_len, force_expansion) + local do_expand = 1 + local result = cimp.vim_FullName(filename, buf, too_short_len, do_expand) local expected = string.sub(filename, 1, (too_short_len - 1)) - eq(expected, (ffi.string(buf))) + eq(expected, ffi.string(buf)) eq(FAIL, result) end) itp('uses the filename if the filename is a URL', function() - local force_expansion = 1 local filename = 'http://www.neovim.org' - local result = vim_FullName(filename, buffer, length, force_expansion) - eq(filename, (ffi.string(buffer))) + local buflen = string.len(filename) + 1 + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(filename, ffi.string(buf)) eq(OK, result) end) itp('fails and uses filename if given filename contains non-existing directory', function() - local force_expansion = 1 local filename = 'non_existing_dir/test.file' - local result = vim_FullName(filename, buffer, length, force_expansion) - eq(filename, (ffi.string(buffer))) + local buflen = string.len(filename) + 1 + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(filename, ffi.string(buf)) eq(FAIL, result) end) itp('concatenates filename if it does not contain a slash', function() - local force_expansion = 1 - local result = vim_FullName('test.file', buffer, length, force_expansion) local expected = lfs.currentdir() .. '/test.file' - eq(expected, (ffi.string(buffer))) + local filename = 'test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('concatenates directory name if it does not contain a slash', function() - local force_expansion = 1 - local result = vim_FullName('..', buffer, length, force_expansion) local expected = lfs.currentdir() .. '/..' - eq(expected, (ffi.string(buffer))) + local filename = '..' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) - -- Is it possible for every developer to enter '..' directory while running - -- the unit tests? Which other directory would be better? itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function() - local force_expansion = 1 - local result = vim_FullName('../test.file', buffer, length, force_expansion) local old_dir = lfs.currentdir() lfs.chdir('..') local expected = lfs.currentdir() .. '/test.file' lfs.chdir(old_dir) - eq(expected, (ffi.string(buffer))) + local filename = '../test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('just copies the path if it is already absolute and force=0', function() - local force_expansion = 0 local absolute_path = '/absolute/path' - local result = vim_FullName(absolute_path, buffer, length, force_expansion) - eq(absolute_path, (ffi.string(buffer))) + local buflen = string.len(absolute_path) + 1 + local do_expand = 0 + local buf, result = vim_FullName(absolute_path, buflen, do_expand) + eq(absolute_path, ffi.string(buf)) eq(OK, result) end) itp('fails and uses filename when the path is relative to HOME', function() eq(false, cimp.os_isdir('~')) -- sanity check: no literal "~" directory. - local force_expansion = 1 local absolute_path = '~/home.file' - local result = vim_FullName(absolute_path, buffer, length, force_expansion) - eq(absolute_path, (ffi.string(buffer))) + local buflen = string.len(absolute_path) + 1 + local do_expand = 1 + local buf, result = vim_FullName(absolute_path, buflen, do_expand) + eq(absolute_path, ffi.string(buf)) eq(FAIL, result) end) itp('works with some "normal" relative path with directories', function() - local force_expansion = 1 - local result = vim_FullName('unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = 'unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) end) itp('does not modify the given filename', function() - local force_expansion = 1 + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' local filename = to_cstr('unit-test-directory/test.file') - -- Don't use the wrapper here but pass a cstring directly to the c - -- function. - local result = cimp.vim_FullName(filename, buffer, length, force_expansion) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) - eq('unit-test-directory/test.file', (ffi.string(filename))) + local buflen = string.len(expected) + 1 + local buf = cstr(buflen, '') + local do_expand = 1 + -- Don't use the wrapper but pass a cstring directly to the c function. + eq('unit-test-directory/test.file', ffi.string(filename)) + local result = cimp.vim_FullName(filename, buf, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('works with directories that have one path component', function() - local force_expansion = 1 - local filename = to_cstr('/tmp') - local result = cimp.vim_FullName(filename, buffer, length, force_expansion) - eq('/tmp', ffi.string(buffer)) + local filename = '/tmp' + local expected = filename + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq('/tmp', ffi.string(buf)) eq(OK, result) end) itp('expands "./" to the current directory #7117', function() - local force_expansion = 1 - local result = vim_FullName('./unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = './unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + eq(expected, ffi.string(buf)) end) itp('collapses "foo/../foo" to "foo" #7117', function() - local force_expansion = 1 - local result = vim_FullName('unit-test-directory/../unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = 'unit-test-directory/../unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + eq(expected, ffi.string(buf)) end) end) |