diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index db552010cb..7d83238a5c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.4. Last change: 2016 Jan 15 +*eval.txt* For Vim version 7.4. Last change: 2016 Jan 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -919,6 +919,11 @@ just above, except that indexes out of range cause an error. Examples: > Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an error. +Watch out for confusion between a namespace and a variable followed by a colon +for a sublist: > + mylist[n:] " uses variable n + mylist[s:] " uses namespace s:, error! + expr8.name entry in a |Dictionary| *expr-entry* @@ -1794,7 +1799,7 @@ cursor( {lnum}, {col} [, {off}]) Number move cursor to {lnum}, {col}, {off} cursor( {list}) Number move cursor to position in {list} deepcopy( {expr} [, {noref}]) any make a full copy of {expr} -delete( {fname}) Number delete file {fname} +delete( {fname} [, {flags}]) Number delete the file or directory {fname} did_filetype() Number TRUE if FileType autocommand event used diff_filler( {lnum}) Number diff filler lines about {lnum} diff_hlID( {lnum}, {col}) Number diff highlighting at {lnum}/{col} @@ -2748,10 +2753,20 @@ deepcopy({expr}[, {noref}]) *deepcopy()* *E698* {noref} set to 1 will fail. Also see |copy()|. -delete({fname}) *delete()* - Deletes the file by the name {fname}. The result is a Number, - which is 0 if the file was deleted successfully, and non-zero - when the deletion failed. +delete({fname} [, {flags}]) *delete()* + Without {flags} or with {flags} empty: Deletes the file by the + name {fname}. This also works when {fname} is a symbolic link. + + When {flags} is "d": Deletes the directory by the name + {fname}. This fails when directory {fname} is not empty. + + When {flags} is "rf": Deletes the directory by the name + {fname} and everything in it, recursively. BE CAREFUL! + A symbolic link itself is deleted, not what it points to. + + The result is a Number, which is 0 if the delete operation was + successful and -1 when the deletion failed or partly failed. + Use |remove()| to delete an item from a |List|. To delete a line from the buffer use |:delete|. Use |:exe| when the line number is in a variable. diff --git a/src/Makefile b/src/Makefile index c49d8af8bb..23664026b7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1992,12 +1992,15 @@ test1 \ test70 test71 test72 test73 test74 test75 test76 test77 test78 test79 \ test80 test81 test82 test83 test84 test85 test86 test87 test88 test89 \ test90 test91 test92 test93 test94 test95 test96 test97 test98 test99 \ - test100 test101 test102 test103 test104 test105 test106 test107: + test100 test101 test102 test103 test104 test105 test106 test107 test108: cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE) test_assert \ test_backspace_opt \ test_cdo \ + test_cursor_func \ + test_delete \ + test_expand \ test_hardcopy \ test_increment \ test_lispwords \ diff --git a/src/eval.c b/src/eval.c index 8eafba94f5..d38c391488 100644 --- a/src/eval.c +++ b/src/eval.c @@ -8132,7 +8132,7 @@ static struct fst {"cscope_connection",0,3, f_cscope_connection}, {"cursor", 1, 3, f_cursor}, {"deepcopy", 1, 2, f_deepcopy}, - {"delete", 1, 1, f_delete}, + {"delete", 1, 2, f_delete}, {"did_filetype", 0, 0, f_did_filetype}, {"diff_filler", 1, 1, f_diff_filler}, {"diff_hlID", 2, 2, f_diff_hlID}, @@ -10392,10 +10392,37 @@ f_delete(argvars, rettv) typval_T *argvars; typval_T *rettv; { + char_u nbuf[NUMBUFLEN]; + char_u *name; + char_u *flags; + + rettv->vval.v_number = -1; if (check_restricted() || check_secure()) - rettv->vval.v_number = -1; + return; + + name = get_tv_string(&argvars[0]); + if (name == NULL || *name == NUL) + { + EMSG(_(e_invarg)); + return; + } + + if (argvars[1].v_type != VAR_UNKNOWN) + flags = get_tv_string_buf(&argvars[1], nbuf); else - rettv->vval.v_number = mch_remove(get_tv_string(&argvars[0])); + flags = (char_u *)""; + + if (*flags == NUL) + /* delete a file */ + rettv->vval.v_number = mch_remove(name) == 0 ? 0 : -1; + else if (STRCMP(flags, "d") == 0) + /* delete an empty directory */ + rettv->vval.v_number = mch_rmdir(name) == 0 ? 0 : -1; + else if (STRCMP(flags, "rf") == 0) + /* delete a directory recursively */ + rettv->vval.v_number = delete_recursive(name); + else + EMSG2(_(e_invexpr2), flags); } /* @@ -20845,10 +20872,10 @@ find_name_end(arg, expr_start, expr_end, flags) else if (br_nest == 0 && mb_nest == 0 && *p == ':') { /* "s:" is start of "s:var", but "n:" is not and can be used in - * slice "[n:]". Also "xx:" is not a namespace. */ + * slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. */ len = (int)(p - arg); if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL) - || len > 1) + || (len > 1 && p[-1] != '}')) break; } diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 8819bec4ed..a4074c8583 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -2220,9 +2220,7 @@ do_arglist(str, what, after) i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data, &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND); ga_clear(&new_ga); - if (i == FAIL) - return FAIL; - if (exp_count == 0) + if (i == FAIL || exp_count == 0) { EMSG(_(e_nomatch)); return FAIL; @@ -2637,6 +2635,10 @@ ex_argdelete(eap) curwin->w_arg_idx -= n; else if (curwin->w_arg_idx > eap->line1) curwin->w_arg_idx = eap->line1; + if (ARGCOUNT == 0) + curwin->w_arg_idx = 0; + else if (curwin->w_arg_idx >= ARGCOUNT) + curwin->w_arg_idx = ARGCOUNT - 1; } } else if (*eap->arg == NUL) diff --git a/src/fileio.c b/src/fileio.c index f8478e6b69..5a05836efd 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -7318,6 +7318,58 @@ write_lnum_adjust(offset) curbuf->b_no_eol_lnum += offset; } +#if defined(TEMPDIRNAMES) || defined(FEAT_EVAL) || defined(PROTO) +/* + * Delete "name" and everything in it, recursively. + * return 0 for succes, -1 if some file was not deleted. + */ + int +delete_recursive(char_u *name) +{ + int result = 0; + char_u **files; + int file_count; + int i; + char_u *exp; + + /* A symbolic link to a directory itself is deleted, not the directory it + * points to. */ + if ( +# if defined(WIN32) + mch_isdir(name) && !mch_is_symbolic_link(name) +# else +# ifdef UNIX + mch_isrealdir(name) +# else + mch_isdir(name) +# endif +# endif + ) + { + vim_snprintf((char *)NameBuff, MAXPATHL, "%s/*", name); + exp = vim_strsave(NameBuff); + if (exp == NULL) + return -1; + if (gen_expand_wildcards(1, &exp, &file_count, &files, + EW_DIR|EW_FILE|EW_SILENT|EW_ALLLINKS|EW_DODOT|EW_EMPTYOK) == OK) + { + for (i = 0; i < file_count; ++i) + if (delete_recursive(files[i]) != 0) + result = -1; + FreeWild(file_count, files); + } + else + result = -1; + vim_free(exp); + (void)mch_rmdir(name); + } + else + result = mch_remove(name) == 0 ? 0 : -1; + + return result; +} +#endif + #if defined(TEMPDIRNAMES) || defined(PROTO) static long temp_count = 0; /* Temp filename counter. */ @@ -7327,30 +7379,16 @@ static long temp_count = 0; /* Temp filename counter. */ void vim_deltempdir() { - char_u **files; - int file_count; - int i; - if (vim_tempdir != NULL) { - sprintf((char *)NameBuff, "%s*", vim_tempdir); - if (gen_expand_wildcards(1, &NameBuff, &file_count, &files, - EW_DIR|EW_FILE|EW_SILENT) == OK) - { - for (i = 0; i < file_count; ++i) - mch_remove(files[i]); - FreeWild(file_count, files); - } - gettail(NameBuff)[-1] = NUL; - (void)mch_rmdir(NameBuff); - + /* remove the trailing path separator */ + gettail(vim_tempdir)[-1] = NUL; + delete_recursive(vim_tempdir); vim_free(vim_tempdir); vim_tempdir = NULL; } } -#endif -#ifdef TEMPDIRNAMES /* * Directory "tempdir" was created. Expand this name to a full path and put * it in "vim_tempdir". This avoids that using ":cd" would confuse us. diff --git a/src/misc1.c b/src/misc1.c index 124c713521..634d64ac75 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -10019,7 +10019,7 @@ dos_expandpath( if (p[0] == '*' && p[1] == '*') starstar = TRUE; - starts_with_dot = (*s == '.'); + starts_with_dot = *s == '.'; pat = file_pat_to_reg_pat(s, e, NULL, FALSE); if (pat == NULL) { @@ -10102,7 +10102,9 @@ dos_expandpath( #endif /* Ignore entries starting with a dot, unless when asked for. Accept * all entries found with "matchname". */ - if ((p[0] != '.' || starts_with_dot) + if ((p[0] != '.' || starts_with_dot + || ((flags & EW_DODOT) + && p[1] != NUL && (p[1] != '.' || p[2] != NUL))) && (matchname == NULL || (regmatch.regprog != NULL && vim_regexec(®match, p, (colnr_T)0)) @@ -10331,7 +10333,7 @@ unix_expandpath(gap, path, wildoff, flags, didstar) starstar = TRUE; /* convert the file pattern to a regexp pattern */ - starts_with_dot = (*s == '.'); + starts_with_dot = *s == '.'; pat = file_pat_to_reg_pat(s, e, NULL, FALSE); if (pat == NULL) { @@ -10380,7 +10382,10 @@ unix_expandpath(gap, path, wildoff, flags, didstar) dp = readdir(dirp); if (dp == NULL) break; - if ((dp->d_name[0] != '.' || starts_with_dot) + if ((dp->d_name[0] != '.' || starts_with_dot + || ((flags & EW_DODOT) + && dp->d_name[1] != NUL + && (dp->d_name[1] != '.' || dp->d_name[2] != NUL))) && ((regmatch.regprog != NULL && vim_regexec(®match, (char_u *)dp->d_name, (colnr_T)0)) || ((flags & EW_NOTWILD) @@ -11088,7 +11093,7 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags) recursive = FALSE; - return (ga.ga_data != NULL) ? retval : FAIL; + return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? retval : FAIL; } # ifdef VIM_BACKTICK diff --git a/src/misc2.c b/src/misc2.c index 3fd924f9c9..bf2d1f1111 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -5549,7 +5549,7 @@ find_file_in_path_option(ptr, len, options, first, path_option, /* copy file name into NameBuff, expanding environment variables */ save_char = ptr[len]; ptr[len] = NUL; - expand_env(ptr, NameBuff, MAXPATHL); + expand_env_esc(ptr, NameBuff, MAXPATHL, FALSE, TRUE, NULL); ptr[len] = save_char; vim_free(ff_file_to_find); diff --git a/src/os_unix.c b/src/os_unix.c index 0cb342451a..5e102423f9 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2996,7 +2996,7 @@ mch_hide(name) } /* - * return TRUE if "name" is a directory + * return TRUE if "name" is a directory or a symlink to a directory * return FALSE if "name" is not a directory * return FALSE for error */ @@ -3017,6 +3017,28 @@ mch_isdir(name) #endif } +/* + * return TRUE if "name" is a directory, NOT a symlink to a directory + * return FALSE if "name" is not a directory + * return FALSE for error + */ + int +mch_isrealdir(name) + char_u *name; +{ + struct stat statb; + + if (*name == NUL) /* Some stat()s don't flag "" as an error. */ + return FALSE; + if (lstat((char *)name, &statb)) + return FALSE; +#ifdef _POSIX_SOURCE + return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); +#else + return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); +#endif +} + static int executable_file __ARGS((char_u *name)); /* diff --git a/src/os_win32.c b/src/os_win32.c index c5b23ca7db..a47ffaf18a 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -3153,6 +3153,30 @@ mch_mkdir(char_u *name) return _mkdir(name); } +/* + * Delete directory "name". + * Return 0 on success, -1 on error. + */ + int +mch_rmdir(char_u *name) +{ +#ifdef FEAT_MBYTE + if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) + { + WCHAR *p; + int retval; + + p = enc_to_utf16(name, NULL); + if (p == NULL) + return -1; + retval = _wrmdir(p); + vim_free(p); + return retval; + } +#endif + return _rmdir(name); +} + /* * Return TRUE if file "fname" has more than one link. */ diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro index 32d7bce318..0f68a20c4a 100644 --- a/src/proto/fileio.pro +++ b/src/proto/fileio.pro @@ -22,6 +22,7 @@ int buf_check_timestamp __ARGS((buf_T *buf, int focus)); void buf_reload __ARGS((buf_T *buf, int orig_mode)); void buf_store_time __ARGS((buf_T *buf, struct stat *st, char_u *fname)); void write_lnum_adjust __ARGS((linenr_T offset)); +int delete_recursive __ARGS((char_u *name)); void vim_deltempdir __ARGS((void)); char_u *vim_tempname __ARGS((int extra_char, int keep)); void forward_slash __ARGS((char_u *fname)); diff --git a/src/proto/os_unix.pro b/src/proto/os_unix.pro index 89dff7791d..be6eb6f103 100644 --- a/src/proto/os_unix.pro +++ b/src/proto/os_unix.pro @@ -41,6 +41,7 @@ void mch_set_acl __ARGS((char_u *fname, vim_acl_T aclent)); void mch_free_acl __ARGS((vim_acl_T aclent)); void mch_hide __ARGS((char_u *name)); int mch_isdir __ARGS((char_u *name)); +int mch_isrealdir __ARGS((char_u *name)); int mch_can_exe __ARGS((char_u *name, char_u **path, int use_path)); int mch_nodetype __ARGS((char_u *name)); void mch_early_init __ARGS((void)); diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro index e6fce88a3b..7cdd15677a 100644 --- a/src/proto/os_win32.pro +++ b/src/proto/os_win32.pro @@ -22,6 +22,7 @@ void mch_hide __ARGS((char_u *name)); int mch_ishidden __ARGS((char_u *name)); int mch_isdir __ARGS((char_u *name)); int mch_mkdir __ARGS((char_u *name)); +int mch_rmdir __ARGS((char_u *name)); int mch_is_hard_link __ARGS((char_u *fname)); int mch_is_symbolic_link __ARGS((char_u *fname)); int mch_is_linked __ARGS((char_u *fname)); diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 33fc3451b7..69fd936cd1 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -139,7 +139,6 @@ SCRIPTS_MORE2 = \ test10.out \ test12.out \ test25.out \ - test27.out \ test49.out \ test97.out @@ -172,7 +171,8 @@ SCRIPTS_GUI = test16.out # Tests using runtest.vim.vim. # Keep test_alot.res as the last one, sort the others. -NEW_TESTS = test_assert.res \ +NEW_TESTS = test_arglist.res \ + test_assert.res \ test_cdo.res \ test_hardcopy.res \ test_increment.res \ diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak index c39e450d5c..cea4699cad 100644 --- a/src/testdir/Make_amiga.mak +++ b/src/testdir/Make_amiga.mak @@ -15,7 +15,6 @@ include Make_all.mak # test11 "cat" doesn't work properly # test12 can't unlink a swap file # test25 uses symbolic link -# test27 can't edit file with "*" # test52 only for Win32 # test85 no Lua interface # test86, 87 no Python interface diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak index f6e45d83eb..3073e9eb5c 100644 --- a/src/testdir/Make_dos.mak +++ b/src/testdir/Make_dos.mak @@ -14,7 +14,6 @@ default: nongui # test10 'errorformat' is different # test12 can't unlink a swap file # test25 uses symbolic link -# test27 can't edit file with "*" in file name # test49 fails in various ways # test97 \{ and \$ are not escaped characters. @@ -39,7 +38,7 @@ win32: nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) newtests report $(DOSTMP_INFILES): $(*B).in if not exist $(DOSTMP)\NUL md $(DOSTMP) if exist $@ del $@ - $(VIMPROG) -u dos.vim --noplugin "+set ff=dos|f $@|wq" $(*B).in + $(VIMPROG) -u dos.vim -U NONE --noplugin "+set ff=dos|f $@|wq" $(*B).in # For each input file dostmp/test99.in run the tests. # This moves test99.in to test99.in.bak temporarily. @@ -56,7 +55,7 @@ $(TEST_OUTFILES): $(DOSTMP)\$(*B).in -@if exist Xfind rd /s /q Xfind -@del X* -@if exist viminfo del viminfo - $(VIMPROG) -u dos.vim --noplugin "+set ff=unix|f test.out|wq" \ + $(VIMPROG) -u dos.vim -U NONE --noplugin "+set ff=unix|f test.out|wq" \ $(DOSTMP)\$(*B).out @diff test.out $*.ok & if errorlevel 1 \ ( move /y test.out $*.failed \ @@ -90,6 +89,7 @@ clean: -if exist Xdir1 rd /s /q Xdir1 -if exist Xfind rd /s /q Xfind -del X* + -for /d %i in (X*) do @rmdir /s/q %i -if exist viminfo del viminfo -if exist test.log del test.log -if exist messages del messages @@ -114,4 +114,4 @@ bench_re_freeze.out: bench_re_freeze.vim newtests: $(NEW_TESTS) .vim.res: - $(VIMPROG) -u NONE -S runtest.vim $*.vim + $(VIMPROG) -u NONE -U NONE -S runtest.vim $*.vim diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak index 88e72b15e2..d0b088c609 100644 --- a/src/testdir/Make_ming.mak +++ b/src/testdir/Make_ming.mak @@ -35,7 +35,6 @@ include Make_all.mak # test10 'errorformat' is different # test12 can't unlink a swap file # test25 uses symbolic link -# test27 can't edit file with "*" in file name # test54 doesn't work yet # test97 \{ and \$ are not escaped characters @@ -66,8 +65,8 @@ win32: fixff $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) echo ALL DONE fixff: - -$(VIMPROG) -u dos.vim --noplugin "+argdo set ff=dos|upd" +q *.in *.ok - -$(VIMPROG) -u dos.vim --noplugin "+argdo set ff=unix|upd" +q \ + -$(VIMPROG) -u dos.vim -U NONE --noplugin "+argdo set ff=dos|upd" +q *.in *.ok + -$(VIMPROG) -u dos.vim -U NONE --noplugin "+argdo set ff=unix|upd" +q \ dotest.in test60.ok test71.ok test74.ok test_listchars.ok clean: diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms index 9a93e21a75..17b7429943 100644 --- a/src/testdir/Make_vms.mms +++ b/src/testdir/Make_vms.mms @@ -163,7 +163,7 @@ SCRIPT_PYTHON = test86.out test87.out -@ write sys$output " "$*" " -@ write sys$output "-----------------------------------------------" -@ !run the test - -@ create/term/wait/nodetach mcr $(VIMPROG) $(GUI_OPTION) -u vms.vim --noplugin -s dotest.in $*.in + -@ create/term/wait/nodetach mcr $(VIMPROG) $(GUI_OPTION) -u vms.vim -U NONE --noplugin -s dotest.in $*.in -@ !analyse the result -@ directory /size/date test.out -@ if "''F$SEARCH("test.out.*")'" .NES. "" then rename/nolog test.out $*.out diff --git a/src/testdir/Makefile b/src/testdir/Makefile index 8f321b5852..6d98a80a34 100644 --- a/src/testdir/Makefile +++ b/src/testdir/Makefile @@ -127,4 +127,4 @@ newtestssilent: $(NEW_TESTS) .vim.res: - $(RUN_VIMTEST) -u NONE -S runtest.vim $*.vim + $(RUN_VIMTEST) -u NONE -U NONE -S runtest.vim $*.vim diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim index fd64c98fc3..686a4df625 100644 --- a/src/testdir/runtest.vim +++ b/src/testdir/runtest.vim @@ -43,6 +43,9 @@ set nomore " Output all messages in English. lang mess C +" Always use forward slashes. +set shellslash + let s:srcdir = expand('%:p:h:h') " Support function: get the alloc ID by name. @@ -81,6 +84,7 @@ else endif " Locate Test_ functions and execute them. +set nomore redir @q function /^Test_ redir END diff --git a/src/testdir/test108.in b/src/testdir/test108.in index b442cf7fcf..59c4dfc712 100644 --- a/src/testdir/test108.in +++ b/src/testdir/test108.in @@ -2,6 +2,7 @@ Tests for backtrace debug commands. vim: set ft=vim : STARTTEST :so small.vim +:lang mess C :function! Foo() : let var1 = 1 : let var2 = Bar(var1) + 9 diff --git a/src/testdir/test27.in b/src/testdir/test27.in deleted file mode 100644 index 2df16d9eff..0000000000 --- a/src/testdir/test27.in +++ /dev/null @@ -1,20 +0,0 @@ -Test for expanding file names - -STARTTEST -:!mkdir Xdir1 -:!mkdir Xdir2 -:!mkdir Xdir3 -:cd Xdir3 -:!mkdir Xdir4 -:cd .. -:w Xdir1/file -:w Xdir3/Xdir4/file -:n Xdir?/*/file -Go%:.w! test.out -:n! Xdir?/*/nofile -Go%:.w >>test.out -:e! xx -:!rm -rf Xdir1 Xdir2 Xdir3 -:qa! -ENDTEST - diff --git a/src/testdir/test27.ok b/src/testdir/test27.ok deleted file mode 100644 index c35f2438a9..0000000000 --- a/src/testdir/test27.ok +++ /dev/null @@ -1,2 +0,0 @@ -Xdir3/Xdir4/file -Xdir?/*/nofile diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim index 87bd26b458..e89afb49ad 100644 --- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -3,6 +3,8 @@ source test_backspace_opt.vim source test_cursor_func.vim +source test_delete.vim +source test_expand.vim source test_lispwords.vim source test_menu.vim source test_searchpos.vim diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim new file mode 100644 index 0000000000..3f72f0ff9c --- /dev/null +++ b/src/testdir/test_arglist.vim @@ -0,0 +1,22 @@ +" Test argument list commands + +func Test_argidx() + args a b c + last + call assert_equal(2, argidx()) + %argdelete + call assert_equal(0, argidx()) + + args a b c + call assert_equal(0, argidx()) + next + call assert_equal(1, argidx()) + next + call assert_equal(2, argidx()) + 1argdelete + call assert_equal(1, argidx()) + 1argdelete + call assert_equal(0, argidx()) + 1argdelete + call assert_equal(0, argidx()) +endfunc diff --git a/src/testdir/test_delete.vim b/src/testdir/test_delete.vim new file mode 100644 index 0000000000..3cf26234dc --- /dev/null +++ b/src/testdir/test_delete.vim @@ -0,0 +1,99 @@ +" Test for delete(). + +func Test_file_delete() + split Xfile + call setline(1, ['a', 'b']) + wq + call assert_equal(['a', 'b'], readfile('Xfile')) + call assert_equal(0, delete('Xfile')) + call assert_fails('call readfile("Xfile")', 'E484:') + call assert_equal(-1, delete('Xfile')) +endfunc + +func Test_dir_delete() + call mkdir('Xdir1') + call assert_true(isdirectory('Xdir1')) + call assert_equal(0, delete('Xdir1', 'd')) + call assert_false(isdirectory('Xdir1')) + call assert_equal(-1, delete('Xdir1', 'd')) +endfunc + +func Test_recursive_delete() + call mkdir('Xdir1') + call mkdir('Xdir1/subdir') + call mkdir('Xdir1/empty') + split Xdir1/Xfile + call setline(1, ['a', 'b']) + w + w Xdir1/subdir/Xfile + close + call assert_true(isdirectory('Xdir1')) + call assert_equal(['a', 'b'], readfile('Xdir1/Xfile')) + call assert_true(isdirectory('Xdir1/subdir')) + call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile')) + call assert_true(isdirectory('Xdir1/empty')) + call assert_equal(0, delete('Xdir1', 'rf')) + call assert_false(isdirectory('Xdir1')) + call assert_equal(-1, delete('Xdir1', 'd')) +endfunc + +func Test_symlink_delete() + if !has('unix') + return + endif + split Xfile + call setline(1, ['a', 'b']) + wq + silent !ln -s Xfile Xlink + " Delete the link, not the file + call assert_equal(0, delete('Xlink')) + call assert_equal(-1, delete('Xlink')) + call assert_equal(0, delete('Xfile')) +endfunc + +func Test_symlink_dir_delete() + if !has('unix') + return + endif + call mkdir('Xdir1') + silent !ln -s Xdir1 Xlink + call assert_true(isdirectory('Xdir1')) + call assert_true(isdirectory('Xlink')) + " Delete the link, not the directory + call assert_equal(0, delete('Xlink')) + call assert_equal(-1, delete('Xlink')) + call assert_equal(0, delete('Xdir1', 'd')) +endfunc + +func Test_symlink_recursive_delete() + if !has('unix') + return + endif + call mkdir('Xdir3') + call mkdir('Xdir3/subdir') + call mkdir('Xdir4') + split Xdir3/Xfile + call setline(1, ['a', 'b']) + w + w Xdir3/subdir/Xfile + w Xdir4/Xfile + close + silent !ln -s ../Xdir4 Xdir3/Xlink + + call assert_true(isdirectory('Xdir3')) + call assert_equal(['a', 'b'], readfile('Xdir3/Xfile')) + call assert_true(isdirectory('Xdir3/subdir')) + call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile')) + call assert_true(isdirectory('Xdir4')) + call assert_true(isdirectory('Xdir3/Xlink')) + call assert_equal(['a', 'b'], readfile('Xdir4/Xfile')) + + call assert_equal(0, delete('Xdir3', 'rf')) + call assert_false(isdirectory('Xdir3')) + call assert_equal(-1, delete('Xdir3', 'd')) + " symlink is deleted, not the directory it points to + call assert_true(isdirectory('Xdir4')) + call assert_equal(['a', 'b'], readfile('Xdir4/Xfile')) + call assert_equal(0, delete('Xdir4/Xfile')) + call assert_equal(0, delete('Xdir4', 'd')) +endfunc diff --git a/src/testdir/test_expand.vim b/src/testdir/test_expand.vim new file mode 100644 index 0000000000..c099edae1c --- /dev/null +++ b/src/testdir/test_expand.vim @@ -0,0 +1,41 @@ +" Test for expanding file names + +func Test_with_directories() + call mkdir('Xdir1') + call mkdir('Xdir2') + call mkdir('Xdir3') + cd Xdir3 + call mkdir('Xdir4') + cd .. + + split Xdir1/file + call setline(1, ['a', 'b']) + w + w Xdir3/Xdir4/file + close + + next Xdir?/*/file + call assert_equal('Xdir3/Xdir4/file', expand('%')) + if has('unix') + next! Xdir?/*/nofile + call assert_equal('Xdir?/*/nofile', expand('%')) + endif + " Edit another file, on MS-Windows the swap file would be in use and can't + " be deleted. + edit foo + + call assert_equal(0, delete('Xdir1', 'rf')) + call assert_equal(0, delete('Xdir2', 'rf')) + call assert_equal(0, delete('Xdir3', 'rf')) +endfunc + +func Test_with_tilde() + let dir = getcwd() + call mkdir('Xdir ~ dir') + call assert_true(isdirectory('Xdir ~ dir')) + cd Xdir\ ~\ dir + call assert_true(getcwd() =~ 'Xdir \~ dir') + exe 'cd ' . fnameescape(dir) + call delete('Xdir ~ dir', 'd') + call assert_false(isdirectory('Xdir ~ dir')) +endfunc diff --git a/src/testdir/test_viml.vim b/src/testdir/test_viml.vim index 5d65953a9e..07286fb024 100644 --- a/src/testdir/test_viml.vim +++ b/src/testdir/test_viml.vim @@ -1,5 +1,5 @@ " Test various aspects of the Vim language. -" This was formerly in test49. +" Most of this was formerly in test49. "------------------------------------------------------------------------------- " Test environment {{{1 @@ -906,6 +906,20 @@ func Test_if_bar_fail() call assert_equal('acdfh-acfh', g:test15_result) endfunc +"------------------------------------------------------------------------------- +" Test 90: Recognizing {} in variable name. {{{1 +"------------------------------------------------------------------------------- + +func Test_curlies() + let s:var = 66 + let ns = 's' + call assert_equal(66, {ns}:var) + + let g:a = {} + let g:b = 't' + let g:a[g:b] = 77 + call assert_equal(77, g:a['t']) +endfunc "------------------------------------------------------------------------------- " Modelines {{{1 diff --git a/src/version.c b/src/version.c index f872235956..1bc2e76fd7 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,38 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1122, +/**/ + 1121, +/**/ + 1120, +/**/ + 1119, +/**/ + 1118, +/**/ + 1117, +/**/ + 1116, +/**/ + 1115, +/**/ + 1114, +/**/ + 1113, +/**/ + 1112, +/**/ + 1111, +/**/ + 1110, +/**/ + 1109, +/**/ + 1108, +/**/ + 1107, /**/ 1106, /**/ diff --git a/src/vim.h b/src/vim.h index ad758d1c94..d6181bc63e 100644 --- a/src/vim.h +++ b/src/vim.h @@ -838,6 +838,8 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname); #define EW_ALLLINKS 0x1000 /* also links not pointing to existing file */ #define EW_SHELLCMD 0x2000 /* called from expand_shellcmd(), don't check * if executable is in $PATH */ +#define EW_DODOT 0x4000 /* also files starting with a dot */ +#define EW_EMPTYOK 0x8000 /* no matches is not an error */ /* Flags for find_file_*() functions. */ #define FINDFILE_FILE 0 /* only files */