summaryrefslogtreecommitdiff
path: root/src/testdir/test_sort.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-22 22:51:33 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-22 22:51:33 +0100
commit0b962473ddc7cee3cb45253dea273573bcca9bf9 (patch)
tree14441eede7c95f476abae9f4524eca4aef6c99a8 /src/testdir/test_sort.vim
parentbd73ae1bc63a3b0187ffe7fc8f0caee5a4eb66fa (diff)
downloadvim-git-0b962473ddc7cee3cb45253dea273573bcca9bf9.tar.gz
patch 7.4.1394v7.4.1394
Problem: Can't sort inside a sort function. Solution: Use a struct to store the sort parameters. (Jacob Niehus)
Diffstat (limited to 'src/testdir/test_sort.vim')
-rw-r--r--src/testdir/test_sort.vim14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim
index 32ad7f8ad..68021f6de 100644
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -1,5 +1,14 @@
" Test sort()
+:func Compare1(a, b) abort
+ call sort(range(3), 'Compare2')
+ return a:a ># a:b
+:endfunc
+
+:func Compare2(a, b) abort
+ return a:a <# a:b
+:endfunc
+
func Test_sort_strings()
" numbers compared as strings
call assert_equal([1, 2, 3], sort([3, 2, 1]))
@@ -21,3 +30,8 @@ endfunc
func Test_sort_float()
call assert_equal([0.28, 3, 13.5], sort([13.5, 0.28, 3], 'f'))
endfunc
+
+func Test_sort_nested()
+ " test ability to call sort() from a compare function
+ call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1'))
+endfunc