aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_getln.c6
-rw-r--r--src/nvim/screen.c5
-rw-r--r--src/nvim/testdir/test_alot.vim1
-rw-r--r--src/nvim/testdir/test_rename.vim119
-rw-r--r--src/nvim/testdir/test_startup.vim60
-rw-r--r--src/nvim/testdir/test_statusline.vim21
-rw-r--r--test/functional/ui/messages_spec.lua2
7 files changed, 209 insertions, 5 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 9977be56ca..76df01c205 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -775,9 +775,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
redrawcmd();
}
- // redraw the statusline for statuslines that display the current mode
- // using the mode() function.
- if (!cmd_silent && msg_scrolled == 0) {
+ // Redraw the statusline in case it uses the current mode using the mode()
+ // function.
+ if (!cmd_silent && msg_scrolled == 0 && *p_stl != NUL) {
curwin->w_redr_status = true;
redraw_statuslines();
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 1e20b77c5c..760a54a316 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -7609,8 +7609,9 @@ void win_new_shellsize(void)
static long old_Columns = 0;
if (old_Rows != Rows) {
- // if 'window' uses the whole screen, keep it using that */
- if (p_window == old_Rows - 1 || old_Rows == 0) {
+ // If 'window' uses the whole screen, keep it using that.
+ // Don't change it when set with "-w size" on the command line.
+ if (p_window == old_Rows - 1 || (old_Rows == 0 && p_window == 0)) {
p_window = Rows - 1;
}
old_Rows = Rows;
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index a47d20a265..71af3eead7 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -33,6 +33,7 @@ source test_move.vim
source test_partial.vim
source test_popup.vim
source test_put.vim
+source test_rename.vim
source test_scroll_opt.vim
source test_sort.vim
source test_sha256.vim
diff --git a/src/nvim/testdir/test_rename.vim b/src/nvim/testdir/test_rename.vim
new file mode 100644
index 0000000000..e4228188bd
--- /dev/null
+++ b/src/nvim/testdir/test_rename.vim
@@ -0,0 +1,119 @@
+" Test rename()
+
+func Test_rename_file_to_file()
+ call writefile(['foo'], 'Xrename1')
+
+ call assert_equal(0, rename('Xrename1', 'Xrename2'))
+
+ call assert_equal('', glob('Xrename1'))
+ call assert_equal(['foo'], readfile('Xrename2'))
+
+ " When the destination file already exists, it should be overwritten.
+ call writefile(['foo'], 'Xrename1')
+ call writefile(['bar'], 'Xrename2')
+
+ call assert_equal(0, rename('Xrename1', 'Xrename2'))
+ call assert_equal('', glob('Xrename1'))
+ call assert_equal(['foo'], readfile('Xrename2'))
+
+ call delete('Xrename2')
+endfunc
+
+func Test_rename_file_ignore_case()
+ " With 'fileignorecase', renaming file will go through a temp file
+ " when the source and destination file only differ by case.
+ set fileignorecase
+ call writefile(['foo'], 'Xrename')
+
+ call assert_equal(0, rename('Xrename', 'XRENAME'))
+
+ call assert_equal(['foo'], readfile('XRENAME'))
+
+ set fileignorecase&
+ call delete('XRENAME')
+endfunc
+
+func Test_rename_same_file()
+ call writefile(['foo'], 'Xrename')
+
+ " When the source and destination are the same file, nothing
+ " should be done. The source file should not be deleted.
+ call assert_equal(0, rename('Xrename', 'Xrename'))
+ call assert_equal(['foo'], readfile('Xrename'))
+
+ call assert_equal(0, rename('./Xrename', 'Xrename'))
+ call assert_equal(['foo'], readfile('Xrename'))
+
+ call delete('Xrename')
+endfunc
+
+func Test_rename_dir_to_dir()
+ call mkdir('Xrenamedir1')
+ call writefile(['foo'], 'Xrenamedir1/Xrenamefile')
+
+ call assert_equal(0, rename('Xrenamedir1', 'Xrenamedir2'))
+
+ call assert_equal('', glob('Xrenamedir1'))
+ call assert_equal(['foo'], readfile('Xrenamedir2/Xrenamefile'))
+
+ call delete('Xrenamedir2/Xrenamefile')
+ call delete('Xrenamedir2', 'd')
+endfunc
+
+func Test_rename_same_dir()
+ call mkdir('Xrenamedir')
+ call writefile(['foo'], 'Xrenamedir/Xrenamefile')
+
+ call assert_equal(0, rename('Xrenamedir', 'Xrenamedir'))
+
+ call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))
+
+ call delete('Xrenamedir/Xrenamefile')
+ call delete('Xrenamedir', 'd')
+endfunc
+
+func Test_rename_copy()
+ " Check that when original file can't be deleted, rename()
+ " still succeeds but copies the file.
+ call mkdir('Xrenamedir')
+ call writefile(['foo'], 'Xrenamedir/Xrenamefile')
+ call setfperm('Xrenamedir', 'r-xr-xr-x')
+
+ call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile'))
+
+ if !has('win32')
+ " On Windows, the source file is removed despite
+ " its directory being made not writable.
+ call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile'))
+ endif
+ call assert_equal(['foo'], readfile('Xrenamefile'))
+
+ call setfperm('Xrenamedir', 'rwxrwxrwx')
+ call delete('Xrenamedir/Xrenamefile')
+ call delete('Xrenamedir', 'd')
+ call delete('Xrenamefile')
+endfunc
+
+func Test_rename_fails()
+ throw 'skipped: TODO: '
+ call writefile(['foo'], 'Xrenamefile')
+
+ " Can't rename into a non-existing directory.
+ call assert_notequal(0, rename('Xrenamefile', 'Xdoesnotexist/Xrenamefile'))
+
+ " Can't rename a non-existing file.
+ call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile2'))
+ call assert_equal('', glob('Xrenamefile2'))
+
+ " When rename() fails, the destination file should not be deleted.
+ call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile'))
+ call assert_equal(['foo'], readfile('Xrenamefile'))
+
+ " Can't rename to en empty file name.
+ call assert_notequal(0, rename('Xrenamefile', ''))
+
+ call assert_fails('call rename("Xrenamefile", [])', 'E730')
+ call assert_fails('call rename(0z, "Xrenamefile")', 'E976')
+
+ call delete('Xrenamefile')
+endfunc
diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim
index eb9378194f..e0dc0e0075 100644
--- a/src/nvim/testdir/test_startup.vim
+++ b/src/nvim/testdir/test_startup.vim
@@ -814,6 +814,34 @@ func Test_v_argv()
call assert_equal(['arg1', '--cmd', 'echo v:argv', '--cmd', 'q'']'], list[idx:])
endfunc
+" Test for the '-t' option to jump to a tag
+func Test_t_arg()
+ let before =<< trim [CODE]
+ set tags=Xtags
+ [CODE]
+ let after =<< trim [CODE]
+ let s = bufname('') .. ':L' .. line('.') .. 'C' .. col('.')
+ call writefile([s], "Xtestout")
+ qall
+ [CODE]
+ call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
+ \ "first\tXfile1\t/^ \\zsfirst$/",
+ \ "second\tXfile1\t/^ \\zssecond$/",
+ \ "third\tXfile1\t/^ \\zsthird$/"],
+ \ 'Xtags')
+ call writefile([' first', ' second', ' third'], 'Xfile1')
+
+ for t_arg in ['-t second', '-tsecond']
+ if RunVim(before, after, '-t second')
+ call assert_equal(['Xfile1:L2C5'], readfile('Xtestout'), t_arg)
+ call delete('Xtestout')
+ endif
+ endfor
+
+ call delete('Xtags')
+ call delete('Xfile1')
+endfunc
+
" Test the '-T' argument which sets the 'term' option.
func Test_T_arg()
throw 'skipped: Nvim does not support "-T" argument'
@@ -890,6 +918,38 @@ func Test_not_a_term()
endfunc
+" Test for the "-w scriptout" argument
+func Test_w_arg()
+ " Can't catch the output of gvim.
+ CheckNotGui
+
+ call writefile(["iVim Editor\<Esc>:q!\<CR>"], 'Xscriptin', 'b')
+ if RunVim([], [], '-s Xscriptin -w Xscriptout')
+ call assert_equal(["iVim Editor\e:q!\r"], readfile('Xscriptout'))
+ call delete('Xscriptout')
+ endif
+ call delete('Xscriptin')
+
+ " Test for failing to open the script output file. This test works only when
+ " the language is English.
+ if !has('win32') && (v:lang == "C" || v:lang =~ '^[Ee]n')
+ call mkdir("Xdir")
+ let m = system(GetVimCommand() .. " -w Xdir")
+ call assert_equal("Cannot open for script output: \"Xdir\"\n", m)
+ call delete("Xdir", 'rf')
+ endif
+
+ " A number argument sets the 'window' option
+ call writefile(["iwindow \<C-R>=&window\<CR>\<Esc>:wq! Xresult\<CR>"], 'Xscriptin', 'b')
+ for w_arg in ['-w 17', '-w17']
+ if RunVim([], [], '-s Xscriptin ' .. w_arg)
+ call assert_equal(["window 17"], readfile('Xresult'), w_arg)
+ call delete('Xresult')
+ endif
+ endfor
+ call delete('Xscriptin')
+endfunc
+
" Test starting vim with various names: vim, ex, view, evim, etc.
func Test_progname()
CheckUnix
diff --git a/src/nvim/testdir/test_statusline.vim b/src/nvim/testdir/test_statusline.vim
index ce2ef4dcd8..48b7b4f2f1 100644
--- a/src/nvim/testdir/test_statusline.vim
+++ b/src/nvim/testdir/test_statusline.vim
@@ -440,6 +440,27 @@ func Test_statusline_removed_group()
call delete('XTest_statusline')
endfunc
+func Test_statusline_using_mode()
+ CheckScreendump
+
+ let lines =<< trim END
+ set laststatus=2
+ let &statusline = '-%{mode()}-'
+ END
+ call writefile(lines, 'XTest_statusline')
+
+ let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 5, 'cols': 50})
+ call VerifyScreenDump(buf, 'Test_statusline_mode_1', {})
+
+ call term_sendkeys(buf, ":")
+ call VerifyScreenDump(buf, 'Test_statusline_mode_2', {})
+
+ " clean up
+ call term_sendkeys(buf, "\<CR>")
+ call StopVimInTerminal(buf)
+ call delete('XTest_statusline')
+endfunc
+
func Test_statusline_after_split_vsplit()
only
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index 1fe3a4128e..9d7719a7c0 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -456,6 +456,8 @@ describe('ui/ext_messages', function()
{1:~ }|
]], messages={
{kind="echomsg", content={{"stuff"}}},
+ }, showmode={
+ { "-- INSERT --", 3 }
}}
end)