goto theend; /* type error; errmsg already given */
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;
" test ability to call sort() from a compare function
call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1'))
endfunc
+
+func Test_sort_default()
+ " docs say omitted, empty or zero argument sorts on string representation.
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"]))
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], ''))
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], 0))
+ call assert_fails('call sort([3.3, 1, "2"], 3)', "E474")
+endfunc