1
0
forked from aniani/vim

patch 7.4.951

Problem:    Sorting number strings does not work as expected. (Luc Hermitte)
Solution:   Add the 'N" argument to sort()
This commit is contained in:
Bram Moolenaar
2015-12-03 16:33:12 +01:00
parent 4649ded287
commit b00da1d6d1
6 changed files with 52 additions and 1 deletions

19
src/testdir/test_sort.vim Normal file
View File

@@ -0,0 +1,19 @@
" Test sort()
func Test_sort_strings()
" numbers compared as strings
call assert_equal([1, 2, 3], sort([3, 2, 1]))
call assert_equal([13, 28, 3], sort([3, 28, 13]))
endfunc
func Test_sort_numeric()
call assert_equal([1, 2, 3], sort([3, 2, 1], 'n'))
call assert_equal([3, 13, 28], sort([13, 28, 3], 'n'))
" strings are not sorted
call assert_equal(['13', '28', '3'], sort(['13', '28', '3'], 'n'))
endfunc
func Test_sort_numbers()
call assert_equal([3, 13, 28], sort([13, 28, 3], 'N'))
call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N'))
endfunc