aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c14
-rw-r--r--src/nvim/api/private/helpers.c1
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/change.c4
-rw-r--r--src/nvim/decoration.c57
-rw-r--r--src/nvim/decoration.h17
-rw-r--r--src/nvim/edit.c2
-rw-r--r--src/nvim/eval.c459
-rw-r--r--src/nvim/eval.h16
-rw-r--r--src/nvim/eval/funcs.c25
-rw-r--r--src/nvim/eval/userfunc.c11
-rw-r--r--src/nvim/event/libuv_process.c2
-rw-r--r--src/nvim/ex_cmds.lua6
-rw-r--r--src/nvim/ex_cmds2.c122
-rw-r--r--src/nvim/ex_docmd.c1
-rw-r--r--src/nvim/ex_eval.c9
-rw-r--r--src/nvim/ex_getln.c15
-rw-r--r--src/nvim/fileio.c8
-rw-r--r--src/nvim/lua/executor.c8
-rw-r--r--src/nvim/msgpack_rpc/channel.c2
-rw-r--r--src/nvim/normal.c4
-rw-r--r--src/nvim/os/pty_process_unix.c4
-rw-r--r--src/nvim/os/pty_process_win.c6
-rw-r--r--src/nvim/os/time.c1
-rw-r--r--src/nvim/regexp.c7
-rw-r--r--src/nvim/screen.c17
-rw-r--r--src/nvim/search.c9
-rw-r--r--src/nvim/syntax.c18
-rw-r--r--src/nvim/tag.c4
-rw-r--r--src/nvim/testdir/runtest.vim5
-rw-r--r--src/nvim/testdir/test_alot.vim1
-rw-r--r--src/nvim/testdir/test_alot_utf8.vim1
-rw-r--r--src/nvim/testdir/test_autocmd.vim14
-rw-r--r--src/nvim/testdir/test_backspace_opt.vim20
-rw-r--r--src/nvim/testdir/test_debugger.vim819
-rw-r--r--src/nvim/testdir/test_expr.vim9
-rw-r--r--src/nvim/testdir/test_filetype.vim2
-rw-r--r--src/nvim/testdir/test_functions.vim16
-rw-r--r--src/nvim/testdir/test_listdict.vim63
-rw-r--r--src/nvim/testdir/test_menu.vim6
-rw-r--r--src/nvim/testdir/test_search.vim533
-rw-r--r--src/nvim/testdir/test_shift.vim117
-rw-r--r--src/nvim/testdir/test_statusline.vim9
-rw-r--r--src/nvim/testdir/test_syntax.vim45
-rw-r--r--src/nvim/testdir/test_utf8.vim2
-rw-r--r--src/nvim/testdir/test_writefile.vim120
46 files changed, 2049 insertions, 584 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index c55dc39605..e79a7a2de2 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1437,6 +1437,10 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,
/// default
/// - "combine": combine with background text color
/// - "blend": blend with background text color.
+/// - hl_eol : when true, for a multiline highlight covering the
+/// EOL of a line, continue the highlight for the rest
+/// of the screen line (just like for diff and
+/// cursorline highlight).
///
/// - ephemeral : for use with |nvim_set_decoration_provider|
/// callbacks. The mark will only be used for the current
@@ -1581,6 +1585,11 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
if (ERROR_SET(err)) {
goto error;
}
+ } else if (strequal("hl_eol", k.data)) {
+ decor.hl_eol = api_object_to_bool(*v, "hl_eol", false, err);
+ if (ERROR_SET(err)) {
+ goto error;
+ }
} else if (strequal("hl_mode", k.data)) {
if (v->type != kObjectTypeString) {
api_set_error(err, kErrorTypeValidation,
@@ -1669,7 +1678,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
if (ephemeral) {
d = &decor;
} else if (kv_size(decor.virt_text)
- || decor.priority != DECOR_PRIORITY_BASE) {
+ || decor.priority != DECOR_PRIORITY_BASE
+ || decor.hl_eol) {
// TODO(bfredl): this is a bit sketchy. eventually we should
// have predefined decorations for both marks/ephemerals
d = xcalloc(1, sizeof(*d));
@@ -1680,7 +1690,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
// TODO(bfredl): synergize these two branches even more
if (ephemeral && decor_state.buf == buf) {
- decor_add_ephemeral((int)line, (int)col, line2, col2, &decor, 0);
+ decor_add_ephemeral((int)line, (int)col, line2, col2, &decor);
} else {
if (ephemeral) {
api_set_error(err, kErrorTypeException, "not yet implemented");
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index c73a9195c3..24ba6110c4 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -1765,6 +1765,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err)
{ "double", { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }, false },
{ "single", { "┌", "─", "┐", "│", "┘", "─", "└", "│" }, false },
{ "shadow", { "", "", " ", " ", " ", " ", " ", "" }, true },
+ { "solid", { " ", " ", " ", " ", " ", " ", " ", " " }, false },
{ NULL, { { NUL } } , false },
};
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index c98f2786c2..ce4163fccf 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1844,7 +1844,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
EMSG(_("W14: Warning: List of file names overflow"));
if (emsg_silent == 0) {
ui_flush();
- os_delay(3000L, true); // make sure it is noticed
+ os_delay(3001L, true); // make sure it is noticed
}
top_file_num = 1;
}
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 38bd591eca..74e27ca880 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -68,7 +68,7 @@ void change_warning(int col)
(void)msg_end();
if (msg_silent == 0 && !silent_mode && ui_active()) {
ui_flush();
- os_delay(1000L, true); // give the user time to think about it
+ os_delay(1002L, true); // give the user time to think about it
}
curbuf->b_did_warn = true;
redraw_cmdline = false; // don't redraw and erase the message
@@ -109,7 +109,7 @@ void changed(void)
// and don't let the emsg() set msg_scroll.
if (need_wait_return && emsg_silent == 0) {
ui_flush();
- os_delay(2000L, true);
+ os_delay(2002L, true);
wait_return(true);
msg_scroll = save_msg_scroll;
} else {
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index 52a48ae6fb..e39d2328f5 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -144,9 +144,9 @@ bool decor_redraw_reset(buf_T *buf, DecorState *state)
state->row = -1;
state->buf = buf;
for (size_t i = 0; i < kv_size(state->active); i++) {
- HlRange item = kv_A(state->active, i);
+ DecorRange item = kv_A(state->active, i);
if (item.virt_text_owned) {
- clear_virttext(&item.virt_text);
+ clear_virttext(&item.decor.virt_text);
}
}
kv_size(state->active) = 0;
@@ -190,14 +190,14 @@ bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state)
if (mark.id&MARKTREE_END_FLAG) {
decor_add(state, altpos.row, altpos.col, mark.row, mark.col,
- decor, false, 0);
+ decor, false);
} else {
if (altpos.row == -1) {
altpos.row = mark.row;
altpos.col = mark.col;
}
decor_add(state, mark.row, mark.col, altpos.row, altpos.col,
- decor, false, 0);
+ decor, false);
}
next_mark:
@@ -222,22 +222,19 @@ bool decor_redraw_line(buf_T *buf, int row, DecorState *state)
}
static void decor_add(DecorState *state, int start_row, int start_col,
- int end_row, int end_col, Decoration *decor, bool owned,
- DecorPriority priority)
+ int end_row, int end_col, Decoration *decor, bool owned)
{
int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0;
- HlRange range = { start_row, start_col, end_row, end_col,
- attr_id, MAX(priority, decor->priority),
- decor->virt_text,
- decor->virt_text_pos, decor->virt_text_hide, decor->hl_mode,
+ DecorRange range = { start_row, start_col, end_row, end_col,
+ *decor, attr_id,
kv_size(decor->virt_text) && owned, -1 };
kv_pushp(state->active);
size_t index;
for (index = kv_size(state->active)-1; index > 0; index--) {
- HlRange item = kv_A(state->active, index-1);
- if (item.priority <= range.priority) {
+ DecorRange item = kv_A(state->active, index-1);
+ if (item.decor.priority <= range.decor.priority) {
break;
}
kv_A(state->active, index) = kv_A(state->active, index-1);
@@ -291,7 +288,7 @@ int decor_redraw_col(buf_T *buf, int col, int virt_col, bool hidden,
}
decor_add(state, mark.row, mark.col, endpos.row, endpos.col,
- decor, false, 0);
+ decor, false);
next_mark:
marktree_itr_next(buf->b_marktree, state->itr);
@@ -300,11 +297,11 @@ next_mark:
int attr = 0;
size_t j = 0;
for (size_t i = 0; i < kv_size(state->active); i++) {
- HlRange item = kv_A(state->active, i);
+ DecorRange item = kv_A(state->active, i);
bool active = false, keep = true;
if (item.end_row < state->row
|| (item.end_row == state->row && item.end_col <= col)) {
- if (!(item.start_row >= state->row && kv_size(item.virt_text))) {
+ if (!(item.start_row >= state->row && kv_size(item.decor.virt_text))) {
keep = false;
}
} else {
@@ -324,13 +321,13 @@ next_mark:
attr = hl_combine_attr(attr, item.attr_id);
}
if ((item.start_row == state->row && item.start_col <= col)
- && kv_size(item.virt_text) && item.virt_col == -1) {
- item.virt_col = (item.virt_text_hide && hidden) ? -2 : virt_col;
+ && kv_size(item.decor.virt_text) && item.virt_col == -1) {
+ item.virt_col = (item.decor.virt_text_hide && hidden) ? -2 : virt_col;
}
if (keep) {
kv_A(state->active, j++) = item;
} else if (item.virt_text_owned) {
- clear_virttext(&item.virt_text);
+ clear_virttext(&item.decor.virt_text);
}
}
kv_size(state->active) = j;
@@ -343,28 +340,34 @@ void decor_redraw_end(DecorState *state)
state->buf = NULL;
}
-VirtText decor_redraw_virt_text(buf_T *buf, DecorState *state)
+VirtText decor_redraw_eol(buf_T *buf, DecorState *state, int *eol_attr)
{
decor_redraw_col(buf, MAXCOL, MAXCOL, false, state);
+ VirtText text = VIRTTEXT_EMPTY;
for (size_t i = 0; i < kv_size(state->active); i++) {
- HlRange item = kv_A(state->active, i);
- if (item.start_row == state->row && kv_size(item.virt_text)
- && item.virt_text_pos == kVTEndOfLine) {
- return item.virt_text;
+ DecorRange item = kv_A(state->active, i);
+ if (!kv_size(text)
+ && item.start_row == state->row && kv_size(item.decor.virt_text)
+ && item.decor.virt_text_pos == kVTEndOfLine) {
+ text = item.decor.virt_text;
+ }
+
+ if (item.decor.hl_eol && item.start_row <= state->row) {
+ *eol_attr = hl_combine_attr(*eol_attr, item.attr_id);
}
}
- return VIRTTEXT_EMPTY;
+
+ return text;
}
void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col,
- Decoration *decor, DecorPriority priority)
+ Decoration *decor)
{
if (end_row == -1) {
end_row = start_row;
end_col = start_col;
}
- decor_add(&decor_state, start_row, start_col, end_row, end_col, decor, true,
- priority);
+ decor_add(&decor_state, start_row, start_col, end_row, end_col, decor, true);
}
diff --git a/src/nvim/decoration.h b/src/nvim/decoration.h
index c5424a1642..08d69060f0 100644
--- a/src/nvim/decoration.h
+++ b/src/nvim/decoration.h
@@ -37,33 +37,28 @@ struct Decoration
VirtTextPos virt_text_pos;
bool virt_text_hide;
HlMode hl_mode;
+ bool hl_eol;
// TODO(bfredl): style, signs, etc
DecorPriority priority;
bool shared; // shared decoration, don't free
};
#define DECORATION_INIT { 0, KV_INITIAL_VALUE, kVTEndOfLine, false, \
- kHlModeUnknown, DECOR_PRIORITY_BASE, false }
+ kHlModeUnknown, false, DECOR_PRIORITY_BASE, false }
typedef struct {
int start_row;
int start_col;
int end_row;
int end_col;
- int attr_id;
- // TODO(bfredl): embed decoration instead, perhaps using an arena
- // for ephemerals?
- DecorPriority priority;
- VirtText virt_text;
- VirtTextPos virt_text_pos;
- bool virt_text_hide;
- HlMode hl_mode;
+ Decoration decor;
+ int attr_id; // cached lookup of decor.hl_id
bool virt_text_owned;
int virt_col;
-} HlRange;
+} DecorRange;
typedef struct {
MarkTreeIter itr[1];
- kvec_t(HlRange) active;
+ kvec_t(DecorRange) active;
buf_T *buf;
int top_row;
int row;
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index ea13052f25..f2fddc89fe 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -2058,7 +2058,7 @@ static bool check_compl_option(bool dict_opt)
vim_beep(BO_COMPL);
setcursor();
ui_flush();
- os_delay(2000L, false);
+ os_delay(2004L, false);
}
return false;
}
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 550fe8ab65..05d429c7d5 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -229,6 +229,7 @@ static struct vimvar {
// Neovim
VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO),
VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO),
+ VV(VV__NULL_STRING, "_null_string", VAR_STRING, VV_RO),
VV(VV__NULL_LIST, "_null_list", VAR_LIST, VV_RO),
VV(VV__NULL_DICT, "_null_dict", VAR_DICT, VV_RO),
VV(VV_LUA, "lua", VAR_PARTIAL, VV_RO),
@@ -916,6 +917,17 @@ varnumber_T eval_to_number(char_u *expr)
return retval;
}
+// Top level evaluation function.
+// Returns an allocated typval_T with the result.
+// Returns NULL when there is an error.
+typval_T *eval_expr(char_u *arg)
+{
+ typval_T *tv = xmalloc(sizeof(*tv));
+ if (eval0(arg, tv, NULL, true) == FAIL) {
+ XFREE_CLEAR(tv);
+ }
+ return tv;
+}
/*
* Prepare v: variable "idx" to be used.
@@ -3129,21 +3141,6 @@ static int pattern_match(char_u *pat, char_u *text, bool ic)
return matches;
}
-/*
- * types for expressions.
- */
-typedef enum {
- TYPE_UNKNOWN = 0,
- TYPE_EQUAL, // ==
- TYPE_NEQUAL, // !=
- TYPE_GREATER, // >
- TYPE_GEQUAL, // >=
- TYPE_SMALLER, // <
- TYPE_SEQUAL, // <=
- TYPE_MATCH, // =~
- TYPE_NOMATCH, // !~
-} exptype_T;
-
// TODO(ZyX-I): move to eval/expressions
/*
@@ -3420,11 +3417,8 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
{
typval_T var2;
char_u *p;
- int i;
- exptype_T type = TYPE_UNKNOWN;
- bool type_is = false; // true for "is" and "isnot"
+ exprtype_T type = EXPR_UNKNOWN;
int len = 2;
- varnumber_T n1, n2;
bool ic;
/*
@@ -3435,35 +3429,42 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
p = *arg;
switch (p[0]) {
- case '=': if (p[1] == '=')
- type = TYPE_EQUAL;
- else if (p[1] == '~')
- type = TYPE_MATCH;
+ case '=':
+ if (p[1] == '=') {
+ type = EXPR_EQUAL;
+ } else if (p[1] == '~') {
+ type = EXPR_MATCH;
+ }
break;
- case '!': if (p[1] == '=')
- type = TYPE_NEQUAL;
- else if (p[1] == '~')
- type = TYPE_NOMATCH;
+ case '!':
+ if (p[1] == '=') {
+ type = EXPR_NEQUAL;
+ } else if (p[1] == '~') {
+ type = EXPR_NOMATCH;
+ }
break;
- case '>': if (p[1] != '=') {
- type = TYPE_GREATER;
+ case '>':
+ if (p[1] != '=') {
+ type = EXPR_GREATER;
len = 1;
- } else
- type = TYPE_GEQUAL;
+ } else {
+ type = EXPR_GEQUAL;
+ }
break;
- case '<': if (p[1] != '=') {
- type = TYPE_SMALLER;
+ case '<':
+ if (p[1] != '=') {
+ type = EXPR_SMALLER;
len = 1;
- } else
- type = TYPE_SEQUAL;
+ } else {
+ type = EXPR_SEQUAL;
+ }
break;
case 'i': if (p[1] == 's') {
if (p[2] == 'n' && p[3] == 'o' && p[4] == 't') {
len = 5;
}
if (!isalnum(p[len]) && p[len] != '_') {
- type = len == 2 ? TYPE_EQUAL : TYPE_NEQUAL;
- type_is = true;
+ type = len == 2 ? EXPR_IS : EXPR_ISNOT;
}
}
break;
@@ -3472,7 +3473,7 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
/*
* If there is a comparative operator, use it.
*/
- if (type != TYPE_UNKNOWN) {
+ if (type != EXPR_UNKNOWN) {
// extra question mark appended: ignore case
if (p[len] == '?') {
ic = true;
@@ -3490,173 +3491,11 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
tv_clear(rettv);
return FAIL;
}
-
if (evaluate) {
- if (type_is && rettv->v_type != var2.v_type) {
- /* For "is" a different type always means FALSE, for "notis"
- * it means TRUE. */
- n1 = (type == TYPE_NEQUAL);
- } else if (rettv->v_type == VAR_LIST || var2.v_type == VAR_LIST) {
- if (type_is) {
- n1 = (rettv->v_type == var2.v_type
- && rettv->vval.v_list == var2.vval.v_list);
- if (type == TYPE_NEQUAL)
- n1 = !n1;
- } else if (rettv->v_type != var2.v_type
- || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) {
- if (rettv->v_type != var2.v_type) {
- EMSG(_("E691: Can only compare List with List"));
- } else {
- EMSG(_("E692: Invalid operation for List"));
- }
- tv_clear(rettv);
- tv_clear(&var2);
- return FAIL;
- } else {
- // Compare two Lists for being equal or unequal.
- n1 = tv_list_equal(rettv->vval.v_list, var2.vval.v_list, ic, false);
- if (type == TYPE_NEQUAL) {
- n1 = !n1;
- }
- }
- } else if (rettv->v_type == VAR_DICT || var2.v_type == VAR_DICT) {
- if (type_is) {
- n1 = (rettv->v_type == var2.v_type
- && rettv->vval.v_dict == var2.vval.v_dict);
- if (type == TYPE_NEQUAL)
- n1 = !n1;
- } else if (rettv->v_type != var2.v_type
- || (type != TYPE_EQUAL && type != TYPE_NEQUAL)) {
- if (rettv->v_type != var2.v_type)
- EMSG(_("E735: Can only compare Dictionary with Dictionary"));
- else
- EMSG(_("E736: Invalid operation for Dictionary"));
- tv_clear(rettv);
- tv_clear(&var2);
- return FAIL;
- } else {
- // Compare two Dictionaries for being equal or unequal.
- n1 = tv_dict_equal(rettv->vval.v_dict, var2.vval.v_dict,
- ic, false);
- if (type == TYPE_NEQUAL) {
- n1 = !n1;
- }
- }
- } else if (tv_is_func(*rettv) || tv_is_func(var2)) {
- if (type != TYPE_EQUAL && type != TYPE_NEQUAL) {
- EMSG(_("E694: Invalid operation for Funcrefs"));
- tv_clear(rettv);
- tv_clear(&var2);
- return FAIL;
- }
- if ((rettv->v_type == VAR_PARTIAL
- && rettv->vval.v_partial == NULL)
- || (var2.v_type == VAR_PARTIAL
- && var2.vval.v_partial == NULL)) {
- // when a partial is NULL assume not equal
- n1 = false;
- } else if (type_is) {
- if (rettv->v_type == VAR_FUNC && var2.v_type == VAR_FUNC) {
- // strings are considered the same if their value is
- // the same
- n1 = tv_equal(rettv, &var2, ic, false);
- } else if (rettv->v_type == VAR_PARTIAL
- && var2.v_type == VAR_PARTIAL) {
- n1 = (rettv->vval.v_partial == var2.vval.v_partial);
- } else {
- n1 = false;
- }
- } else {
- n1 = tv_equal(rettv, &var2, ic, false);
- }
- if (type == TYPE_NEQUAL) {
- n1 = !n1;
- }
- }
- /*
- * If one of the two variables is a float, compare as a float.
- * When using "=~" or "!~", always compare as string.
- */
- else if ((rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT)
- && type != TYPE_MATCH && type != TYPE_NOMATCH) {
- float_T f1, f2;
+ const int ret = typval_compare(rettv, &var2, type, ic);
- if (rettv->v_type == VAR_FLOAT) {
- f1 = rettv->vval.v_float;
- } else {
- f1 = tv_get_number(rettv);
- }
- if (var2.v_type == VAR_FLOAT) {
- f2 = var2.vval.v_float;
- } else {
- f2 = tv_get_number(&var2);
- }
- n1 = false;
- switch (type) {
- case TYPE_EQUAL: n1 = (f1 == f2); break;
- case TYPE_NEQUAL: n1 = (f1 != f2); break;
- case TYPE_GREATER: n1 = (f1 > f2); break;
- case TYPE_GEQUAL: n1 = (f1 >= f2); break;
- case TYPE_SMALLER: n1 = (f1 < f2); break;
- case TYPE_SEQUAL: n1 = (f1 <= f2); break;
- case TYPE_UNKNOWN:
- case TYPE_MATCH:
- case TYPE_NOMATCH: break;
- }
- }
- /*
- * If one of the two variables is a number, compare as a number.
- * When using "=~" or "!~", always compare as string.
- */
- else if ((rettv->v_type == VAR_NUMBER || var2.v_type == VAR_NUMBER)
- && type != TYPE_MATCH && type != TYPE_NOMATCH) {
- n1 = tv_get_number(rettv);
- n2 = tv_get_number(&var2);
- switch (type) {
- case TYPE_EQUAL: n1 = (n1 == n2); break;
- case TYPE_NEQUAL: n1 = (n1 != n2); break;
- case TYPE_GREATER: n1 = (n1 > n2); break;
- case TYPE_GEQUAL: n1 = (n1 >= n2); break;
- case TYPE_SMALLER: n1 = (n1 < n2); break;
- case TYPE_SEQUAL: n1 = (n1 <= n2); break;
- case TYPE_UNKNOWN:
- case TYPE_MATCH:
- case TYPE_NOMATCH: break;
- }
- } else {
- char buf1[NUMBUFLEN];
- char buf2[NUMBUFLEN];
- const char *const s1 = tv_get_string_buf(rettv, buf1);
- const char *const s2 = tv_get_string_buf(&var2, buf2);
- if (type != TYPE_MATCH && type != TYPE_NOMATCH) {
- i = mb_strcmp_ic(ic, s1, s2);
- } else {
- i = 0;
- }
- n1 = false;
- switch (type) {
- case TYPE_EQUAL: n1 = (i == 0); break;
- case TYPE_NEQUAL: n1 = (i != 0); break;
- case TYPE_GREATER: n1 = (i > 0); break;
- case TYPE_GEQUAL: n1 = (i >= 0); break;
- case TYPE_SMALLER: n1 = (i < 0); break;
- case TYPE_SEQUAL: n1 = (i <= 0); break;
-
- case TYPE_MATCH:
- case TYPE_NOMATCH: {
- n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
- if (type == TYPE_NOMATCH) {
- n1 = !n1;
- }
- break;
- }
- case TYPE_UNKNOWN: break; // Avoid gcc warning.
- }
- }
- tv_clear(rettv);
tv_clear(&var2);
- rettv->v_type = VAR_NUMBER;
- rettv->vval.v_number = n1;
+ return ret;
}
}
@@ -8000,8 +7839,8 @@ int get_id_len(const char **const arg)
*/
int get_name_len(const char **const arg,
char **alias,
- int evaluate,
- int verbose)
+ bool evaluate,
+ bool verbose)
{
int len;
@@ -8486,10 +8325,8 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
return oldval;
}
-/*
- * Get the value of internal variable "name".
- * Return OK or FAIL.
- */
+// Get the value of internal variable "name".
+// Return OK or FAIL. If OK is returned "rettv" must be cleared.
int get_var_tv(
const char *name,
int len, // length of "name"
@@ -10746,3 +10583,209 @@ bool invoke_prompt_interrupt(void)
tv_clear(&rettv);
return true;
}
+
+// Compare "typ1" and "typ2". Put the result in "typ1".
+int typval_compare(
+ typval_T *typ1, // first operand
+ typval_T *typ2, // second operand
+ exprtype_T type, // operator
+ bool ic // ignore case
+)
+ FUNC_ATTR_NONNULL_ALL
+{
+ varnumber_T n1, n2;
+ const bool type_is = type == EXPR_IS || type == EXPR_ISNOT;
+
+ if (type_is && typ1->v_type != typ2->v_type) {
+ // For "is" a different type always means false, for "notis"
+ // it means true.
+ n1 = type == EXPR_ISNOT;
+ } else if (typ1->v_type == VAR_LIST || typ2->v_type == VAR_LIST) {
+ if (type_is) {
+ n1 = typ1->v_type == typ2->v_type
+ && typ1->vval.v_list == typ2->vval.v_list;
+ if (type == EXPR_ISNOT) {
+ n1 = !n1;
+ }
+ } else if (typ1->v_type != typ2->v_type
+ || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) {
+ if (typ1->v_type != typ2->v_type) {
+ EMSG(_("E691: Can only compare List with List"));
+ } else {
+ EMSG(_("E692: Invalid operation for List"));
+ }
+ tv_clear(typ1);
+ return FAIL;
+ } else {
+ // Compare two Lists for being equal or unequal.
+ n1 = tv_list_equal(typ1->vval.v_list, typ2->vval.v_list, ic, false);
+ if (type == EXPR_NEQUAL) {
+ n1 = !n1;
+ }
+ }
+ } else if (typ1->v_type == VAR_DICT || typ2->v_type == VAR_DICT) {
+ if (type_is) {
+ n1 = typ1->v_type == typ2->v_type
+ && typ1->vval.v_dict == typ2->vval.v_dict;
+ if (type == EXPR_ISNOT) {
+ n1 = !n1;
+ }
+ } else if (typ1->v_type != typ2->v_type
+ || (type != EXPR_EQUAL && type != EXPR_NEQUAL)) {
+ if (typ1->v_type != typ2->v_type) {
+ EMSG(_("E735: Can only compare Dictionary with Dictionary"));
+ } else {
+ EMSG(_("E736: Invalid operation for Dictionary"));
+ }
+ tv_clear(typ1);
+ return FAIL;
+ } else {
+ // Compare two Dictionaries for being equal or unequal.
+ n1 = tv_dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, ic, false);
+ if (type == EXPR_NEQUAL) {
+ n1 = !n1;
+ }
+ }
+ } else if (tv_is_func(*typ1) || tv_is_func(*typ2)) {
+ if (type != EXPR_EQUAL && type != EXPR_NEQUAL
+ && type != EXPR_IS && type != EXPR_ISNOT) {
+ EMSG(_("E694: Invalid operation for Funcrefs"));
+ tv_clear(typ1);
+ return FAIL;
+ }
+ if ((typ1->v_type == VAR_PARTIAL && typ1->vval.v_partial == NULL)
+ || (typ2->v_type == VAR_PARTIAL && typ2->vval.v_partial == NULL)) {
+ // when a partial is NULL assume not equal
+ n1 = false;
+ } else if (type_is) {
+ if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) {
+ // strings are considered the same if their value is
+ // the same
+ n1 = tv_equal(typ1, typ2, ic, false);
+ } else if (typ1->v_type == VAR_PARTIAL && typ2->v_type == VAR_PARTIAL) {
+ n1 = typ1->vval.v_partial == typ2->vval.v_partial;
+ } else {
+ n1 = false;
+ }
+ } else {
+ n1 = tv_equal(typ1, typ2, ic, false);
+ }
+ if (type == EXPR_NEQUAL || type == EXPR_ISNOT) {
+ n1 = !n1;
+ }
+ } else if ((typ1->v_type == VAR_FLOAT || typ2->v_type == VAR_FLOAT)
+ && type != EXPR_MATCH && type != EXPR_NOMATCH) {
+ // If one of the two variables is a float, compare as a float.
+ // When using "=~" or "!~", always compare as string.
+ const float_T f1 = tv_get_float(typ1);
+ const float_T f2 = tv_get_float(typ2);
+ n1 = false;
+ switch (type) {
+ case EXPR_IS:
+ case EXPR_EQUAL: n1 = f1 == f2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL: n1 = f1 != f2; break;
+ case EXPR_GREATER: n1 = f1 > f2; break;
+ case EXPR_GEQUAL: n1 = f1 >= f2; break;
+ case EXPR_SMALLER: n1 = f1 < f2; break;
+ case EXPR_SEQUAL: n1 = f1 <= f2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH: break; // avoid gcc warning
+ }
+ } else if ((typ1->v_type == VAR_NUMBER || typ2->v_type == VAR_NUMBER)
+ && type != EXPR_MATCH && type != EXPR_NOMATCH) {
+ // If one of the two variables is a number, compare as a number.
+ // When using "=~" or "!~", always compare as string.
+ n1 = tv_get_number(typ1);
+ n2 = tv_get_number(typ2);
+ switch (type) {
+ case EXPR_IS:
+ case EXPR_EQUAL: n1 = n1 == n2; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL: n1 = n1 != n2; break;
+ case EXPR_GREATER: n1 = n1 > n2; break;
+ case EXPR_GEQUAL: n1 = n1 >= n2; break;
+ case EXPR_SMALLER: n1 = n1 < n2; break;
+ case EXPR_SEQUAL: n1 = n1 <= n2; break;
+ case EXPR_UNKNOWN:
+ case EXPR_MATCH:
+ case EXPR_NOMATCH: break; // avoid gcc warning
+ }
+ } else {
+ char buf1[NUMBUFLEN];
+ char buf2[NUMBUFLEN];
+ const char *const s1 = tv_get_string_buf(typ1, buf1);
+ const char *const s2 = tv_get_string_buf(typ2, buf2);
+ int i;
+ if (type != EXPR_MATCH && type != EXPR_NOMATCH) {
+ i = mb_strcmp_ic(ic, s1, s2);
+ } else {
+ i = 0;
+ }
+ n1 = false;
+ switch (type) {
+ case EXPR_IS:
+ case EXPR_EQUAL: n1 = i == 0; break;
+ case EXPR_ISNOT:
+ case EXPR_NEQUAL: n1 = i != 0; break;
+ case EXPR_GREATER: n1 = i > 0; break;
+ case EXPR_GEQUAL: n1 = i >= 0; break;
+ case EXPR_SMALLER: n1 = i < 0; break;
+ case EXPR_SEQUAL: n1 = i <= 0; break;
+
+ case EXPR_MATCH:
+ case EXPR_NOMATCH:
+ n1 = pattern_match((char_u *)s2, (char_u *)s1, ic);
+ if (type == EXPR_NOMATCH) {
+ n1 = !n1;
+ }
+ break;
+ case EXPR_UNKNOWN: break; // avoid gcc warning
+ }
+ }
+ tv_clear(typ1);
+ typ1->v_type = VAR_NUMBER;
+ typ1->vval.v_number = n1;
+ return OK;
+}
+
+char *typval_tostring(typval_T *arg)
+{
+ if (arg == NULL) {
+ return xstrdup("(does not exist)");
+ }
+ return encode_tv2string(arg, NULL);
+}
+
+bool var_exists(const char *var)
+ FUNC_ATTR_NONNULL_ALL
+{
+ char *tofree;
+ bool n = false;
+
+ // get_name_len() takes care of expanding curly braces
+ const char *name = var;
+ const int len = get_name_len((const char **)&var, &tofree, true, false);
+ if (len > 0) {
+ typval_T tv;
+
+ if (tofree != NULL) {
+ name = tofree;
+ }
+ n = get_var_tv(name, len, &tv, NULL, false, true) == OK;
+ if (n) {
+ // Handle d.key, l[idx], f(expr).
+ n = handle_subscript(&var, &tv, true, false) == OK;
+ if (n) {
+ tv_clear(&tv);
+ }
+ }
+ }
+ if (*var != NUL) {
+ n = false;
+ }
+
+ xfree(tofree);
+ return n;
+}
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 4f03d5d259..3da4bb8655 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -158,6 +158,7 @@ typedef enum {
// Neovim
VV_STDERR,
VV_MSGPACK_TYPES,
+ VV__NULL_STRING, // String with NULL value. For test purposes only.
VV__NULL_LIST, // List with NULL value. For test purposes only.
VV__NULL_DICT, // Dictionary with NULL value. For test purposes only.
VV_LUA,
@@ -227,6 +228,21 @@ typedef enum
ASSERT_OTHER,
} assert_type_T;
+/// types for expressions.
+typedef enum {
+ EXPR_UNKNOWN = 0,
+ EXPR_EQUAL, ///< ==
+ EXPR_NEQUAL, ///< !=
+ EXPR_GREATER, ///< >
+ EXPR_GEQUAL, ///< >=
+ EXPR_SMALLER, ///< <
+ EXPR_SEQUAL, ///< <=
+ EXPR_MATCH, ///< =~
+ EXPR_NOMATCH, ///< !~
+ EXPR_IS, ///< is
+ EXPR_ISNOT, ///< isnot
+} exprtype_T;
+
/// Type for dict_list function
typedef enum {
kDictListKeys, ///< List dictionary keys.
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index fb72b9425e..0d288e2cc2 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2051,7 +2051,6 @@ static void f_exepath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_exists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int n = false;
- int len = 0;
const char *p = tv_get_string(&argvars[0]);
if (*p == '$') { // Environment variable.
@@ -2082,29 +2081,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
n = au_exists(p + 1);
}
} else { // Internal variable.
- typval_T tv;
-
- // get_name_len() takes care of expanding curly braces
- const char *name = p;
- char *tofree;
- len = get_name_len((const char **)&p, &tofree, true, false);
- if (len > 0) {
- if (tofree != NULL) {
- name = tofree;
- }
- n = (get_var_tv(name, len, &tv, NULL, false, true) == OK);
- if (n) {
- // Handle d.key, l[idx], f(expr).
- n = (handle_subscript(&p, &tv, true, false) == OK);
- if (n) {
- tv_clear(&tv);
- }
- }
- }
- if (*p != NUL)
- n = FALSE;
-
- xfree(tofree);
+ n = var_exists(p);
}
rettv->vval.v_number = n;
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 689d05e079..00260bc3f7 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -833,6 +833,8 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
bool islambda = false;
char_u numbuf[NUMBUFLEN];
char_u *name;
+ typval_T *tv_to_free[MAX_FUNC_ARGS];
+ int tv_to_free_len = 0;
proftime_T wait_start;
proftime_T call_start;
int started_profiling = false;
@@ -985,6 +987,11 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
v->di_tv = isdefault ? def_rettv : argvars[i];
v->di_tv.v_lock = VAR_FIXED;
+ if (isdefault) {
+ // Need to free this later, no matter where it's stored.
+ tv_to_free[tv_to_free_len++] = &v->di_tv;
+ }
+
if (addlocal) {
// Named arguments can be accessed without the "a:" prefix in lambda
// expressions. Add to the l: dict.
@@ -1209,7 +1216,9 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
did_emsg |= save_did_emsg;
depth--;
-
+ for (int i = 0; i < tv_to_free_len; i++) {
+ tv_clear(tv_to_free[i]);
+ }
cleanup_function_call(fc);
if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) {
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c
index 0b1ecb12e2..c02f730431 100644
--- a/src/nvim/event/libuv_process.c
+++ b/src/nvim/event/libuv_process.c
@@ -82,7 +82,7 @@ int libuv_process_spawn(LibuvProcess *uvproc)
int status;
if ((status = uv_spawn(&proc->loop->uv, &uvproc->uv, &uvproc->uvopts))) {
- ELOG("uv_spawn failed: %s", uv_strerror(status));
+ ELOG("uv_spawn(%s) failed: %s", uvproc->uvopts.file, uv_strerror(status));
if (uvproc->uvopts.env) {
os_free_fullenv(uvproc->uvopts.env);
}
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 2965ea7496..d99383303b 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -928,6 +928,12 @@ module.cmds = {
func='ex_edit',
},
{
+ command='eval',
+ flags=bit.bor(EXTRA, NOTRLCOM, SBOXOK, CMDWIN),
+ addr_type='ADDR_NONE',
+ func='ex_eval',
+ },
+ {
command='ex',
flags=bit.bor(BANG, FILE1, CMDARG, ARGOPT, TRLBAR),
addr_type='ADDR_NONE',
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index cc0ec71627..950a1a436f 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -120,6 +120,9 @@ struct source_cookie {
/// batch mode debugging: don't save and restore typeahead.
static bool debug_greedy = false;
+static char *debug_oldval = NULL; // old and newval for debug expressions
+static char *debug_newval = NULL;
+
/// Debug mode. Repeatedly get Ex commands, until told to continue normal
/// execution.
void do_debug(char_u *cmd)
@@ -166,6 +169,16 @@ void do_debug(char_u *cmd)
if (!debug_did_msg) {
MSG(_("Entering Debug mode. Type \"cont\" to continue."));
}
+ if (debug_oldval != NULL) {
+ smsg(_("Oldval = \"%s\""), debug_oldval);
+ xfree(debug_oldval);
+ debug_oldval = NULL;
+ }
+ if (debug_newval != NULL) {
+ smsg(_("Newval = \"%s\""), debug_newval);
+ xfree(debug_newval);
+ debug_newval = NULL;
+ }
if (sourcing_name != NULL) {
msg(sourcing_name);
}
@@ -174,7 +187,6 @@ void do_debug(char_u *cmd)
} else {
smsg(_("cmd: %s"), cmd);
}
-
// Repeat getting a command and executing it.
for (;; ) {
msg_scroll = true;
@@ -514,11 +526,13 @@ bool dbg_check_skipped(exarg_T *eap)
/// This is a grow-array of structs.
struct debuggy {
int dbg_nr; ///< breakpoint number
- int dbg_type; ///< DBG_FUNC or DBG_FILE
- char_u *dbg_name; ///< function or file name
+ int dbg_type; ///< DBG_FUNC or DBG_FILE or DBG_EXPR
+ char_u *dbg_name; ///< function, expression or file name
regprog_T *dbg_prog; ///< regexp program
linenr_T dbg_lnum; ///< line number in function or file
int dbg_forceit; ///< ! used
+ typval_T *dbg_val; ///< last result of watchexpression
+ int dbg_level; ///< stored nested level for expr
};
static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL };
@@ -530,6 +544,7 @@ static int last_breakp = 0; // nr of last defined breakpoint
static garray_T prof_ga = { 0, 0, sizeof(struct debuggy), 4, NULL };
#define DBG_FUNC 1
#define DBG_FILE 2
+#define DBG_EXPR 3
/// Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them
@@ -562,6 +577,8 @@ static int dbg_parsearg(char_u *arg, garray_T *gap)
}
bp->dbg_type = DBG_FILE;
here = true;
+ } else if (gap != &prof_ga && STRNCMP(p, "expr", 4) == 0) {
+ bp->dbg_type = DBG_EXPR;
} else {
EMSG2(_(e_invarg2), p);
return FAIL;
@@ -590,6 +607,9 @@ static int dbg_parsearg(char_u *arg, garray_T *gap)
bp->dbg_name = vim_strsave(p);
} else if (here) {
bp->dbg_name = vim_strsave(curbuf->b_ffname);
+ } else if (bp->dbg_type == DBG_EXPR) {
+ bp->dbg_name = vim_strsave(p);
+ bp->dbg_val = eval_expr(bp->dbg_name);
} else {
// Expand the file name in the same way as do_source(). This means
// doing it twice, so that $DIR/file gets expanded when $DIR is
@@ -621,7 +641,6 @@ static int dbg_parsearg(char_u *arg, garray_T *gap)
void ex_breakadd(exarg_T *eap)
{
struct debuggy *bp;
- char_u *pat;
garray_T *gap;
gap = &dbg_breakp;
@@ -633,22 +652,28 @@ void ex_breakadd(exarg_T *eap)
bp = &DEBUGGY(gap, gap->ga_len);
bp->dbg_forceit = eap->forceit;
- pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false);
- if (pat != NULL) {
- bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
- xfree(pat);
- }
- if (pat == NULL || bp->dbg_prog == NULL) {
- xfree(bp->dbg_name);
- } else {
- if (bp->dbg_lnum == 0) { // default line number is 1
- bp->dbg_lnum = 1;
+ if (bp->dbg_type != DBG_EXPR) {
+ char_u *pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false);
+ if (pat != NULL) {
+ bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
+ xfree(pat);
}
- if (eap->cmdidx != CMD_profile) {
- DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
- debug_tick++;
+ if (pat == NULL || bp->dbg_prog == NULL) {
+ xfree(bp->dbg_name);
+ } else {
+ if (bp->dbg_lnum == 0) { // default line number is 1
+ bp->dbg_lnum = 1;
+ }
+ if (eap->cmdidx != CMD_profile) {
+ DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
+ debug_tick++;
+ }
+ gap->ga_len++;
}
- gap->ga_len++;
+ } else {
+ // DBG_EXPR
+ DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp;
+ debug_tick++;
}
}
}
@@ -691,7 +716,7 @@ void ex_breakdel(exarg_T *eap)
todel = 0;
del_all = true;
} else {
- // ":breakdel {func|file} [lnum] {name}"
+ // ":breakdel {func|file|expr} [lnum] {name}"
if (dbg_parsearg(eap->arg, gap) == FAIL) {
return;
}
@@ -716,6 +741,10 @@ void ex_breakdel(exarg_T *eap)
} else {
while (!GA_EMPTY(gap)) {
xfree(DEBUGGY(gap, todel).dbg_name);
+ if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR
+ && DEBUGGY(gap, todel).dbg_val != NULL) {
+ tv_free(DEBUGGY(gap, todel).dbg_val);
+ }
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
gap->ga_len--;
if (todel < gap->ga_len) {
@@ -750,11 +779,15 @@ void ex_breaklist(exarg_T *eap)
if (bp->dbg_type == DBG_FILE) {
home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, true);
}
- smsg(_("%3d %s %s line %" PRId64),
- bp->dbg_nr,
- bp->dbg_type == DBG_FUNC ? "func" : "file",
- bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
- (int64_t)bp->dbg_lnum);
+ if (bp->dbg_type != DBG_EXPR) {
+ smsg(_("%3d %s %s line %" PRId64),
+ bp->dbg_nr,
+ bp->dbg_type == DBG_FUNC ? "func" : "file",
+ bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
+ (int64_t)bp->dbg_lnum);
+ } else {
+ smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name);
+ }
}
}
}
@@ -814,6 +847,7 @@ debuggy_find(
// an already found breakpoint.
bp = &DEBUGGY(gap, i);
if ((bp->dbg_type == DBG_FILE) == file
+ && bp->dbg_type != DBG_EXPR
&& (gap == &prof_ga
|| (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum)))) {
// Save the value of got_int and reset it. We don't want a
@@ -828,6 +862,46 @@ debuggy_find(
}
}
got_int |= prev_got_int;
+ } else if (bp->dbg_type == DBG_EXPR) {
+ bool line = false;
+
+ prev_got_int = got_int;
+ got_int = false;
+
+ typval_T *tv = eval_expr(bp->dbg_name);
+ if (tv != NULL) {
+ if (bp->dbg_val == NULL) {
+ debug_oldval = typval_tostring(NULL);
+ bp->dbg_val = tv;
+ debug_newval = typval_tostring(bp->dbg_val);
+ line = true;
+ } else {
+ if (typval_compare(tv, bp->dbg_val, EXPR_IS, false) == OK
+ && tv->vval.v_number == false) {
+ line = true;
+ debug_oldval = typval_tostring(bp->dbg_val);
+ // Need to evaluate again, typval_compare() overwrites "tv".
+ typval_T *v = eval_expr(bp->dbg_name);
+ debug_newval = typval_tostring(v);
+ tv_free(bp->dbg_val);
+ bp->dbg_val = v;
+ }
+ tv_free(tv);
+ }
+ } else if (bp->dbg_val != NULL) {
+ debug_oldval = typval_tostring(bp->dbg_val);
+ debug_newval = typval_tostring(NULL);
+ tv_free(bp->dbg_val);
+ bp->dbg_val = NULL;
+ line = true;
+ }
+
+ if (line) {
+ lnum = after > 0 ? after : 1;
+ break;
+ }
+
+ got_int |= prev_got_int;
}
}
if (name != fname) {
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index d1eddfc74f..ae5c334592 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1857,6 +1857,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
case CMD_echoerr:
case CMD_echomsg:
case CMD_echon:
+ case CMD_eval:
case CMD_execute:
case CMD_filter:
case CMD_help:
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index 0917c6dd02..5ca88002f1 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -788,6 +788,15 @@ void report_discard_pending(int pending, void *value)
}
}
+// ":eval".
+void ex_eval(exarg_T *eap)
+{
+ typval_T tv;
+
+ if (eval0(eap->arg, &tv, &eap->nextcmd, !eap->skip) == OK) {
+ tv_clear(&tv);
+ }
+}
/*
* ":if".
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index e6b2b231f9..7159b27665 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -784,9 +784,18 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
// 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();
+ if (!cmd_silent && msg_scrolled == 0) {
+ bool found_one = false;
+
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (*p_stl != NUL || *wp->w_p_stl != NUL) {
+ wp->w_redr_status = true;
+ found_one = true;
+ }
+ }
+ if (found_one) {
+ redraw_statuslines();
+ }
}
did_emsg = false;
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 65bd809436..792ef81665 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -4947,11 +4947,11 @@ int buf_check_timestamp(buf_T *buf)
(void)msg_end();
if (emsg_silent == 0) {
ui_flush();
- /* give the user some time to think about it */
- os_delay(1000L, true);
+ // give the user some time to think about it
+ os_delay(1004L, true);
- /* don't redraw and erase the message */
- redraw_cmdline = FALSE;
+ // don't redraw and erase the message
+ redraw_cmdline = false;
}
}
already_warned = TRUE;
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 9b8e9ff8cc..f99a2dd0fe 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -17,6 +17,7 @@
#include "nvim/api/vim.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/vim.h"
+#include "nvim/extmark.h"
#include "nvim/ex_getln.h"
#include "nvim/ex_cmds2.h"
#include "nvim/map.h"
@@ -1243,13 +1244,16 @@ void ex_luado(exarg_T *const eap)
break;
}
lua_pushvalue(lstate, -1);
- lua_pushstring(lstate, (const char *)ml_get_buf(curbuf, l, false));
+ const char *old_line = (const char *)ml_get_buf(curbuf, l, false);
+ lua_pushstring(lstate, old_line);
lua_pushnumber(lstate, (lua_Number)l);
if (lua_pcall(lstate, 2, 1, 0)) {
nlua_error(lstate, _("E5111: Error calling lua: %.*s"));
break;
}
if (lua_isstring(lstate, -1)) {
+ size_t old_line_len = STRLEN(old_line);
+
size_t new_line_len;
const char *const new_line = lua_tolstring(lstate, -1, &new_line_len);
char *const new_line_transformed = xmemdupz(new_line, new_line_len);
@@ -1259,7 +1263,7 @@ void ex_luado(exarg_T *const eap)
}
}
ml_replace(l, (char_u *)new_line_transformed, false);
- changed_bytes(l, 0);
+ inserted_bytes(l, 0, (int)old_line_len, (int)new_line_len);
}
lua_pop(lstate, 1);
}
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index a0b439ac45..a2d8859c68 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -219,7 +219,7 @@ static void receive_msgpack(Stream *stream, RBuffer *rbuf, size_t c,
char buf[256];
snprintf(buf, sizeof(buf), "ch %" PRIu64 " was closed by the client",
channel->id);
- call_set_error(channel, buf, WARN_LOG_LEVEL);
+ call_set_error(channel, buf, INFO_LOG_LEVEL);
goto end;
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index f016ef6813..c948881eca 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -630,9 +630,9 @@ static void normal_redraw_mode_message(NormalState *s)
ui_cursor_shape(); // show different cursor shape
ui_flush();
if (msg_scroll || emsg_on_display) {
- os_delay(1000L, true); // wait at least one second
+ os_delay(1003L, true); // wait at least one second
}
- os_delay(3000L, false); // wait up to three seconds
+ os_delay(3003L, false); // wait up to three seconds
State = save_State;
msg_scroll = false;
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index d794969ab5..36d6dbe2db 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -175,7 +175,7 @@ static void init_child(PtyProcess *ptyproc)
Process *proc = (Process *)ptyproc;
if (proc->cwd && os_chdir(proc->cwd) != 0) {
- ELOG("chdir failed: %s", strerror(errno));
+ ELOG("chdir(%s) failed: %s", proc->cwd, strerror(errno));
return;
}
@@ -184,7 +184,7 @@ static void init_child(PtyProcess *ptyproc)
assert(proc->env);
environ = tv_dict_to_env(proc->env);
execvp(prog, proc->argv);
- ELOG("execvp failed: %s: %s", strerror(errno), prog);
+ ELOG("execvp(%s) failed: %s", prog, strerror(errno));
_exit(122); // 122 is EXEC_FAILED in the Vim source.
}
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c
index 94444e4d23..2bf73d08e6 100644
--- a/src/nvim/os/pty_process_win.c
+++ b/src/nvim/os/pty_process_win.c
@@ -203,11 +203,13 @@ int pty_process_spawn(PtyProcess *ptyproc)
cleanup:
if (status) {
// In the case of an error of MultiByteToWideChar or CreateProcessW.
- ELOG("pty_process_spawn: %s: error code: %d", emsg, status);
+ ELOG("pty_process_spawn(%s): %s: error code: %d",
+ proc->argv[0], emsg, status);
status = os_translate_sys_error(status);
} else if (err != NULL) {
status = (int)winpty_error_code(err);
- ELOG("pty_process_spawn: %s: error code: %d", emsg, status);
+ ELOG("pty_process_spawn(%s): %s: error code: %d",
+ proc->argv[0], emsg, status);
status = translate_winpty_error(status);
}
winpty_error_free(err);
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c
index e7e0dc4013..9ea74716aa 100644
--- a/src/nvim/os/time.c
+++ b/src/nvim/os/time.c
@@ -62,6 +62,7 @@ uint64_t os_now(void)
/// @param ignoreinput If true, only SIGINT (CTRL-C) can interrupt.
void os_delay(uint64_t ms, bool ignoreinput)
{
+ DLOG("%" PRIu64 " ms", ms);
if (ignoreinput) {
if (ms > INT_MAX) {
ms = INT_MAX;
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index d7693c7a6f..184f5da97d 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -6665,6 +6665,10 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
int len = 0; /* init for GCC */
static char_u *eval_result = NULL;
+ // We need to keep track of how many backslashes we escape, so that the byte
+ // counts for `extmark_splice` are correct.
+ int num_escaped = 0;
+
// Be paranoid...
if ((source == NULL && expr == NULL) || dest == NULL) {
EMSG(_(e_null));
@@ -6840,6 +6844,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
// later. Used to insert a literal CR.
default:
if (backslash) {
+ num_escaped += 1;
if (copy) {
*dst = '\\';
}
@@ -6979,7 +6984,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
*dst = NUL;
exit:
- return (int)((dst - dest) + 1);
+ return (int)((dst - dest) + 1 - num_escaped);
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 9fb2eb2772..6be3b6fb60 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -3951,7 +3951,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
.hl_id = hl_err }));
do_virttext = true;
} else if (has_decor) {
- virt_text = decor_redraw_virt_text(wp->w_buffer, &decor_state);
+ virt_text = decor_redraw_eol(wp->w_buffer, &decor_state, &line_attr);
if (kv_size(virt_text)) {
do_virttext = true;
}
@@ -4381,11 +4381,12 @@ void draw_virt_text(buf_T *buf, int *end_col, int max_col)
{
DecorState *state = &decor_state;
for (size_t i = 0; i < kv_size(state->active); i++) {
- HlRange *item = &kv_A(state->active, i);
- if (item->start_row == state->row && kv_size(item->virt_text)
- && item->virt_text_pos == kVTOverlay
+ DecorRange *item = &kv_A(state->active, i);
+ if (item->start_row == state->row && kv_size(item->decor.virt_text)
+ && item->decor.virt_text_pos == kVTOverlay
&& item->virt_col >= 0) {
- VirtText vt = item->virt_text;
+ VirtText vt = item->decor.virt_text;
+ HlMode hl_mode = item->decor.hl_mode;
LineState s = LINE_STATE("");
int virt_attr = 0;
int col = item->virt_col;
@@ -4405,9 +4406,9 @@ void draw_virt_text(buf_T *buf, int *end_col, int max_col)
}
int attr;
bool through = false;
- if (item->hl_mode == kHlModeCombine) {
+ if (hl_mode == kHlModeCombine) {
attr = hl_combine_attr(linebuf_attr[col], virt_attr);
- } else if (item->hl_mode == kHlModeBlend) {
+ } else if (hl_mode == kHlModeBlend) {
through = (*s.p == ' ');
attr = hl_blend_attrs(linebuf_attr[col], virt_attr, &through);
} else {
@@ -6226,7 +6227,7 @@ void check_for_delay(int check_msg_scroll)
&& !did_wait_return
&& emsg_silent == 0) {
ui_flush();
- os_delay(1000L, true);
+ os_delay(1006L, true);
emsg_on_display = false;
if (check_msg_scroll) {
msg_scroll = false;
diff --git a/src/nvim/search.c b/src/nvim/search.c
index c4479a077e..abe05bbd12 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -2373,10 +2373,11 @@ showmatch(
* brief pause, unless 'm' is present in 'cpo' and a character is
* available.
*/
- if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL)
- os_delay(p_mat * 100L, true);
- else if (!char_avail())
- os_delay(p_mat * 100L, false);
+ if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) {
+ os_delay(p_mat * 100L + 8, true);
+ } else if (!char_avail()) {
+ os_delay(p_mat * 100L + 9, false);
+ }
curwin->w_cursor = save_cursor; // restore cursor position
*so = save_so;
*siso = save_siso;
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 825aef1465..77a751e5ad 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -5306,13 +5306,17 @@ get_id_list(
xfree(name);
break;
}
- if (name[1] == 'A')
- id = SYNID_ALLBUT;
- else if (name[1] == 'T')
- id = SYNID_TOP;
- else
- id = SYNID_CONTAINED;
- id += current_syn_inc_tag;
+ if (name[1] == 'A') {
+ id = SYNID_ALLBUT + current_syn_inc_tag;
+ } else if (name[1] == 'T') {
+ if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) {
+ id = curwin->w_s->b_syn_topgrp;
+ } else {
+ id = SYNID_TOP + current_syn_inc_tag;
+ }
+ } else {
+ id = SYNID_CONTAINED + current_syn_inc_tag;
+ }
} else if (name[1] == '@') {
if (skip) {
id = -1;
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 588821f260..a6310344e9 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -625,7 +625,7 @@ do_tag(
}
if (ic && !msg_scrolled && msg_silent == 0) {
ui_flush();
- os_delay(1000L, true);
+ os_delay(1007L, true);
}
}
@@ -2853,7 +2853,7 @@ static int jumpto_tag(
MSG(_("E435: Couldn't find tag, just guessing!"));
if (!msg_scrolled && msg_silent == 0) {
ui_flush();
- os_delay(1000L, true);
+ os_delay(1010L, true);
}
}
retval = OK;
diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim
index 2d94b637e0..49993c03aa 100644
--- a/src/nvim/testdir/runtest.vim
+++ b/src/nvim/testdir/runtest.vim
@@ -13,6 +13,9 @@
" For csh:
" setenv TEST_FILTER Test_channel
"
+" While working on a test you can make $TEST_NO_RETRY non-empty to not retry:
+" export TEST_NO_RETRY=yes
+"
" To ignore failure for tests that are known to fail in a certain environment,
" set $TEST_MAY_FAIL to a comma separated list of function names. E.g. for
" sh/bash:
@@ -413,9 +416,11 @@ for s:test in sort(s:tests)
call RunTheTest(s:test)
" Repeat a flaky test. Give up when:
+ " - $TEST_NO_RETRY is not empty
" - it fails again with the same message
" - it fails five times (with a different message)
if len(v:errors) > 0
+ \ && $TEST_NO_RETRY == ''
\ && (index(s:flaky_tests, s:test) >= 0
\ || g:test_is_flaky)
while 1
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index 71af3eead7..e50602ccad 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -35,6 +35,7 @@ source test_popup.vim
source test_put.vim
source test_rename.vim
source test_scroll_opt.vim
+source test_shift.vim
source test_sort.vim
source test_sha256.vim
source test_suspend.vim
diff --git a/src/nvim/testdir/test_alot_utf8.vim b/src/nvim/testdir/test_alot_utf8.vim
index be0bd01413..70f14320a6 100644
--- a/src/nvim/testdir/test_alot_utf8.vim
+++ b/src/nvim/testdir/test_alot_utf8.vim
@@ -6,7 +6,6 @@
source test_charsearch_utf8.vim
source test_expr_utf8.vim
-source test_listlbr_utf8.vim
source test_matchadd_conceal_utf8.vim
source test_mksession_utf8.vim
source test_regexp_utf8.vim
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index 5e99edf233..5611560b1b 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -276,28 +276,28 @@ func Test_augroup_warning()
augroup TheWarning
au VimEnter * echo 'entering'
augroup END
- call assert_true(match(execute('au VimEnter'), "TheWarning.*VimEnter") >= 0)
+ call assert_match("TheWarning.*VimEnter", execute('au VimEnter'))
redir => res
augroup! TheWarning
redir END
- call assert_true(match(res, "W19:") >= 0)
- call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0)
+ call assert_match("W19:", res)
+ call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
" check "Another" does not take the pace of the deleted entry
augroup Another
augroup END
- call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0)
+ call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
augroup! Another
" no warning for postpone aucmd delete
augroup StartOK
au VimEnter * call RemoveGroup()
augroup END
- call assert_true(match(execute('au VimEnter'), "StartOK.*VimEnter") >= 0)
+ call assert_match("StartOK.*VimEnter", execute('au VimEnter'))
redir => res
doautocmd VimEnter
redir END
- call assert_true(match(res, "W19:") < 0)
+ call assert_notmatch("W19:", res)
au! VimEnter
endfunc
@@ -325,7 +325,7 @@ func Test_augroup_deleted()
au VimEnter * echo
augroup end
augroup! x
- call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0)
+ call assert_match("-Deleted-.*VimEnter", execute('au VimEnter'))
au! VimEnter
endfunc
diff --git a/src/nvim/testdir/test_backspace_opt.vim b/src/nvim/testdir/test_backspace_opt.vim
index d680b442db..11459991ea 100644
--- a/src/nvim/testdir/test_backspace_opt.vim
+++ b/src/nvim/testdir/test_backspace_opt.vim
@@ -1,15 +1,5 @@
" Tests for 'backspace' settings
-func Exec(expr)
- let str=''
- try
- exec a:expr
- catch /.*/
- let str=v:exception
- endtry
- return str
-endfunc
-
func Test_backspace_option()
set backspace=
call assert_equal('', &backspace)
@@ -41,10 +31,10 @@ func Test_backspace_option()
set backspace-=eol
call assert_equal('', &backspace)
" Check the error
- call assert_equal(0, match(Exec('set backspace=ABC'), '.*E474'))
- call assert_equal(0, match(Exec('set backspace+=def'), '.*E474'))
+ call assert_fails('set backspace=ABC', 'E474:')
+ call assert_fails('set backspace+=def', 'E474:')
" NOTE: Vim doesn't check following error...
- "call assert_equal(0, match(Exec('set backspace-=ghi'), '.*E474'))
+ "call assert_fails('set backspace-=ghi', 'E474:')
" Check backwards compatibility with version 5.4 and earlier
set backspace=0
@@ -55,8 +45,8 @@ func Test_backspace_option()
call assert_equal('2', &backspace)
set backspace=3
call assert_equal('3', &backspace)
- call assert_false(match(Exec('set backspace=4'), '.*E474'))
- call assert_false(match(Exec('set backspace=10'), '.*E474'))
+ call assert_fails('set backspace=4', 'E474:')
+ call assert_fails('set backspace=10', 'E474:')
" Cleared when 'compatible' is set
" set compatible
diff --git a/src/nvim/testdir/test_debugger.vim b/src/nvim/testdir/test_debugger.vim
index 59d51b855b..d1464e9d3b 100644
--- a/src/nvim/testdir/test_debugger.vim
+++ b/src/nvim/testdir/test_debugger.vim
@@ -2,6 +2,31 @@
source shared.vim
source screendump.vim
+source check.vim
+
+func CheckCWD()
+ " Check that the longer lines don't wrap due to the length of the script name
+ " in cwd
+ let script_len = len( getcwd() .. '/Xtest1.vim' )
+ let longest_line = len( 'Breakpoint in "" line 1' )
+ if script_len > ( 75 - longest_line )
+ throw 'Skipped: Your CWD has too many characters'
+ endif
+endfunc
+command! -nargs=0 -bar CheckCWD call CheckCWD()
+
+func CheckDbgOutput(buf, lines, options = {})
+ " Verify the expected output
+ let lnum = 20 - len(a:lines)
+ for l in a:lines
+ if get(a:options, 'match', 'equal') ==# 'pattern'
+ call WaitForAssert({-> assert_match(l, term_getline(a:buf, lnum))}, 200)
+ else
+ call WaitForAssert({-> assert_equal(l, term_getline(a:buf, lnum))}, 200)
+ endif
+ let lnum += 1
+ endfor
+endfunc
" Run a Vim debugger command
" If the expected output argument is supplied, then check for it.
@@ -10,20 +35,17 @@ func RunDbgCmd(buf, cmd, ...)
call term_wait(a:buf)
if a:0 != 0
- " Verify the expected output
- let lnum = 20 - len(a:1)
- for l in a:1
- call WaitForAssert({-> assert_equal(l, term_getline(a:buf, lnum))})
- let lnum += 1
- endfor
+ let options = #{match: 'equal'}
+ if a:0 > 1
+ call extend(options, a:2)
+ endif
+ call CheckDbgOutput(a:buf, a:1, options)
endif
endfunc
" Debugger tests
func Test_Debugger()
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot run Vim in a terminal window'
- endif
+ CheckRunVimInTerminal
" Create a Vim script with some functions
let lines =<< trim END
@@ -317,6 +339,785 @@ func Test_Debugger()
call delete('Xtest.vim')
endfunc
+func Test_Backtrace_Through_Source()
+ CheckRunVimInTerminal
+ CheckCWD
+ let file1 =<< trim END
+ func SourceAnotherFile()
+ source Xtest2.vim
+ endfunc
+
+ func CallAFunction()
+ call SourceAnotherFile()
+ call File2Function()
+ endfunc
+
+ func GlobalFunction()
+ call CallAFunction()
+ endfunc
+ END
+ call writefile(file1, 'Xtest1.vim')
+
+ let file2 =<< trim END
+ func DoAThing()
+ echo "DoAThing"
+ endfunc
+
+ func File2Function()
+ call DoAThing()
+ endfunc
+
+ call File2Function()
+ END
+ call writefile(file2, 'Xtest2.vim')
+
+ let buf = RunVimInTerminal('-S Xtest1.vim', {})
+
+ call RunDbgCmd(buf,
+ \ ':debug call GlobalFunction()',
+ \ ['cmd: call GlobalFunction()'])
+ call RunDbgCmd(buf, 'step', ['line 1: call CallAFunction()'])
+
+ call RunDbgCmd(buf, 'backtrace', ['>backtrace',
+ \ '->0 function GlobalFunction',
+ \ 'line 1: call CallAFunction()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call SourceAnotherFile()'])
+ call RunDbgCmd(buf, 'step', ['line 1: source Xtest2.vim'])
+
+ call RunDbgCmd(buf, 'backtrace', ['>backtrace',
+ \ ' 2 function GlobalFunction[1]',
+ \ ' 1 CallAFunction[1]',
+ \ '->0 SourceAnotherFile',
+ \ 'line 1: source Xtest2.vim'])
+
+ " Step into the 'source' command. Note that we print the full trace all the
+ " way though the source command.
+ call RunDbgCmd(buf, 'step', ['line 1: func DoAThing()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()'])
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ '->1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ '->2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up', [ 'frame at highest level: 3' ] )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ '->2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ '->1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down', [ 'frame is zero' ] )
+
+ " step until we have another meaninfgul trace
+ call RunDbgCmd(buf, 'step', ['line 5: func File2Function()'])
+ call RunDbgCmd(buf, 'step', ['line 9: call File2Function()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 9: call File2Function()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call DoAThing()'])
+ call RunDbgCmd(buf, 'step', ['line 1: echo "DoAThing"'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 5 function GlobalFunction[1]',
+ \ ' 4 CallAFunction[1]',
+ \ ' 3 SourceAnotherFile[1]',
+ \ ' 2 script ' .. getcwd() .. '/Xtest2.vim[9]',
+ \ ' 1 function File2Function[1]',
+ \ '->0 DoAThing',
+ \ 'line 1: echo "DoAThing"'])
+
+ " Now, step (back to Xfile1.vim), and call the function _in_ Xfile2.vim
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 10: End of sourced file'])
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 2: call File2Function()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 1 function GlobalFunction[1]',
+ \ '->0 CallAFunction',
+ \ 'line 2: call File2Function()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call DoAThing()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 2 function GlobalFunction[1]',
+ \ ' 1 CallAFunction[2]',
+ \ '->0 File2Function',
+ \ 'line 1: call DoAThing()'])
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest1.vim')
+ call delete('Xtest2.vim')
+endfunc
+
+func Test_Backtrace_Autocmd()
+ CheckRunVimInTerminal
+ CheckCWD
+ let file1 =<< trim END
+ func SourceAnotherFile()
+ source Xtest2.vim
+ endfunc
+
+ func CallAFunction()
+ call SourceAnotherFile()
+ call File2Function()
+ endfunc
+
+ func GlobalFunction()
+ call CallAFunction()
+ endfunc
+
+ au User TestGlobalFunction :call GlobalFunction() | echo "Done"
+ END
+ call writefile(file1, 'Xtest1.vim')
+
+ let file2 =<< trim END
+ func DoAThing()
+ echo "DoAThing"
+ endfunc
+
+ func File2Function()
+ call DoAThing()
+ endfunc
+
+ call File2Function()
+ END
+ call writefile(file2, 'Xtest2.vim')
+
+ let buf = RunVimInTerminal('-S Xtest1.vim', {})
+
+ call RunDbgCmd(buf,
+ \ ':debug doautocmd User TestGlobalFunction',
+ \ ['cmd: doautocmd User TestGlobalFunction'])
+ call RunDbgCmd(buf, 'step', ['cmd: call GlobalFunction() | echo "Done"'])
+
+ " At this point the ontly thing in the stack is the autocommand
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->0 User Autocommands for "TestGlobalFunction"',
+ \ 'cmd: call GlobalFunction() | echo "Done"'])
+
+ " And now we're back into the call stack
+ call RunDbgCmd(buf, 'step', ['line 1: call CallAFunction()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 1 User Autocommands for "TestGlobalFunction"',
+ \ '->0 function GlobalFunction',
+ \ 'line 1: call CallAFunction()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call SourceAnotherFile()'])
+ call RunDbgCmd(buf, 'step', ['line 1: source Xtest2.vim'])
+
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 User Autocommands for "TestGlobalFunction"',
+ \ ' 2 function GlobalFunction[1]',
+ \ ' 1 CallAFunction[1]',
+ \ '->0 SourceAnotherFile',
+ \ 'line 1: source Xtest2.vim'])
+
+ " Step into the 'source' command. Note that we print the full trace all the
+ " way though the source command.
+ call RunDbgCmd(buf, 'step', ['line 1: func DoAThing()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()'])
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ '->1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ '->2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ '->3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'up', [ 'frame at highest level: 4' ] )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ '->3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ '->2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ '->1 SourceAnotherFile[1]',
+ \ ' 0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down' )
+ call RunDbgCmd( buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 1: func DoAThing()' ] )
+
+ call RunDbgCmd( buf, 'down', [ 'frame is zero' ] )
+
+ " step until we have another meaninfgul trace
+ call RunDbgCmd(buf, 'step', ['line 5: func File2Function()'])
+ call RunDbgCmd(buf, 'step', ['line 9: call File2Function()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 4 User Autocommands for "TestGlobalFunction"',
+ \ ' 3 function GlobalFunction[1]',
+ \ ' 2 CallAFunction[1]',
+ \ ' 1 SourceAnotherFile[1]',
+ \ '->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ 'line 9: call File2Function()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call DoAThing()'])
+ call RunDbgCmd(buf, 'step', ['line 1: echo "DoAThing"'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 6 User Autocommands for "TestGlobalFunction"',
+ \ ' 5 function GlobalFunction[1]',
+ \ ' 4 CallAFunction[1]',
+ \ ' 3 SourceAnotherFile[1]',
+ \ ' 2 script ' .. getcwd() .. '/Xtest2.vim[9]',
+ \ ' 1 function File2Function[1]',
+ \ '->0 DoAThing',
+ \ 'line 1: echo "DoAThing"'])
+
+ " Now, step (back to Xfile1.vim), and call the function _in_ Xfile2.vim
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 10: End of sourced file'])
+ call RunDbgCmd(buf, 'step', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'step', ['line 2: call File2Function()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 2 User Autocommands for "TestGlobalFunction"',
+ \ ' 1 function GlobalFunction[1]',
+ \ '->0 CallAFunction',
+ \ 'line 2: call File2Function()'])
+
+ call RunDbgCmd(buf, 'step', ['line 1: call DoAThing()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 User Autocommands for "TestGlobalFunction"',
+ \ ' 2 function GlobalFunction[1]',
+ \ ' 1 CallAFunction[2]',
+ \ '->0 File2Function',
+ \ 'line 1: call DoAThing()'])
+
+
+ " Now unwind so that we get back to the original autocommand (and the second
+ " cmd echo "Done")
+ call RunDbgCmd(buf, 'finish', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 3 User Autocommands for "TestGlobalFunction"',
+ \ ' 2 function GlobalFunction[1]',
+ \ ' 1 CallAFunction[2]',
+ \ '->0 File2Function',
+ \ 'line 1: End of function'])
+
+ call RunDbgCmd(buf, 'finish', ['line 2: End of function'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 2 User Autocommands for "TestGlobalFunction"',
+ \ ' 1 function GlobalFunction[1]',
+ \ '->0 CallAFunction',
+ \ 'line 2: End of function'])
+
+ call RunDbgCmd(buf, 'finish', ['line 1: End of function'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 1 User Autocommands for "TestGlobalFunction"',
+ \ '->0 function GlobalFunction',
+ \ 'line 1: End of function'])
+
+ call RunDbgCmd(buf, 'step', ['cmd: echo "Done"'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->0 User Autocommands for "TestGlobalFunction"',
+ \ 'cmd: echo "Done"'])
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest1.vim')
+ call delete('Xtest2.vim')
+endfunc
+
+func Test_Backtrace_CmdLine()
+ CheckRunVimInTerminal
+ CheckCWD
+ let file1 =<< trim END
+ func SourceAnotherFile()
+ source Xtest2.vim
+ endfunc
+
+ func CallAFunction()
+ call SourceAnotherFile()
+ call File2Function()
+ endfunc
+
+ func GlobalFunction()
+ call CallAFunction()
+ endfunc
+
+ au User TestGlobalFunction :call GlobalFunction() | echo "Done"
+ END
+ call writefile(file1, 'Xtest1.vim')
+
+ let file2 =<< trim END
+ func DoAThing()
+ echo "DoAThing"
+ endfunc
+
+ func File2Function()
+ call DoAThing()
+ endfunc
+
+ call File2Function()
+ END
+ call writefile(file2, 'Xtest2.vim')
+
+ let buf = RunVimInTerminal(
+ \ '-S Xtest1.vim -c "debug call GlobalFunction()"',
+ \ {'wait_for_ruler': 0})
+
+ " Need to wait for the vim-in-terminal to be ready
+ call CheckDbgOutput(buf, ['command line',
+ \ 'cmd: call GlobalFunction()'])
+
+ " At this point the ontly thing in the stack is the cmdline
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ '->0 command line',
+ \ 'cmd: call GlobalFunction()'])
+
+ " And now we're back into the call stack
+ call RunDbgCmd(buf, 'step', ['line 1: call CallAFunction()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '>backtrace',
+ \ ' 1 command line',
+ \ '->0 function GlobalFunction',
+ \ 'line 1: call CallAFunction()'])
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest1.vim')
+ call delete('Xtest2.vim')
+endfunc
+
+func Test_Backtrace_DefFunction()
+ CheckRunVimInTerminal
+ CheckCWD
+ let file1 =<< trim END
+ vim9script
+ import File2Function from './Xtest2.vim'
+
+ def SourceAnotherFile()
+ source Xtest2.vim
+ enddef
+
+ def CallAFunction()
+ SourceAnotherFile()
+ File2Function()
+ enddef
+
+ def g:GlobalFunction()
+ CallAFunction()
+ enddef
+
+ defcompile
+ END
+ call writefile(file1, 'Xtest1.vim')
+
+ let file2 =<< trim END
+ vim9script
+
+ def DoAThing(): number
+ var a = 100 * 2
+ a += 3
+ return a
+ enddef
+
+ export def File2Function()
+ DoAThing()
+ enddef
+
+ defcompile
+ File2Function()
+ END
+ call writefile(file2, 'Xtest2.vim')
+
+ let buf = RunVimInTerminal('-S Xtest1.vim', {})
+
+ call RunDbgCmd(buf,
+ \ ':debug call GlobalFunction()',
+ \ ['cmd: call GlobalFunction()'])
+
+ " FIXME: Vim9 lines are not debugged!
+ call RunDbgCmd(buf, 'step', ['line 1: source Xtest2.vim'])
+
+ " But they do appear in the backtrace
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 2 function GlobalFunction[1]',
+ \ '\V 1 <SNR>\.\*_CallAFunction[1]',
+ \ '\V->0 <SNR>\.\*_SourceAnotherFile',
+ \ '\Vline 1: source Xtest2.vim'],
+ \ #{match: 'pattern'})
+
+
+ call RunDbgCmd(buf, 'step', ['line 1: vim9script'])
+ call RunDbgCmd(buf, 'step', ['line 3: def DoAThing(): number'])
+ call RunDbgCmd(buf, 'step', ['line 9: export def File2Function()'])
+ call RunDbgCmd(buf, 'step', ['line 9: def File2Function()'])
+ call RunDbgCmd(buf, 'step', ['line 13: defcompile'])
+ call RunDbgCmd(buf, 'step', ['line 14: File2Function()'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 3 function GlobalFunction[1]',
+ \ '\V 2 <SNR>\.\*_CallAFunction[1]',
+ \ '\V 1 <SNR>\.\*_SourceAnotherFile[1]',
+ \ '\V->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ '\Vline 14: File2Function()'],
+ \ #{match: 'pattern'})
+
+ " Don't step into compiled functions...
+ call RunDbgCmd(buf, 'step', ['line 15: End of sourced file'])
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 3 function GlobalFunction[1]',
+ \ '\V 2 <SNR>\.\*_CallAFunction[1]',
+ \ '\V 1 <SNR>\.\*_SourceAnotherFile[1]',
+ \ '\V->0 script ' .. getcwd() .. '/Xtest2.vim',
+ \ '\Vline 15: End of sourced file'],
+ \ #{match: 'pattern'})
+
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest1.vim')
+ call delete('Xtest2.vim')
+endfunc
+
+func Test_debug_backtrace_level()
+ CheckRunVimInTerminal
+ CheckCWD
+ let lines =<< trim END
+ let s:file1_var = 'file1'
+ let g:global_var = 'global'
+
+ func s:File1Func( arg )
+ let s:file1_var .= a:arg
+ let local_var = s:file1_var .. ' test1'
+ let g:global_var .= local_var
+ source Xtest2.vim
+ endfunc
+
+ call s:File1Func( 'arg1' )
+ END
+ call writefile(lines, 'Xtest1.vim')
+
+ let lines =<< trim END
+ let s:file2_var = 'file2'
+
+ func s:File2Func( arg )
+ let s:file2_var .= a:arg
+ let local_var = s:file2_var .. ' test2'
+ let g:global_var .= local_var
+ endfunc
+
+ call s:File2Func( 'arg2' )
+ END
+ call writefile(lines, 'Xtest2.vim')
+
+ let file1 = getcwd() .. '/Xtest1.vim'
+ let file2 = getcwd() .. '/Xtest2.vim'
+
+ " set a breakpoint and source file1.vim
+ let buf = RunVimInTerminal(
+ \ '-c "breakadd file 1 Xtest1.vim" -S Xtest1.vim',
+ \ #{ wait_for_ruler: 0 } )
+
+ call CheckDbgOutput(buf, [
+ \ 'Breakpoint in "' .. file1 .. '" line 1',
+ \ 'Entering Debug mode. Type "cont" to continue.',
+ \ 'command line..script ' .. file1,
+ \ 'line 1: let s:file1_var = ''file1'''
+ \ ])
+
+ " step throught the initial declarations
+ call RunDbgCmd(buf, 'step', [ 'line 2: let g:global_var = ''global''' ] )
+ call RunDbgCmd(buf, 'step', [ 'line 4: func s:File1Func( arg )' ] )
+ call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
+ call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
+ call RunDbgCmd(buf, 'echo global_var', [ 'global' ] )
+
+ " step in to the first function
+ call RunDbgCmd(buf, 'step', [ 'line 11: call s:File1Func( ''arg1'' )' ] )
+ call RunDbgCmd(buf, 'step', [ 'line 1: let s:file1_var .= a:arg' ] )
+ call RunDbgCmd(buf, 'echo a:arg', [ 'arg1' ] )
+ call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
+ call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
+ call RunDbgCmd(buf,
+ \'echo global_var',
+ \[ 'E121: Undefined variable: global_var' ] )
+ call RunDbgCmd(buf,
+ \'echo local_var',
+ \[ 'E121: Undefined variable: local_var' ] )
+ call RunDbgCmd(buf,
+ \'echo l:local_var',
+ \[ 'E121: Undefined variable: l:local_var' ] )
+
+ " backtrace up
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 2 command line',
+ \ '\V 1 script ' .. file1 .. '[11]',
+ \ '\V->0 function <SNR>\.\*_File1Func',
+ \ '\Vline 1: let s:file1_var .= a:arg',
+ \ ],
+ \ #{ match: 'pattern' } )
+ call RunDbgCmd(buf, 'up', [ '>up' ] )
+
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 2 command line',
+ \ '\V->1 script ' .. file1 .. '[11]',
+ \ '\V 0 function <SNR>\.\*_File1Func',
+ \ '\Vline 1: let s:file1_var .= a:arg',
+ \ ],
+ \ #{ match: 'pattern' } )
+
+ " Expression evaluation in the script frame (not the function frame)
+ " FIXME: Unexpected in this scope (a: should not be visibnle)
+ call RunDbgCmd(buf, 'echo a:arg', [ 'arg1' ] )
+ call RunDbgCmd(buf, 'echo s:file1_var', [ 'file1' ] )
+ call RunDbgCmd(buf, 'echo g:global_var', [ 'global' ] )
+ " FIXME: Unexpected in this scope (global should be found)
+ call RunDbgCmd(buf,
+ \'echo global_var',
+ \[ 'E121: Undefined variable: global_var' ] )
+ call RunDbgCmd(buf,
+ \'echo local_var',
+ \[ 'E121: Undefined variable: local_var' ] )
+ call RunDbgCmd(buf,
+ \'echo l:local_var',
+ \[ 'E121: Undefined variable: l:local_var' ] )
+
+
+ " step while backtraced jumps to the latest frame
+ call RunDbgCmd(buf, 'step', [
+ \ 'line 2: let local_var = s:file1_var .. '' test1''' ] )
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 2 command line',
+ \ '\V 1 script ' .. file1 .. '[11]',
+ \ '\V->0 function <SNR>\.\*_File1Func',
+ \ '\Vline 2: let local_var = s:file1_var .. '' test1''',
+ \ ],
+ \ #{ match: 'pattern' } )
+
+ call RunDbgCmd(buf, 'step', [ 'line 3: let g:global_var .= local_var' ] )
+ call RunDbgCmd(buf, 'echo local_var', [ 'file1arg1 test1' ] )
+ call RunDbgCmd(buf, 'echo l:local_var', [ 'file1arg1 test1' ] )
+
+ call RunDbgCmd(buf, 'step', [ 'line 4: source Xtest2.vim' ] )
+ call RunDbgCmd(buf, 'step', [ 'line 1: let s:file2_var = ''file2''' ] )
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 3 command line',
+ \ '\V 2 script ' .. file1 .. '[11]',
+ \ '\V 1 function <SNR>\.\*_File1Func[4]',
+ \ '\V->0 script ' .. file2,
+ \ '\Vline 1: let s:file2_var = ''file2''',
+ \ ],
+ \ #{ match: 'pattern' } )
+
+ " Expression evaluation in the script frame file2 (not the function frame)
+ call RunDbgCmd(buf, 'echo a:arg', [ 'E121: Undefined variable: a:arg' ] )
+ call RunDbgCmd(buf,
+ \ 'echo s:file1_var',
+ \ [ 'E121: Undefined variable: s:file1_var' ] )
+ call RunDbgCmd(buf, 'echo g:global_var', [ 'globalfile1arg1 test1' ] )
+ call RunDbgCmd(buf, 'echo global_var', [ 'globalfile1arg1 test1' ] )
+ call RunDbgCmd(buf,
+ \'echo local_var',
+ \[ 'E121: Undefined variable: local_var' ] )
+ call RunDbgCmd(buf,
+ \'echo l:local_var',
+ \[ 'E121: Undefined variable: l:local_var' ] )
+ call RunDbgCmd(buf,
+ \ 'echo s:file2_var',
+ \ [ 'E121: Undefined variable: s:file2_var' ] )
+
+ call RunDbgCmd(buf, 'step', [ 'line 3: func s:File2Func( arg )' ] )
+ call RunDbgCmd(buf, 'echo s:file2_var', [ 'file2' ] )
+
+ " Up the stack to the other script context
+ call RunDbgCmd(buf, 'up')
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 3 command line',
+ \ '\V 2 script ' .. file1 .. '[11]',
+ \ '\V->1 function <SNR>\.\*_File1Func[4]',
+ \ '\V 0 script ' .. file2,
+ \ '\Vline 3: func s:File2Func( arg )',
+ \ ],
+ \ #{ match: 'pattern' } )
+ " FIXME: Unexpected. Should see the a: and l: dicts from File1Func
+ call RunDbgCmd(buf, 'echo a:arg', [ 'E121: Undefined variable: a:arg' ] )
+ call RunDbgCmd(buf,
+ \ 'echo l:local_var',
+ \ [ 'E121: Undefined variable: l:local_var' ] )
+
+ call RunDbgCmd(buf, 'up')
+ call RunDbgCmd(buf, 'backtrace', [
+ \ '\V>backtrace',
+ \ '\V 3 command line',
+ \ '\V->2 script ' .. file1 .. '[11]',
+ \ '\V 1 function <SNR>\.\*_File1Func[4]',
+ \ '\V 0 script ' .. file2,
+ \ '\Vline 3: func s:File2Func( arg )',
+ \ ],
+ \ #{ match: 'pattern' } )
+
+ " FIXME: Unexpected (wrong script vars are used)
+ call RunDbgCmd(buf,
+ \ 'echo s:file1_var',
+ \ [ 'E121: Undefined variable: s:file1_var' ] )
+ call RunDbgCmd(buf, 'echo s:file2_var', [ 'file2' ] )
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest1.vim')
+ call delete('Xtest2.vim')
+endfunc
+
" Test for setting a breakpoint on a :endif where the :if condition is false
" and then quit the script. This should generate an interrupt.
func Test_breakpt_endif_intr()
diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim
index 09d79979ce..0b41a1127a 100644
--- a/src/nvim/testdir/test_expr.vim
+++ b/src/nvim/testdir/test_expr.vim
@@ -501,3 +501,12 @@ func Test_empty_concatenate()
call assert_equal('b', 'a'[4:0] . 'b')
call assert_equal('b', 'b' . 'a'[4:0])
endfunc
+
+func Test_eval_after_if()
+ let s:val = ''
+ func SetVal(x)
+ let s:val ..= a:x
+ endfunc
+ if 0 | eval SetVal('a') | endif | call SetVal('b')
+ call assert_equal('b', s:val)
+endfunc
diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim
index 1a98dc6451..bd2e673570 100644
--- a/src/nvim/testdir/test_filetype.vim
+++ b/src/nvim/testdir/test_filetype.vim
@@ -275,6 +275,8 @@ let s:filename_checks = {
\ 'lss': ['file.lss'],
\ 'lua': ['file.lua', 'file.rockspec', 'file.nse'],
\ 'lynx': ['lynx.cfg'],
+ \ 'm3build': ['m3makefile', 'm3overrides'],
+ \ 'm3quake': ['file.quake', 'cm3.cfg'],
\ 'm4': ['file.at'],
\ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml'],
\ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases'],
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim
index 555f549743..93f567b3a0 100644
--- a/src/nvim/testdir/test_functions.vim
+++ b/src/nvim/testdir/test_functions.vim
@@ -1071,10 +1071,10 @@ func Test_inputlist()
endfunc
func Test_balloon_show()
- if has('balloon_eval')
- " This won't do anything but must not crash either.
- call balloon_show('hi!')
- endif
+ CheckFeature balloon_eval
+
+ " This won't do anything but must not crash either.
+ call balloon_show('hi!')
endfunc
func Test_shellescape()
@@ -1448,4 +1448,12 @@ func Test_nr2char()
call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"'))
endfunc
+func HasDefault(msg = 'msg')
+ return a:msg
+endfunc
+
+func Test_default_arg_value()
+ call assert_equal('msg', HasDefault())
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim
index 8e2a987e74..affb141a26 100644
--- a/src/nvim/testdir/test_listdict.vim
+++ b/src/nvim/testdir/test_listdict.vim
@@ -506,6 +506,15 @@ func Test_dict_lock_extend()
call assert_equal({'a': 99, 'b': 100}, d)
endfunc
+" Cannot use += with a locked dict
+func Test_dict_lock_operator()
+ unlet! d
+ let d = {}
+ lockvar d
+ call assert_fails("let d += {'k' : 10}", 'E741:')
+ unlockvar d
+endfunc
+
" No remove() of write-protected scope-level variable
func! Tfunc(this_is_a_long_parameter_name)
call assert_fails("call remove(a:, 'this_is_a_long_parameter_name')", 'E742')
@@ -709,6 +718,23 @@ func Test_listdict_extend()
call assert_fails("call extend([1, 2], 1)", 'E712:')
call assert_fails("call extend([1, 2], {})", 'E712:')
+
+ " Extend g: dictionary with an invalid variable name
+ call assert_fails("call extend(g:, {'-!' : 10})", 'E461:')
+
+ " Extend a list with itself.
+ let l = [1, 5, 7]
+ call extend(l, l, 0)
+ call assert_equal([1, 5, 7, 1, 5, 7], l)
+ let l = [1, 5, 7]
+ call extend(l, l, 1)
+ call assert_equal([1, 1, 5, 7, 5, 7], l)
+ let l = [1, 5, 7]
+ call extend(l, l, 2)
+ call assert_equal([1, 5, 1, 5, 7, 7], l)
+ let l = [1, 5, 7]
+ call extend(l, l, 3)
+ call assert_equal([1, 5, 7, 1, 5, 7], l)
endfunc
func s:check_scope_dict(x, fixed)
@@ -782,3 +808,40 @@ func Test_scope_dict()
" Test for v:
call s:check_scope_dict('v', v:true)
endfunc
+
+" Test for a null list
+func Test_null_list()
+ let l = v:_null_list
+ call assert_equal('', join(l))
+ call assert_equal(0, len(l))
+ call assert_equal(1, empty(l))
+ call assert_fails('let s = join([1, 2], [])', 'E730:')
+ call assert_equal([], split(v:_null_string))
+ call assert_equal([], l[:2])
+ call assert_true([] == l)
+ call assert_equal('[]', string(l))
+ " call assert_equal(0, sort(l))
+ " call assert_equal(0, sort(l))
+ " call assert_equal(0, uniq(l))
+ let k = [] + l
+ call assert_equal([], k)
+ let k = l + []
+ call assert_equal([], k)
+ call assert_equal(0, len(copy(l)))
+ call assert_equal(0, count(l, 5))
+ call assert_equal([], deepcopy(l))
+ call assert_equal(5, get(l, 2, 5))
+ call assert_equal(-1, index(l, 2, 5))
+ " call assert_equal(0, insert(l, 2, -1))
+ call assert_equal(0, min(l))
+ call assert_equal(0, max(l))
+ " call assert_equal(0, remove(l, 0, 2))
+ call assert_equal([], repeat(l, 2))
+ " call assert_equal(0, reverse(l))
+ " call assert_equal(0, sort(l))
+ call assert_equal('[]', string(l))
+ " call assert_equal(0, extend(l, l, 0))
+ lockvar l
+ call assert_equal(1, islocked('l'))
+ unlockvar l
+endfunc
diff --git a/src/nvim/testdir/test_menu.vim b/src/nvim/testdir/test_menu.vim
index 055d944b15..de6d4aa359 100644
--- a/src/nvim/testdir/test_menu.vim
+++ b/src/nvim/testdir/test_menu.vim
@@ -11,7 +11,13 @@ func Test_load_menu()
call assert_report('error while loading menus: ' . v:exception)
endtry
call assert_match('browse confirm w', execute(':menu File.Save'))
+
+ let v:errmsg = ''
+ doautocmd LoadBufferMenu VimEnter
+ call assert_equal('', v:errmsg)
+
source $VIMRUNTIME/delmenu.vim
+ call assert_equal('', v:errmsg)
endfunc
func Test_translate_menu()
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index 7aa01c61ca..75d42b986b 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -7,9 +7,8 @@ source check.vim
" See test/functional/legacy/search_spec.lua
func Test_search_cmdline()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
" need to disable char_avail,
" so that expansion of commandline works
call test_override("char_avail", 1)
@@ -206,9 +205,8 @@ endfunc
" See test/functional/legacy/search_spec.lua
func Test_search_cmdline2()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
" need to disable char_avail,
" so that expansion of commandline works
call test_override("char_avail", 1)
@@ -369,9 +367,8 @@ func Incsearch_cleanup()
endfunc
func Test_search_cmdline3()
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
call Cmdline3_prep()
1
" first match
@@ -382,9 +379,8 @@ func Test_search_cmdline3()
endfunc
func Test_search_cmdline3s()
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
call Cmdline3_prep()
1
call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx')
@@ -408,9 +404,8 @@ func Test_search_cmdline3s()
endfunc
func Test_search_cmdline3g()
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
call Cmdline3_prep()
1
call feedkeys(":g/the\<c-l>/d\<cr>", 'tx')
@@ -431,9 +426,8 @@ func Test_search_cmdline3g()
endfunc
func Test_search_cmdline3v()
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
call Cmdline3_prep()
1
call feedkeys(":v/the\<c-l>/d\<cr>", 'tx')
@@ -450,9 +444,8 @@ endfunc
" See test/functional/legacy/search_spec.lua
func Test_search_cmdline4()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
" need to disable char_avail,
" so that expansion of commandline works
call test_override("char_avail", 1)
@@ -484,9 +477,8 @@ func Test_search_cmdline4()
endfunc
func Test_search_cmdline5()
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
" Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work
" regardless char_avail.
new
@@ -503,6 +495,46 @@ func Test_search_cmdline5()
bw!
endfunc
+func Test_search_cmdline6()
+ " Test that consecutive matches
+ " are caught by <c-g>/<c-t>
+ CheckFunction test_override
+ CheckOption incsearch
+
+ " need to disable char_avail,
+ " so that expansion of commandline works
+ call test_override("char_avail", 1)
+ new
+ call setline(1, [' bbvimb', ''])
+ set incsearch
+ " first match
+ norm! gg0
+ call feedkeys("/b\<cr>", 'tx')
+ call assert_equal([0,1,2,0], getpos('.'))
+ " second match
+ norm! gg0
+ call feedkeys("/b\<c-g>\<cr>", 'tx')
+ call assert_equal([0,1,3,0], getpos('.'))
+ " third match
+ norm! gg0
+ call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx')
+ call assert_equal([0,1,7,0], getpos('.'))
+ " first match again
+ norm! gg0
+ call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx')
+ call assert_equal([0,1,2,0], getpos('.'))
+ set nowrapscan
+ " last match
+ norm! gg0
+ call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx')
+ call assert_equal([0,1,7,0], getpos('.'))
+ " clean up
+ set wrapscan&vim
+ set noincsearch
+ call test_override("char_avail", 0)
+ bw!
+endfunc
+
func Test_search_cmdline7()
CheckFunction test_override
" Test that pressing <c-g> in an empty command line
@@ -598,26 +630,226 @@ func Test_search_regexp()
enew!
endfunc
-" Test for search('multi-byte char', 'bce')
-func Test_search_multibyte()
- let save_enc = &encoding
- set encoding=utf8
- enew!
- call append('$', 'A')
- call cursor(2, 1)
- call assert_equal(2, search('A', 'bce', line('.')))
- enew!
- let &encoding = save_enc
+func Test_search_cmdline_incsearch_highlight()
+ CheckFunction test_override
+ CheckOption incsearch
+
+ set incsearch hlsearch
+ " need to disable char_avail,
+ " so that expansion of commandline works
+ call test_override("char_avail", 1)
+ new
+ call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third'])
+
+ 1
+ call feedkeys("/second\<cr>", 'tx')
+ call assert_equal('second', @/)
+ call assert_equal(' 2 the second', getline('.'))
+
+ " Canceling search won't change @/
+ 1
+ let @/ = 'last pattern'
+ call feedkeys("/third\<C-c>", 'tx')
+ call assert_equal('last pattern', @/)
+ call feedkeys("/third\<Esc>", 'tx')
+ call assert_equal('last pattern', @/)
+ call feedkeys("/3\<bs>\<bs>", 'tx')
+ call assert_equal('last pattern', @/)
+ call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx')
+ call assert_equal('last pattern', @/)
+
+ " clean up
+ set noincsearch nohlsearch
+ bw!
endfunc
-" Similar to Test_incsearch_substitute() but with a screendump halfway.
-func Test_incsearch_substitute_dump()
- if !exists('+incsearch')
+func Test_search_cmdline_incsearch_highlight_attr()
+ CheckOption incsearch
+ CheckFeature terminal
+ CheckNotGui
+
+ let h = winheight(0)
+ if h < 3
return
endif
+
+ " Prepare buffer text
+ let lines = ['abb vim vim vi', 'vimvivim']
+ call writefile(lines, 'Xsearch.txt')
+ let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3})
+
+ call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])})
+ " wait for vim to complete initialization
+ call term_wait(buf)
+
+ " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight
+ call term_sendkeys(buf, ":set incsearch hlsearch\<cr>")
+ call term_sendkeys(buf, '/b')
+ call term_wait(buf, 200)
+ let screen_line1 = term_scrape(buf, 1)
+ call assert_true(len(screen_line1) > 2)
+ " a0: attr_normal
+ let a0 = screen_line1[0].attr
+ " a1: attr_incsearch
+ let a1 = screen_line1[1].attr
+ " a2: attr_hlsearch
+ let a2 = screen_line1[2].attr
+ call assert_notequal(a0, a1)
+ call assert_notequal(a0, a2)
+ call assert_notequal(a1, a2)
+ call term_sendkeys(buf, "\<cr>gg0")
+
+ " Test incremental highlight search
+ call term_sendkeys(buf, "/vim")
+ call term_wait(buf, 200)
+ " Buffer:
+ " abb vim vim vi
+ " vimvivim
+ " Search: /vim
+ let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0]
+ let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
+ call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
+ call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
+
+ " Test <C-g>
+ call term_sendkeys(buf, "\<C-g>\<C-g>")
+ call term_wait(buf, 200)
+ let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0]
+ let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2]
+ call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
+ call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
+
+ " Test <C-t>
+ call term_sendkeys(buf, "\<C-t>")
+ call term_wait(buf, 200)
+ let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0]
+ let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
+ call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
+ call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
+
+ " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight)
+ call term_sendkeys(buf, "\<cr>")
+ call term_wait(buf, 200)
+ let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0]
+ let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2]
+ call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
+ call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
+
+ " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight)
+ call term_sendkeys(buf, ":1\<cr>")
+ call term_sendkeys(buf, ":set nohlsearch\<cr>")
+ call term_sendkeys(buf, "/vim")
+ call term_wait(buf, 200)
+ let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0]
+ let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0]
+ call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr'))
+ call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr'))
+ call delete('Xsearch.txt')
+
+ call delete('Xsearch.txt')
+ bwipe!
+endfunc
+
+func Test_incsearch_cmdline_modifier()
+ CheckFunction test_override
+ CheckOption incsearch
+
+ call test_override("char_avail", 1)
+ new
+ call setline(1, ['foo'])
+ set incsearch
+ " Test that error E14 does not occur in parsing command modifier.
+ call feedkeys("V:tab", 'tx')
+
+ call Incsearch_cleanup()
+endfunc
+
+func Test_incsearch_scrolling()
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'
endif
+ call assert_equal(0, &scrolloff)
+ call writefile([
+ \ 'let dots = repeat(".", 120)',
+ \ 'set incsearch cmdheight=2 scrolloff=0',
+ \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])',
+ \ 'normal gg',
+ \ 'redraw',
+ \ ], 'Xscript')
+ let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70})
+ " Need to send one key at a time to force a redraw
+ call term_sendkeys(buf, '/')
+ sleep 100m
+ call term_sendkeys(buf, 't')
+ sleep 100m
+ call term_sendkeys(buf, 'a')
+ sleep 100m
+ call term_sendkeys(buf, 'r')
+ sleep 100m
+ call term_sendkeys(buf, 'g')
+ call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {})
+
+ call term_sendkeys(buf, "\<Esc>")
+ call StopVimInTerminal(buf)
+ call delete('Xscript')
+endfunc
+
+func Test_incsearch_search_dump()
+ CheckOption incsearch
+ CheckScreendump
+
+ call writefile([
+ \ 'set incsearch hlsearch scrolloff=0',
+ \ 'for n in range(1, 8)',
+ \ ' call setline(n, "foo " . n)',
+ \ 'endfor',
+ \ '3',
+ \ ], 'Xis_search_script')
+ let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70})
+ " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
+ " the 'ambiwidth' check.
+ sleep 100m
+
+ " Need to send one key at a time to force a redraw.
+ call term_sendkeys(buf, '/fo')
+ call VerifyScreenDump(buf, 'Test_incsearch_search_01', {})
+ call term_sendkeys(buf, "\<Esc>")
+ sleep 100m
+
+ call term_sendkeys(buf, '/\v')
+ call VerifyScreenDump(buf, 'Test_incsearch_search_02', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xis_search_script')
+endfunc
+
+func Test_incsearch_substitute()
+ CheckFunction test_override
+ CheckOption incsearch
+
+ call test_override("char_avail", 1)
+ new
+ set incsearch
+ for n in range(1, 10)
+ call setline(n, 'foo ' . n)
+ endfor
+ 4
+ call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx')
+ call assert_equal('foo 3', getline(3))
+ call assert_equal('xxx 4', getline(4))
+ call assert_equal('xxx 5', getline(5))
+ call assert_equal('xxx 6', getline(6))
+ call assert_equal('foo 7', getline(7))
+
+ call Incsearch_cleanup()
+endfunc
+
+" Similar to Test_incsearch_substitute() but with a screendump halfway.
+func Test_incsearch_substitute_dump()
+ CheckOption incsearch
+ CheckScreendump
+
call writefile([
\ 'set incsearch hlsearch scrolloff=0',
\ 'for n in range(1, 10)',
@@ -724,12 +956,8 @@ func Test_incsearch_substitute_dump()
endfunc
func Test_incsearch_highlighting()
- if !exists('+incsearch')
- return
- endif
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckOption incsearch
+ CheckScreendump
call writefile([
\ 'set incsearch hlsearch',
@@ -745,16 +973,40 @@ func Test_incsearch_highlighting()
call term_sendkeys(buf, ":%s;ello/the")
call VerifyScreenDump(buf, 'Test_incsearch_substitute_15', {})
call term_sendkeys(buf, "<Esc>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xis_subst_hl_script')
+endfunc
+
+func Test_incsearch_with_change()
+ CheckFeature timers
+ CheckOption incsearch
+ CheckScreendump
+
+ call writefile([
+ \ 'set incsearch hlsearch scrolloff=0',
+ \ 'call setline(1, ["one", "two ------ X", "three"])',
+ \ 'call timer_start(200, { _ -> setline(2, "x")})',
+ \ ], 'Xis_change_script')
+ let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70})
+ " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
+ " the 'ambiwidth' check.
+ sleep 300m
+
+ " Highlight X, it will be deleted by the timer callback.
+ call term_sendkeys(buf, ':%s/X')
+ call VerifyScreenDump(buf, 'Test_incsearch_change_01', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xis_change_script')
endfunc
" Similar to Test_incsearch_substitute_dump() for :sort
func Test_incsearch_sort_dump()
- if !exists('+incsearch')
- return
- endif
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckOption incsearch
+ CheckScreendump
+
call writefile([
\ 'set incsearch hlsearch scrolloff=0',
\ 'call setline(1, ["another one 2", "that one 3", "the one 1"])',
@@ -778,12 +1030,9 @@ endfunc
" Similar to Test_incsearch_substitute_dump() for :vimgrep famiry
func Test_incsearch_vimgrep_dump()
- if !exists('+incsearch')
- return
- endif
- if !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps'
- endif
+ CheckOption incsearch
+ CheckScreendump
+
call writefile([
\ 'set incsearch hlsearch scrolloff=0',
\ 'call setline(1, ["another one 2", "that one 3", "the one 1"])',
@@ -820,9 +1069,8 @@ endfunc
func Test_keep_last_search_pattern()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
new
call setline(1, ['foo', 'foo', 'foo'])
set incsearch
@@ -842,9 +1090,8 @@ endfunc
func Test_word_under_cursor_after_match()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
new
call setline(1, 'foo bar')
set incsearch
@@ -862,9 +1109,8 @@ endfunc
func Test_subst_word_under_cursor()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
new
call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)'])
set incsearch
@@ -878,130 +1124,6 @@ func Test_subst_word_under_cursor()
set noincsearch
endfunc
-func Test_incsearch_with_change()
- if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
- throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
- endif
-
- call writefile([
- \ 'set incsearch hlsearch scrolloff=0',
- \ 'call setline(1, ["one", "two ------ X", "three"])',
- \ 'call timer_start(200, { _ -> setline(2, "x")})',
- \ ], 'Xis_change_script')
- let buf = RunVimInTerminal('-S Xis_change_script', {'rows': 9, 'cols': 70})
- " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
- " the 'ambiwidth' check.
- sleep 300m
-
- " Highlight X, it will be deleted by the timer callback.
- call term_sendkeys(buf, ':%s/X')
- call VerifyScreenDump(buf, 'Test_incsearch_change_01', {})
- call term_sendkeys(buf, "\<Esc>")
-
- call StopVimInTerminal(buf)
- call delete('Xis_change_script')
-endfunc
-
-func Test_incsearch_cmdline_modifier()
- CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
- call test_override("char_avail", 1)
- new
- call setline(1, ['foo'])
- set incsearch
- " Test that error E14 does not occur in parsing command modifier.
- call feedkeys("V:tab", 'tx')
-
- call Incsearch_cleanup()
-endfunc
-
-func Test_incsearch_scrolling()
- if !CanRunVimInTerminal()
- return
- endif
- call assert_equal(0, &scrolloff)
- call writefile([
- \ 'let dots = repeat(".", 120)',
- \ 'set incsearch cmdheight=2 scrolloff=0',
- \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])',
- \ 'normal gg',
- \ 'redraw',
- \ ], 'Xscript')
- let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70})
- " Need to send one key at a time to force a redraw
- call term_sendkeys(buf, '/')
- sleep 100m
- call term_sendkeys(buf, 't')
- sleep 100m
- call term_sendkeys(buf, 'a')
- sleep 100m
- call term_sendkeys(buf, 'r')
- sleep 100m
- call term_sendkeys(buf, 'g')
- call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {})
-
- call term_sendkeys(buf, "\<Esc>")
- call StopVimInTerminal(buf)
- call delete('Xscript')
-endfunc
-
-func Test_incsearch_search_dump()
- if !exists('+incsearch')
- return
- endif
- if !CanRunVimInTerminal()
- return
- endif
- call writefile([
- \ 'set incsearch hlsearch scrolloff=0',
- \ 'for n in range(1, 8)',
- \ ' call setline(n, "foo " . n)',
- \ 'endfor',
- \ '3',
- \ ], 'Xis_search_script')
- let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70})
- " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
- " the 'ambiwidth' check.
- sleep 100m
-
- " Need to send one key at a time to force a redraw.
- call term_sendkeys(buf, '/fo')
- call VerifyScreenDump(buf, 'Test_incsearch_search_01', {})
- call term_sendkeys(buf, "\<Esc>")
- sleep 100m
-
- call term_sendkeys(buf, '/\v')
- call VerifyScreenDump(buf, 'Test_incsearch_search_02', {})
- call term_sendkeys(buf, "\<Esc>")
-
- call StopVimInTerminal(buf)
- call delete('Xis_search_script')
-endfunc
-
-func Test_incsearch_substitute()
- CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
- call test_override("char_avail", 1)
- new
- set incsearch
- for n in range(1, 10)
- call setline(n, 'foo ' . n)
- endfor
- 4
- call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx')
- call assert_equal('foo 3', getline(3))
- call assert_equal('xxx 4', getline(4))
- call assert_equal('xxx 5', getline(5))
- call assert_equal('xxx 6', getline(6))
- call assert_equal('foo 7', getline(7))
-
- call Incsearch_cleanup()
-endfunc
-
func Test_incsearch_substitute_long_line()
CheckFunction test_override
new
@@ -1018,9 +1140,8 @@ func Test_incsearch_substitute_long_line()
endfunc
func Test_search_undefined_behaviour()
- if !has("terminal")
- return
- endif
+ CheckFeature terminal
+
let h = winheight(0)
if h < 3
return
@@ -1036,6 +1157,18 @@ func Test_search_undefined_behaviour2()
call search("\%UC0000000")
endfunc
+" Test for search('multi-byte char', 'bce')
+func Test_search_multibyte()
+ let save_enc = &encoding
+ set encoding=utf8
+ enew!
+ call append('$', 'A')
+ call cursor(2, 1)
+ call assert_equal(2, search('A', 'bce', line('.')))
+ enew!
+ let &encoding = save_enc
+endfunc
+
" This was causing E874. Also causes an invalid read?
func Test_look_behind()
new
@@ -1074,9 +1207,8 @@ func Test_search_Ctrl_L_combining()
" ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE &#x307; /\%u307\Z "\u0307"
" ' ̣' U+0323 Dec:803 COMBINING DOT BELOW &#x323; /\%u323 "\u0323"
" Those should also appear on the commandline
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
call Cmdline3_prep()
1
let bufcontent = ['', 'Miạ̀́̇m']
@@ -1126,9 +1258,8 @@ endfunc
func Test_incsearch_add_char_under_cursor()
CheckFunction test_override
- if !exists('+incsearch')
- return
- endif
+ CheckOption incsearch
+
set incsearch
new
call setline(1, ['find match', 'anything'])
@@ -1213,7 +1344,7 @@ func Test_search_smartcase_utf8()
close!
endfunc
-func Test_zzzz_incsearch_highlighting_newline()
+func Test_incsearch_highlighting_newline()
CheckRunVimInTerminal
CheckOption incsearch
CheckScreendump
@@ -1226,20 +1357,16 @@ func Test_zzzz_incsearch_highlighting_newline()
[CODE]
call writefile(commands, 'Xincsearch_nl')
let buf = RunVimInTerminal('-S Xincsearch_nl', {'rows': 5, 'cols': 10})
- " Need to send one key at a time to force a redraw
call term_sendkeys(buf, '/test')
- sleep 100m
call VerifyScreenDump(buf, 'Test_incsearch_newline1', {})
+ " Need to send one key at a time to force a redraw
call term_sendkeys(buf, '\n')
- sleep 100m
call VerifyScreenDump(buf, 'Test_incsearch_newline2', {})
call term_sendkeys(buf, 'x')
- sleep 100m
call VerifyScreenDump(buf, 'Test_incsearch_newline3', {})
call term_sendkeys(buf, 'x')
call VerifyScreenDump(buf, 'Test_incsearch_newline4', {})
call term_sendkeys(buf, "\<CR>")
- sleep 100m
call VerifyScreenDump(buf, 'Test_incsearch_newline5', {})
call StopVimInTerminal(buf)
diff --git a/src/nvim/testdir/test_shift.vim b/src/nvim/testdir/test_shift.vim
new file mode 100644
index 0000000000..ec357dac88
--- /dev/null
+++ b/src/nvim/testdir/test_shift.vim
@@ -0,0 +1,117 @@
+" Test shifting lines with :> and :<
+
+source check.vim
+
+func Test_ex_shift_right()
+ set shiftwidth=2
+
+ " shift right current line.
+ call setline(1, range(1, 5))
+ 2
+ >
+ 3
+ >>
+ call assert_equal(['1',
+ \ ' 2',
+ \ ' 3',
+ \ '4',
+ \ '5'], getline(1, '$'))
+
+ " shift right with range.
+ call setline(1, range(1, 4))
+ 2,3>>
+ call assert_equal(['1',
+ \ ' 2',
+ \ ' 3',
+ \ '4',
+ \ '5'], getline(1, '$'))
+
+ " shift right with range and count.
+ call setline(1, range(1, 4))
+ 2>3
+ call assert_equal(['1',
+ \ ' 2',
+ \ ' 3',
+ \ ' 4',
+ \ '5'], getline(1, '$'))
+
+ bw!
+ set shiftwidth&
+endfunc
+
+func Test_ex_shift_left()
+ set shiftwidth=2
+
+ call setline(1, range(1, 5))
+ %>>>
+
+ " left shift current line.
+ 2<
+ 3<<
+ 4<<<<<
+ call assert_equal([' 1',
+ \ ' 2',
+ \ ' 3',
+ \ '4',
+ \ ' 5'], getline(1, '$'))
+
+ " shift right with range.
+ call setline(1, range(1, 5))
+ %>>>
+ 2,3<<
+ call assert_equal([' 1',
+ \ ' 2',
+ \ ' 3',
+ \ ' 4',
+ \ ' 5'], getline(1, '$'))
+
+ " shift right with range and count.
+ call setline(1, range(1, 5))
+ %>>>
+ 2<<3
+ call assert_equal([' 1',
+ \ ' 2',
+ \ ' 3',
+ \ ' 4',
+ \ ' 5'], getline(1, '$'))
+
+ bw!
+ set shiftwidth&
+endfunc
+
+func Test_ex_shift_rightleft()
+ CheckFeature rightleft
+
+ set shiftwidth=2 rightleft
+
+ call setline(1, range(1, 4))
+ 2,3<<
+ call assert_equal(['1',
+ \ ' 2',
+ \ ' 3',
+ \ '4'], getline(1, '$'))
+
+ 3,4>
+ call assert_equal(['1',
+ \ ' 2',
+ \ ' 3',
+ \ '4'], getline(1, '$'))
+
+ bw!
+ set rightleft& shiftwidth&
+endfunc
+
+func Test_ex_shift_errors()
+ call assert_fails('><', 'E488:')
+ call assert_fails('<>', 'E488:')
+
+ call assert_fails('>!', 'E477:')
+ call assert_fails('<!', 'E477:')
+
+ " call assert_fails('2,1>', 'E493:')
+ call assert_fails('execute "2,1>"', 'E493:')
+ " call assert_fails('2,1<', 'E493:')
+ call assert_fails('execute "2,1<"', 'E493:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_statusline.vim b/src/nvim/testdir/test_statusline.vim
index 48b7b4f2f1..f5b6446108 100644
--- a/src/nvim/testdir/test_statusline.vim
+++ b/src/nvim/testdir/test_statusline.vim
@@ -444,19 +444,20 @@ func Test_statusline_using_mode()
CheckScreendump
let lines =<< trim END
- set laststatus=2
- let &statusline = '-%{mode()}-'
+ setlocal statusline=-%{mode()}-
+ split
+ setlocal statusline=+%{mode()}+
END
call writefile(lines, 'XTest_statusline')
- let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 5, 'cols': 50})
+ let buf = RunVimInTerminal('-S XTest_statusline', {'rows': 7, '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 term_sendkeys(buf, "close\<CR>")
call StopVimInTerminal(buf)
call delete('XTest_statusline')
endfunc
diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim
index 66cb0bbe22..875e23894f 100644
--- a/src/nvim/testdir/test_syntax.vim
+++ b/src/nvim/testdir/test_syntax.vim
@@ -24,6 +24,32 @@ func GetSyntaxItem(pat)
return c
endfunc
+func AssertHighlightGroups(lnum, startcol, expected, trans = 1, msg = "")
+ " Assert that the characters starting at a given (line, col)
+ " sequentially match the expected highlight groups.
+ " If groups are provided as a string, each character is assumed to be a
+ " group and spaces represent no group, useful for visually describing tests.
+ let l:expectedGroups = type(a:expected) == v:t_string
+ "\ ? a:expected->split('\zs')->map({_, v -> trim(v)})
+ \ ? map(split(a:expected, '\zs'), {_, v -> trim(v)})
+ \ : a:expected
+ let l:errors = 0
+ " let l:msg = (a:msg->empty() ? "" : a:msg .. ": ")
+ let l:msg = (empty(a:msg) ? "" : a:msg .. ": ")
+ \ .. "Wrong highlight group at " .. a:lnum .. ","
+
+ " for l:i in range(a:startcol, a:startcol + l:expectedGroups->len() - 1)
+ " let l:errors += synID(a:lnum, l:i, a:trans)
+ " \ ->synIDattr("name")
+ " \ ->assert_equal(l:expectedGroups[l:i - 1],
+ for l:i in range(a:startcol, a:startcol + len(l:expectedGroups) - 1)
+ let l:errors +=
+ \ assert_equal(synIDattr(synID(a:lnum, l:i, a:trans), "name"),
+ \ l:expectedGroups[l:i - 1],
+ \ l:msg .. l:i)
+ endfor
+endfunc
+
func Test_syn_iskeyword()
new
call setline(1, [
@@ -707,3 +733,22 @@ func Test_syntax_foldlevel()
quit!
endfunc
+
+func Test_syn_include_contains_TOP()
+ let l:case = "TOP in included syntax means its group list name"
+ new
+ syntax include @INCLUDED syntax/c.vim
+ syntax region FencedCodeBlockC start=/```c/ end=/```/ contains=@INCLUDED
+
+ call setline(1, ['```c', '#if 0', 'int', '#else', 'int', '#endif', '```' ])
+ let l:expected = ["cCppOutIf2"]
+ eval AssertHighlightGroups(3, 1, l:expected, 1)
+ " cCppOutElse has contains=TOP
+ let l:expected = ["cType"]
+ eval AssertHighlightGroups(5, 1, l:expected, 1, l:case)
+ syntax clear
+ bw!
+endfunc
+
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim
index e8161f8fcb..c51fb3a759 100644
--- a/src/nvim/testdir/test_utf8.vim
+++ b/src/nvim/testdir/test_utf8.vim
@@ -84,7 +84,7 @@ func Test_list2str_str2list_utf8()
" Null list is the same as an empty list
call assert_equal('', list2str([]))
- " call assert_equal('', list2str(test_null_list()))
+ call assert_equal('', list2str(v:_null_list))
endfunc
func Test_list2str_str2list_latin1()
diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim
index 56031662a3..c62c01d5f3 100644
--- a/src/nvim/testdir/test_writefile.vim
+++ b/src/nvim/testdir/test_writefile.vim
@@ -1,5 +1,8 @@
" Tests for the writefile() function and some :write commands.
+source check.vim
+source term_util.vim
+
func Test_writefile()
let f = tempname()
call writefile(["over","written"], f, "b")
@@ -179,3 +182,120 @@ func Test_writefile_sync_arg()
call writefile(['two'], 'Xtest', 'S')
call delete('Xtest')
endfunc
+
+" Tests for reading and writing files with conversion for Win32.
+func Test_write_file_encoding()
+ CheckMSWindows
+ throw 'skipped: Nvim does not support :w ++enc=cp1251'
+ let save_encoding = &encoding
+ let save_fileencodings = &fileencodings
+ set encoding& fileencodings&
+ let text =<< trim END
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ END
+ call writefile(text, 'Xfile')
+ edit Xfile
+
+ " write tests:
+ " combine three values for 'encoding' with three values for 'fileencoding'
+ " also write files for read tests
+ call cursor(1, 1)
+ set encoding=utf-8
+ .w! ++enc=utf-8 Xtest
+ .w ++enc=cp1251 >> Xtest
+ .w ++enc=cp866 >> Xtest
+ .w! ++enc=utf-8 Xutf8
+ let expected =<< trim END
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ call cursor(2, 1)
+ set encoding=cp1251
+ .w! ++enc=utf-8 Xtest
+ .w ++enc=cp1251 >> Xtest
+ .w ++enc=cp866 >> Xtest
+ .w! ++enc=cp1251 Xcp1251
+ let expected =<< trim END
+ 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ call cursor(3, 1)
+ set encoding=cp866
+ .w! ++enc=utf-8 Xtest
+ .w ++enc=cp1251 >> Xtest
+ .w ++enc=cp866 >> Xtest
+ .w! ++enc=cp866 Xcp866
+ let expected =<< trim END
+ 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ " read three 'fileencoding's with utf-8 'encoding'
+ set encoding=utf-8 fencs=utf-8,cp1251
+ e Xutf8
+ .w! ++enc=utf-8 Xtest
+ e Xcp1251
+ .w ++enc=utf-8 >> Xtest
+ set fencs=utf-8,cp866
+ e Xcp866
+ .w ++enc=utf-8 >> Xtest
+ let expected =<< trim END
+ 1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ 3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ " read three 'fileencoding's with cp1251 'encoding'
+ set encoding=utf-8 fencs=utf-8,cp1251
+ e Xutf8
+ .w! ++enc=cp1251 Xtest
+ e Xcp1251
+ .w ++enc=cp1251 >> Xtest
+ set fencs=utf-8,cp866
+ e Xcp866
+ .w ++enc=cp1251 >> Xtest
+ let expected =<< trim END
+ 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ " read three 'fileencoding's with cp866 'encoding'
+ set encoding=cp866 fencs=utf-8,cp1251
+ e Xutf8
+ .w! ++enc=cp866 Xtest
+ e Xcp1251
+ .w ++enc=cp866 >> Xtest
+ set fencs=utf-8,cp866
+ e Xcp866
+ .w ++enc=cp866 >> Xtest
+ let expected =<< trim END
+ 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
+ END
+ call assert_equal(expected, readfile('Xtest'))
+
+ call delete('Xfile')
+ call delete('Xtest')
+ call delete('Xutf8')
+ call delete('Xcp1251')
+ call delete('Xcp866')
+ let &encoding = save_encoding
+ let &fileencodings = save_fileencodings
+ %bw!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab