1
0
forked from aniani/vim

patch 8.2.1946: sort() with NULL string not tested

Problem:    sort() with NULL string not tested.
Solution:   Add a test.  use v:collate. (Dominique Pellé, closes #7247)
This commit is contained in:
Bram Moolenaar
2020-11-03 18:51:54 +01:00
parent 0d90e728fe
commit 35efa22ff2
2 changed files with 10 additions and 5 deletions

View File

@@ -24,21 +24,25 @@ func Test_sort_strings()
" This does not appear to work correctly on Mac. " This does not appear to work correctly on Mac.
if !has('mac') if !has('mac')
let lc = execute('language collate')
" With the following locales, the accentuated letters are ordered " With the following locales, the accentuated letters are ordered
" similarly to the non-accentuated letters... " similarly to the non-accentuated letters...
if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"' if v:collate =~? '^\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8$'
call assert_equal(['a', 'A', 'ä', 'Ä', 'o', 'O', 'ô', 'Ô', 'œ', 'œ', 'p', 'P'], call assert_equal(['a', 'A', 'ä', 'Ä', 'o', 'O', 'ô', 'Ô', 'œ', 'œ', 'p', 'P'],
\ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l'))
" ... whereas with a Swedish locale, the accentuated letters are ordered " ... whereas with a Swedish locale, the accentuated letters are ordered
" after Z. " after Z.
elseif lc =~? '"sv.*utf-\?8"' elseif v:collate =~? '^sv.*utf-\?8$'
call assert_equal(['a', 'A', 'o', 'O', 'p', 'P', 'ä', 'Ä', 'œ', 'œ', 'ô', 'Ô'], call assert_equal(['a', 'A', 'o', 'O', 'p', 'P', 'ä', 'Ä', 'œ', 'œ', 'ô', 'Ô'],
\ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l'))
endif endif
endif endif
endfunc endfunc
func Test_sort_null_string()
" null strings are sorted as empty strings.
call assert_equal(['', 'a', 'b'], sort(['b', test_null_string(), 'a']))
endfunc
func Test_sort_numeric() func Test_sort_numeric()
call assert_equal([1, 2, 3], sort([3, 2, 1], 'n')) call assert_equal([1, 2, 3], sort([3, 2, 1], 'n'))
call assert_equal([3, 13, 28], sort([13, 28, 3], 'n')) call assert_equal([3, 13, 28], sort([13, 28, 3], 'n'))
@@ -1229,8 +1233,7 @@ func Test_sort_cmd()
" With the following locales, the accentuated letters are ordered " With the following locales, the accentuated letters are ordered
" similarly to the non-accentuated letters. " similarly to the non-accentuated letters.
" This does not appear to work on Mac " This does not appear to work on Mac
let lc = execute('language collate') if v:collate =~? '^\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8$' && !has('mac')
if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"' && !has('mac')
let tests += [ let tests += [
\ { \ {
\ 'name' : 'sort with locale', \ 'name' : 'sort with locale',

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1946,
/**/ /**/
1945, 1945,
/**/ /**/