aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJurica Bradaric <jbradaric@gmail.com>2016-05-14 22:41:18 +0200
committerJurica Bradaric <jbradaric@gmail.com>2016-06-09 20:34:43 +0200
commitb2d15fbebc1470057da3c814f0e1539b021da63e (patch)
tree727c101325318adf2eb1887dce494d1b1d5ea4fd
parent82da7eed343151e11bb281ea37136812a0a93712 (diff)
downloadrneovim-b2d15fbebc1470057da3c814f0e1539b021da63e.tar.gz
rneovim-b2d15fbebc1470057da3c814f0e1539b021da63e.tar.bz2
rneovim-b2d15fbebc1470057da3c814f0e1539b021da63e.zip
vim-patch:7.4.1464
Problem: When the argument of sort() is zero or empty it fails. Solution: Make zero work as documented. (suggested by Yasuhiro Matsumoto) https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
-rw-r--r--src/nvim/eval.c10
-rw-r--r--src/nvim/version.c2
-rw-r--r--test/functional/legacy/function_sort_spec.lua10
3 files changed, 19 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 4d96e79f71..9c2a704367 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -15305,11 +15305,17 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
}
if (i == 1) {
info.item_compare_ic = true;
- } else {
+ } else if (argvars[1].v_type != VAR_NUMBER) {
info.item_compare_func = get_tv_string(&argvars[1]);
+ } else if (i != 0) {
+ EMSG(_(e_invarg));
+ goto theend;
}
if (info.item_compare_func != NULL) {
- if (STRCMP(info.item_compare_func, "n") == 0) {
+ if (*info.item_compare_func == NUL) {
+ // empty string means default sort
+ info.item_compare_func = NULL;
+ } else if (STRCMP(info.item_compare_func, "n") == 0) {
info.item_compare_func = NULL;
info.item_compare_numeric = true;
} else if (STRCMP(info.item_compare_func, "N") == 0) {
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 6479690a53..5352a5bc5f 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -229,7 +229,7 @@ static int included_patches[] = {
// 1467 NA
// 1466 NA
// 1465 NA
- // 1464,
+ 1464,
// 1463 NA
// 1462 NA
// 1461 NA
diff --git a/test/functional/legacy/function_sort_spec.lua b/test/functional/legacy/function_sort_spec.lua
index 3347dd9699..fb4a5b7713 100644
--- a/test/functional/legacy/function_sort_spec.lua
+++ b/test/functional/legacy/function_sort_spec.lua
@@ -3,6 +3,8 @@ local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local execute = helpers.execute
+local exc_exec = helpers.exc_exec
+local neq = helpers.neq
describe('sort', function()
before_each(clear)
@@ -39,4 +41,12 @@ describe('sort', function()
execute('endfunc')
eq({1, 3, 5}, eval("sort([3, 1, 5], 'Compare1')"))
end)
+
+ it('default sort', function()
+ -- docs say omitted, empty or zero argument sorts on string representation
+ eq({'2', 1, 3.3}, eval('sort([3.3, 1, "2"])'))
+ eq({'2', 1, 3.3}, eval([[sort([3.3, 1, "2"], '')]]))
+ eq({'2', 1, 3.3}, eval('sort([3.3, 1, "2"], 0)'))
+ neq(exc_exec('call sort([3.3, 1, "2"], 3)'):find('E474:'), nil)
+ end)
end)