diff options
-rw-r--r-- | cmake/RunTests.cmake | 2 | ||||
-rw-r--r-- | runtime/ftplugin/man.vim | 4 | ||||
-rw-r--r-- | src/nvim/buffer.c | 1 | ||||
-rw-r--r-- | src/nvim/digraph.c | 17 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 10 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 5 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 18 | ||||
-rw-r--r-- | src/nvim/indent_c.c | 3 | ||||
-rw-r--r-- | src/nvim/macros.h | 12 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 4 | ||||
-rw-r--r-- | src/nvim/syntax.c | 141 | ||||
-rw-r--r-- | src/nvim/testdir/Makefile | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_cindent.vim | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_syntax.vim | 184 | ||||
-rw-r--r-- | src/nvim/vim.h | 1 | ||||
-rw-r--r-- | test/functional/legacy/003_cindent_spec.lua | 1 | ||||
-rw-r--r-- | test/functional/plugin/health_spec.lua | 6 |
17 files changed, 355 insertions, 73 deletions
diff --git a/cmake/RunTests.cmake b/cmake/RunTests.cmake index 95c06aeb94..5b62fd72c9 100644 --- a/cmake/RunTests.cmake +++ b/cmake/RunTests.cmake @@ -38,7 +38,7 @@ set(ENV{SYSTEM_NAME} ${SYSTEM_NAME}) execute_process( COMMAND ${BUSTED_PRG} ${TEST_TAG} ${TEST_FILTER} -v -o ${BUSTED_OUTPUT_TYPE} --lua=${LUA_PRG} --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua - --lpath=${BUILD_DIR}/?.lua ${TEST_PATH} + --lpath=${BUILD_DIR}/?.lua --lpath=?.lua ${TEST_PATH} WORKING_DIRECTORY ${WORKING_DIR} ERROR_VARIABLE err RESULT_VARIABLE res diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim index e36dfc5a90..68ebb33e45 100644 --- a/runtime/ftplugin/man.vim +++ b/runtime/ftplugin/man.vim @@ -6,7 +6,7 @@ if exists('b:did_ftplugin') || &filetype !=# 'man' endif let b:did_ftplugin = 1 -let s:pager = !exists('b:man_sect') +let s:pager = get(s:, 'pager', 0) || !exists('b:man_sect') if s:pager call man#init_pager() @@ -35,7 +35,7 @@ if !exists('g:no_plugin_maps') && !exists('g:no_man_maps') nnoremap <silent> <buffer> <C-]> :Man<CR> nnoremap <silent> <buffer> K :Man<CR> nnoremap <silent> <buffer> <C-T> :call man#pop_tag()<CR> - if s:pager + if 1 == bufnr('%') || s:pager nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR> else nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 21830539f5..6f0c78fde4 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1775,6 +1775,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_flp); clear_string_option(&buf->b_p_isk); clear_string_option(&buf->b_p_keymap); + keymap_ga_clear(&buf->b_kmap_ga); ga_clear(&buf->b_kmap_ga); clear_string_option(&buf->b_p_com); clear_string_option(&buf->b_p_cms); diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index dbcc8db109..bc4c12e0b7 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1841,6 +1841,16 @@ void ex_loadkeymap(exarg_T *eap) status_redraw_curbuf(); } +/// Frees the buf_T.b_kmap_ga field of a buffer. +void keymap_ga_clear(garray_T *kmap_ga) +{ + kmap_T *kp = (kmap_T *)kmap_ga->ga_data; + for (int i = 0; i < kmap_ga->ga_len; i++) { + xfree(kp[i].from); + xfree(kp[i].to); + } +} + /// Stop using 'keymap'. static void keymap_unload(void) { @@ -1858,12 +1868,11 @@ static void keymap_unload(void) // clear the ":lmap"s kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; - for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { + for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); - (void)do_map(1, buf, LANGMAP, FALSE); - xfree(kp[i].from); - xfree(kp[i].to); + (void)do_map(1, buf, LANGMAP, false); } + keymap_ga_clear(&curbuf->b_kmap_ga); p_cpo = save_cpo; diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index f6c42a2d3c..9bae436e3d 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -28,6 +28,11 @@ #include "nvim/lib/kvec.h" #include "nvim/eval/typval_encode.h" +#ifdef __MINGW32__ +# undef fpclassify +# define fpclassify __fpclassify +#endif + #define ga_concat(a, b) ga_concat(a, (char_u *)b) #define utf_ptr2char(b) utf_ptr2char((char_u *)b) #define utf_ptr2len(b) ((size_t)utf_ptr2len((char_u *)b)) @@ -288,11 +293,6 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, : OK); } -#ifdef __MINGW32__ -# undef fpclassify -# define fpclassify __fpclassify -#endif - #define TYPVAL_ENCODE_CONV_STRING(tv, buf, len) \ do { \ const char *const buf_ = (const char *) buf; \ diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 2fa8db6b82..4f0208c5c3 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3442,6 +3442,10 @@ const char * set_one_cmd_context( case CMD_profile: set_context_in_profile_cmd(xp, arg); break; + case CMD_checkhealth: + xp->xp_context = EXPAND_CHECKHEALTH; + xp->xp_pattern = (char_u *)arg; + break; case CMD_behave: xp->xp_context = EXPAND_BEHAVE; xp->xp_pattern = (char_u *)arg; @@ -4871,6 +4875,7 @@ static struct { { EXPAND_AUGROUP, "augroup" }, { EXPAND_BEHAVE, "behave" }, { EXPAND_BUFFERS, "buffer" }, + { EXPAND_CHECKHEALTH, "checkhealth" }, { EXPAND_COLORS, "color" }, { EXPAND_COMMANDS, "command" }, { EXPAND_COMPILER, "compiler" }, diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ade8b46956..54bbe66620 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4257,20 +4257,20 @@ addstar ( * use with vim_regcomp(). First work out how long it will be: */ - /* For help tags the translation is done in find_help_tags(). - * For a tag pattern starting with "/" no translation is needed. */ + // For help tags the translation is done in find_help_tags(). + // For a tag pattern starting with "/" no translation is needed. if (context == EXPAND_HELP + || context == EXPAND_CHECKHEALTH || context == EXPAND_COLORS || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX || context == EXPAND_FILETYPE || context == EXPAND_PACKADD - || ((context == EXPAND_TAGS_LISTFILES - || context == EXPAND_TAGS) - && fname[0] == '/')) + || ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS) + && fname[0] == '/')) { retval = vim_strnsave(fname, len); - else { - new_len = len + 2; /* +2 for '^' at start, NUL at end */ + } else { + new_len = len + 2; // +2 for '^' at start, NUL at end for (i = 0; i < len; i++) { if (fname[i] == '*' || fname[i] == '~') new_len++; /* '*' needs to be replaced by ".*" @@ -4667,6 +4667,10 @@ ExpandFromContext ( char *directories[] = { "syntax", "indent", "ftplugin", NULL }; return ExpandRTDir(pat, 0, num_file, file, directories); } + if (xp->xp_context == EXPAND_CHECKHEALTH) { + char *directories[] = { "autoload/health", NULL }; + return ExpandRTDir(pat, 0, num_file, file, directories); + } if (xp->xp_context == EXPAND_USER_LIST) { return ExpandUserList(xp, num_file, file); } diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 279d45bb0a..53364c0fc5 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1619,6 +1619,9 @@ void parse_cino(buf_T *buf) * while(). */ buf->b_ind_if_for_while = 0; + // indentation for # comments + buf->b_ind_hash_comment = 0; + for (p = buf->b_p_cino; *p; ) { l = p++; if (*p == '-') diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 05065499f4..a98c1e05a0 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -148,8 +148,7 @@ /// zero in those cases (-Wdiv-by-zero in GCC). #define ARRAY_SIZE(arr) ((sizeof(arr)/sizeof((arr)[0])) / ((size_t)(!(sizeof(arr) % sizeof((arr)[0]))))) -// Windows defines a RGB macro that produces 0x00bbggrr color values for use -// with GDI. Our macro is different, and we don't use GDI. +// Duplicated in os/win_defs.h to avoid include-order sensitivity. #if defined(WIN32) && defined(RGB) # undef RGB #endif @@ -188,18 +187,19 @@ /// @return ((Type *)obj). #define STRUCT_CAST(Type, obj) ((Type *)(obj)) -// Type of uv_buf_t.len on Windows is ULONG, but others is size_t. +// Type of uv_buf_t.len is platform-dependent. +// Related: https://github.com/libuv/libuv/pull/1236 #if defined(WIN32) # define UV_BUF_LEN(x) (ULONG)(x) #else # define UV_BUF_LEN(x) (x) #endif -// Type of bufcnt for read/write on Windows is unsigned int, not size_t. +// Type of read()/write() `count` param is platform-dependent. #if defined(WIN32) -# define IO_SIZE(x) (unsigned)(x) +# define IO_COUNT(x) (unsigned)(x) #else -# define IO_SIZE(x) (x) +# define IO_COUNT(x) (x) #endif #endif // NVIM_MACROS_H diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index f3b3871aac..c0a97aeb34 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -461,7 +461,7 @@ ptrdiff_t os_read(const int fd, bool *ret_eof, char *const ret_buf, while (read_bytes != size) { assert(size >= read_bytes); const ptrdiff_t cur_read_bytes = read(fd, ret_buf + read_bytes, - IO_SIZE(size - read_bytes)); + IO_COUNT(size - read_bytes)); if (cur_read_bytes > 0) { read_bytes += (size_t)cur_read_bytes; } @@ -564,7 +564,7 @@ ptrdiff_t os_write(const int fd, const char *const buf, const size_t size) while (written_bytes != size) { assert(size >= written_bytes); const ptrdiff_t cur_written_bytes = write(fd, buf + written_bytes, - IO_SIZE(size - written_bytes)); + IO_COUNT(size - written_bytes)); if (cur_written_bytes > 0) { written_bytes += (size_t)cur_written_bytes; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d1a5f0bd1c..05bc6c9d96 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -52,6 +52,7 @@ static bool did_syntax_onoff = false; struct hl_group { char_u *sg_name; ///< highlight group name char_u *sg_name_u; ///< uppercase of sg_name + int sg_cleared; ///< "hi clear" was used int sg_attr; ///< Screen attr @see ATTR_ENTRY int sg_link; ///< link to this highlight group ID int sg_set; ///< combination of flags in \ref SG_SET @@ -3019,12 +3020,19 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) return; next = skiptowhite(arg); - if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) - curwin->w_s->b_syn_conceal = TRUE; - else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) - curwin->w_s->b_syn_conceal = FALSE; - else + if (*arg == NUL) { + if (curwin->w_s->b_syn_conceal) { + MSG(_("syn conceal on")); + } else { + MSG(_("syn conceal off")); + } + } else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) { + curwin->w_s->b_syn_conceal = true; + } else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) { + curwin->w_s->b_syn_conceal = false; + } else { EMSG2(_("E390: Illegal argument: %s"), arg); + } } /* @@ -3040,12 +3048,19 @@ static void syn_cmd_case(exarg_T *eap, int syncing) return; next = skiptowhite(arg); - if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) - curwin->w_s->b_syn_ic = FALSE; - else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) - curwin->w_s->b_syn_ic = TRUE; - else + if (*arg == NUL) { + if (curwin->w_s->b_syn_ic) { + MSG(_("syntax case ignore")); + } else { + MSG(_("syntax case match")); + } + } else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) { + curwin->w_s->b_syn_ic = false; + } else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) { + curwin->w_s->b_syn_ic = true; + } else { EMSG2(_("E390: Illegal argument: %s"), arg); + } } /* @@ -3061,7 +3076,15 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) return; next = skiptowhite(arg); - if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) { + if (*arg == NUL) { + if (curwin->w_s->b_syn_spell == SYNSPL_TOP) { + MSG(_("syntax spell toplevel")); + } else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) { + MSG(_("syntax spell notoplevel")); + } else { + MSG(_("syntax spell default")); + } + } else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) { curwin->w_s->b_syn_spell = SYNSPL_TOP; } else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10) { curwin->w_s->b_syn_spell = SYNSPL_NOTOP; @@ -3121,10 +3144,11 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) */ void syntax_clear(synblock_T *block) { - block->b_syn_error = FALSE; /* clear previous error */ - block->b_syn_ic = FALSE; /* Use case, by default */ - block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */ - block->b_syn_containedin = FALSE; + block->b_syn_error = false; // clear previous error + block->b_syn_ic = false; // Use case, by default + block->b_syn_spell = SYNSPL_DEFAULT; // default spell checking + block->b_syn_containedin = false; + block->b_syn_conceal = false; /* free the keywords */ clear_keywtab(&block->b_keywtab); @@ -4001,10 +4025,11 @@ get_group_name ( * Return NULL for any error; */ static char_u * -get_syn_options ( - char_u *arg, /* next argument to be checked */ - syn_opt_arg_T *opt, /* various things */ - int *conceal_char +get_syn_options( + char_u *arg, // next argument to be checked + syn_opt_arg_T *opt, // various things + int *conceal_char, + int skip // TRUE if skipping over command ) { char_u *gname_start, *gname; @@ -4080,14 +4105,17 @@ get_syn_options ( EMSG(_("E395: contains argument not accepted here")); return NULL; } - if (get_id_list(&arg, 8, &opt->cont_list) == FAIL) + if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) { return NULL; + } } else if (flagtab[fidx].argtype == 2) { - if (get_id_list(&arg, 11, &opt->cont_in_list) == FAIL) + if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) { return NULL; + } } else if (flagtab[fidx].argtype == 3) { - if (get_id_list(&arg, 9, &opt->next_list) == FAIL) + if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) { return NULL; + } } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { /* cchar=? */ if (has_mbyte) { @@ -4257,7 +4285,11 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) rest = get_group_name(arg, &group_name_end); if (rest != NULL) { - syn_id = syn_check_group(arg, (int)(group_name_end - arg)); + if (eap->skip) { + syn_id = -1; + } else { + syn_id = syn_check_group(arg, (int)(group_name_end - arg)); + } if (syn_id != 0) { // Allocate a buffer, for removing backslashes in the keyword. keyword_copy = xmalloc(STRLEN(rest) + 1); @@ -4276,7 +4308,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) cnt = 0; p = keyword_copy; for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) { - rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest == NULL || ends_excmd(*rest)) { break; } @@ -4375,17 +4407,18 @@ syn_cmd_match ( syn_opt_arg.cont_list = NULL; syn_opt_arg.cont_in_list = NULL; syn_opt_arg.next_list = NULL; - rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); /* get the pattern. */ init_syn_patterns(); memset(&item, 0, sizeof(item)); rest = get_syn_pattern(rest, &item); - if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) + if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) { syn_opt_arg.flags |= HL_HAS_EOL; + } - /* Get options after the pattern */ - rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); + // Get options after the pattern + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); if (rest != NULL) { /* all arguments are valid */ /* @@ -4497,14 +4530,13 @@ syn_cmd_region ( syn_opt_arg.cont_in_list = NULL; syn_opt_arg.next_list = NULL; - /* - * get the options, patterns and matchgroup. - */ + // get the options, patterns and matchgroup. while (rest != NULL && !ends_excmd(*rest)) { - /* Check for option arguments */ - rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); - if (rest == NULL || ends_excmd(*rest)) + // Check for option arguments + rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); + if (rest == NULL || ends_excmd(*rest)) { break; + } /* must be a pattern or matchgroup then */ key_end = rest; @@ -4926,13 +4958,15 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing) break; clstr_list = NULL; - if (get_id_list(&rest, opt_len, &clstr_list) == FAIL) { + if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) { EMSG2(_(e_invarg2), rest); break; } - syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, - &clstr_list, list_op); - got_clstr = TRUE; + if (scl_id >= 0) { + syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, + &clstr_list, list_op); + } + got_clstr = true; } if (got_clstr) { @@ -5180,9 +5214,10 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) static int get_id_list ( char_u **arg, - int keylen, /* length of keyword */ - short **list /* where to store the resulting list, if not - NULL, the list is silently skipped! */ + int keylen, // length of keyword + int16_t **list, // where to store the resulting list, if not + // NULL, the list is silently skipped! + int skip ) { char_u *p = NULL; @@ -5251,7 +5286,11 @@ get_id_list ( id = SYNID_CONTAINED; id += current_syn_inc_tag; } else if (name[1] == '@') { - id = syn_check_cluster(name + 2, (int)(end - p - 1)); + if (skip) { + id = -1; + } else { + id = syn_check_cluster(name + 2, (int)(end - p - 1)); + } } else { /* * Handle full group name. @@ -6457,6 +6496,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) HL_TABLE()[from_id - 1].sg_set |= SG_LINK; HL_TABLE()[from_id - 1].sg_link = to_id; HL_TABLE()[from_id - 1].sg_scriptID = current_SID; + HL_TABLE()[from_id - 1].sg_cleared = false; redraw_all_later(SOME_VALID); } } @@ -6839,6 +6879,7 @@ void do_highlight(const char *line, const bool forceit, const bool init) error = true; break; } + HL_TABLE()[idx].sg_cleared = false; // When highlighting has been given for a group, don't link it. if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) { @@ -6920,6 +6961,8 @@ static int hl_has_settings(int idx, int check_link) */ static void highlight_clear(int idx) { + HL_TABLE()[idx].sg_cleared = true; + HL_TABLE()[idx].sg_attr = 0; HL_TABLE()[idx].sg_cterm = 0; HL_TABLE()[idx].sg_cterm_bold = FALSE; @@ -7730,10 +7773,20 @@ const char *get_highlight_name(expand_T *const xp, const int idx) } else if (idx == highlight_ga.ga_len + include_none + include_default + 1 && include_link != 0) { return "clear"; - } else if (idx < 0 || idx >= highlight_ga.ga_len) { + } else if (idx < 0) { + return NULL; + } + + // Items are never removed from the table, skip the ones that were cleared. + int current_idx = idx; + while (current_idx < highlight_ga.ga_len + && HL_TABLE()[current_idx].sg_cleared) { + current_idx++; + } + if (current_idx >= highlight_ga.ga_len) { return NULL; } - return (const char *)HL_TABLE()[idx].sg_name; + return (const char *)HL_TABLE()[current_idx].sg_name; } color_name_table_T color_name_table[] = { diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index c1e6eedf94..18f0bac3cf 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -40,11 +40,12 @@ SCRIPTS ?= $(SCRIPTS_DEFAULT) # Tests using runtest.vim. # Keep test_alot*.res as the last one, sort the others. NEW_TESTS ?= \ - test_arabic.vim \ + test_arabic.res \ test_autocmd.res \ test_bufwintabinfo.res \ test_changedtick.res \ test_charsearch.res \ + test_cindent.res \ test_cmdline.res \ test_command_count.res \ test_cscope.res \ diff --git a/src/nvim/testdir/test_cindent.vim b/src/nvim/testdir/test_cindent.vim new file mode 100644 index 0000000000..5685c2be66 --- /dev/null +++ b/src/nvim/testdir/test_cindent.vim @@ -0,0 +1,16 @@ +" Test for cinoptions and cindent +" +" TODO: rewrite test3.in into this new style test + +func Test_cino_hash() + " Test that curbuf->b_ind_hash_comment is correctly reset + new + setlocal cindent cinoptions=#1 + setlocal cinoptions= + call setline(1, ["#include <iostream>"]) + call cursor(1, 1) + norm! o#include + "call feedkeys("o#include\<esc>", 't') + call assert_equal(["#include <iostream>", "#include"], getline(1,2)) + bwipe! +endfunc diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 6c084dd2a7..6456ca2b23 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -152,9 +152,191 @@ func Test_syntax_completion() call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:) + " Check that clearing "Aap" avoids it showing up before Boolean. + hi Aap ctermfg=blue + call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"syn list Aap Boolean Character ', @:) + hi clear Aap + call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') call assert_match('^"syn list Boolean Character ', @:) call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') call assert_match('^"syn match Boolean Character ', @:) -endfunc
\ No newline at end of file +endfunc + +func Test_syntax_arg_skipped() + syn clear + syntax case ignore + if 0 + syntax case match + endif + call assert_match('case ignore', execute('syntax case')) + + syn keyword Foo foo + call assert_match('Foo', execute('syntax')) + syn clear + call assert_match('case match', execute('syntax case')) + call assert_notmatch('Foo', execute('syntax')) + + if has('conceal') + syn clear + syntax conceal on + if 0 + syntax conceal off + endif + call assert_match('conceal on', execute('syntax conceal')) + syn clear + call assert_match('conceal off', execute('syntax conceal')) + endif + + syntax conceal on + syntax conceal off + call assert_match('conceal off', execute('syntax conceal')) + + syntax region Bar start=/</ end=/>/ + if 0 + syntax region NotTest start=/</ end=/>/ contains=@Spell + endif + call assert_match('Bar', execute('syntax')) + call assert_notmatch('NotTest', execute('syntax')) + call assert_notmatch('Spell', execute('syntax')) + + hi Foo ctermfg=blue + let a = execute('hi Foo') + if 0 + syntax rest + endif + call assert_equal(a, execute('hi Foo')) + hi clear Bar + hi clear Foo + + set ft=tags + syn off + if 0 + syntax enable + endif + call assert_match('No Syntax items defined', execute('syntax')) + syntax enable + call assert_match('tagComment', execute('syntax')) + set ft= + + syn clear + if 0 + syntax include @Spell nothing + endif + call assert_notmatch('Spell', execute('syntax')) + + syn clear + syn iskeyword 48-57,$,_ + call assert_match('48-57,$,_', execute('syntax iskeyword')) + if 0 + syn clear + syn iskeyword clear + endif + call assert_match('48-57,$,_', execute('syntax iskeyword')) + syn iskeyword clear + call assert_match('not set', execute('syntax iskeyword')) + syn iskeyword 48-57,$,_ + syn clear + call assert_match('not set', execute('syntax iskeyword')) + + syn clear + syn keyword Foo foo + if 0 + syn keyword NotAdded bar + endif + call assert_match('Foo', execute('syntax')) + call assert_notmatch('NotAdded', execute('highlight')) + + syn clear + syn keyword Foo foo + call assert_match('Foo', execute('syntax')) + call assert_match('Foo', execute('syntax list')) + call assert_notmatch('Foo', execute('if 0 | syntax | endif')) + call assert_notmatch('Foo', execute('if 0 | syntax list | endif')) + + syn clear + syn match Fopi /asdf/ + if 0 + syn match Fopx /asdf/ + endif + call assert_match('Fopi', execute('syntax')) + call assert_notmatch('Fopx', execute('syntax')) + + syn clear + syn spell toplevel + call assert_match('spell toplevel', execute('syntax spell')) + if 0 + syn spell notoplevel + endif + call assert_match('spell toplevel', execute('syntax spell')) + syn spell notoplevel + call assert_match('spell notoplevel', execute('syntax spell')) + syn spell default + call assert_match('spell default', execute('syntax spell')) + + syn clear + if 0 + syntax cluster Spell + endif + call assert_notmatch('Spell', execute('syntax')) + + syn clear + syn keyword Foo foo + syn sync ccomment + syn sync maxlines=5 + if 0 + syn sync maxlines=11 + endif + call assert_match('on C-style comments', execute('syntax sync')) + call assert_match('maximal 5 lines', execute('syntax sync')) + syn sync clear + if 0 + syn sync ccomment + endif + call assert_notmatch('on C-style comments', execute('syntax sync')) + + syn clear +endfunc + +func Test_invalid_arg() + call assert_fails('syntax case asdf', 'E390:') + call assert_fails('syntax conceal asdf', 'E390:') + call assert_fails('syntax spell asdf', 'E390:') +endfunc + +func Test_syn_sync() + syntax region HereGroup start=/this/ end=/that/ + syntax sync match SyncHere grouphere HereGroup "pattern" + call assert_match('SyncHere', execute('syntax sync')) + syn sync clear + call assert_notmatch('SyncHere', execute('syntax sync')) + syn clear +endfunc + +func Test_syn_clear() + syntax keyword Foo foo + syntax keyword Bar tar + call assert_match('Foo', execute('syntax')) + call assert_match('Bar', execute('syntax')) + syn clear Foo + call assert_notmatch('Foo', execute('syntax')) + call assert_match('Bar', execute('syntax')) + syn clear Foo Bar + call assert_notmatch('Foo', execute('syntax')) + call assert_notmatch('Bar', execute('syntax')) + hi clear Foo + hi clear Bar +endfunc + +func Test_invalid_name() + syn clear + syn keyword Nop yes + call assert_fails("syntax keyword Wr\x17ong bar", 'E669:') + syntax keyword @Wrong bar + call assert_match('W18:', execute('1messages')) + syn clear + hi clear Nop + hi clear @Wrong +endfunc diff --git a/src/nvim/vim.h b/src/nvim/vim.h index b535e380d1..b932c2d0f8 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -155,6 +155,7 @@ enum { EXPAND_USER_ADDR_TYPE, EXPAND_PACKADD, EXPAND_MESSAGES, + EXPAND_CHECKHEALTH, }; diff --git a/test/functional/legacy/003_cindent_spec.lua b/test/functional/legacy/003_cindent_spec.lua index 58e87354fb..13726050b2 100644 --- a/test/functional/legacy/003_cindent_spec.lua +++ b/test/functional/legacy/003_cindent_spec.lua @@ -1,4 +1,5 @@ -- Test for 'cindent'. +-- For new tests, consider putting them in test_cindent.vim. -- -- There are 50+ test command blocks (the stuff between STARTTEST and ENDTEST) -- in the original test. These have been converted to "it" test cases here. diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 8ee0f258d0..f2d5e433db 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,6 +6,7 @@ local clear = helpers.clear local curbuf_contents = helpers.curbuf_contents local command = helpers.command local eq = helpers.eq +local getcompletion = helpers.funcs.getcompletion describe(':checkhealth', function() it("detects invalid $VIMRUNTIME", function() @@ -31,6 +32,11 @@ describe(':checkhealth', function() eq("ERROR: $VIM is invalid: zub", string.match(curbuf_contents(), "ERROR: $VIM .* zub")) end) + it('completions can be listed via getcompletion()', function() + clear() + eq('nvim', getcompletion('nvim', 'checkhealth')[1]) + eq('provider', getcompletion('prov', 'checkhealth')[1]) + end) end) describe('health.vim', function() |