aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-08-20 22:25:57 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:07:43 +0300
commit54bd2e8b731376b29c150f909c6b50103bfbb91a (patch)
treea1862a81cd83c25792d890bd4072944c8805c281
parente18a5783080f7c94f408ec5f53dedffdb69789e1 (diff)
downloadrneovim-54bd2e8b731376b29c150f909c6b50103bfbb91a.tar.gz
rneovim-54bd2e8b731376b29c150f909c6b50103bfbb91a.tar.bz2
rneovim-54bd2e8b731376b29c150f909c6b50103bfbb91a.zip
eval: Make setmatches() return -1 in case of some failures
-rw-r--r--src/nvim/eval.c17
-rw-r--r--test/functional/eval/match_functions_spec.lua7
-rw-r--r--test/functional/legacy/063_match_and_matchadd_spec.lua5
3 files changed, 21 insertions, 8 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 5015deead7..7ec1fda0a8 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -14680,6 +14680,7 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
clear_matches(curwin);
li = l->lv_first;
+ bool match_add_failed = false;
while (li != NULL) {
int i = 0;
@@ -14728,17 +14729,23 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
&conceal_di->di_tv)
: NULL);
if (i == 0) {
- match_add(curwin, group,
- tv_dict_get_string(d, "pattern", false),
- priority, id, NULL, conceal);
+ if (match_add(curwin, group,
+ tv_dict_get_string(d, "pattern", false),
+ priority, id, NULL, conceal) != id) {
+ match_add_failed = true;
+ }
} else {
- match_add(curwin, group, NULL, priority, id, s, conceal);
+ if (match_add(curwin, group, NULL, priority, id, s, conceal) != id) {
+ match_add_failed = true;
+ }
tv_list_unref(s);
s = NULL;
}
li = li->li_next;
}
- rettv->vval.v_number = 0;
+ if (!match_add_failed) {
+ rettv->vval.v_number = 0;
+ }
}
}
diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua
index df91e41475..f6bad59c66 100644
--- a/test/functional/eval/match_functions_spec.lua
+++ b/test/functional/eval/match_functions_spec.lua
@@ -36,4 +36,11 @@ describe('setmatches()', function()
conceal='5',
}}, funcs.getmatches())
end)
+
+ it('fails with -1 if highlight group is not defined', function()
+ eq(-1, funcs.setmatches({{group=1, pattern=2, id=3, priority=4}}))
+ eq({}, funcs.getmatches())
+ eq(-1, funcs.setmatches({{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}}))
+ eq({}, funcs.getmatches())
+ end)
end)
diff --git a/test/functional/legacy/063_match_and_matchadd_spec.lua b/test/functional/legacy/063_match_and_matchadd_spec.lua
index 298e0a31ea..5818bb6b3a 100644
--- a/test/functional/legacy/063_match_and_matchadd_spec.lua
+++ b/test/functional/legacy/063_match_and_matchadd_spec.lua
@@ -97,11 +97,10 @@ describe('063: Test for ":match", "matchadd()" and related functions', function(
-- Check that "setmatches()" will not add two matches with the same ID. The
-- expected behaviour (for now) is to add the first match but not the
- -- second and to return 0 (even though it is a matter of debate whether
- -- this can be considered successful behaviour).
+ -- second and to return -1.
execute("let r1 = setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}])")
feed("<cr>")
- eq(0, eval("r1"))
+ eq(-1, eval("r1"))
eq({{group = 'MyGroup1', pattern = 'TODO', priority = 10, id = 1}}, eval('getmatches()'))
-- Check that "setmatches()" returns 0 if successful and otherwise -1.