Mercurial > vim
comparison src/testdir/test_sort.vim @ 22796:d3694e3685d3 v8.2.1946
patch 8.2.1946: sort() with NULL string not tested
Commit: https://github.com/vim/vim/commit/35efa22ff2b98126363098db9304796b5624f97f
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 3 18:51:54 2020 +0100
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 https://github.com/vim/vim/issues/7247)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 03 Nov 2020 19:00:03 +0100 |
parents | 8561ae67f85d |
children | b545334ae654 |
comparison
equal
deleted
inserted
replaced
22795:9dbb9450336f | 22796:d3694e3685d3 |
---|---|
22 call assert_equal(['A', 'a', 'o', 'O', 'p', 'P', 'Ä', 'Ô', 'ä', 'ô', 'œ', 'œ'], | 22 call assert_equal(['A', 'a', 'o', 'O', 'p', 'P', 'Ä', 'Ô', 'ä', 'ô', 'œ', 'œ'], |
23 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'i')) | 23 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'i')) |
24 | 24 |
25 " This does not appear to work correctly on Mac. | 25 " This does not appear to work correctly on Mac. |
26 if !has('mac') | 26 if !has('mac') |
27 let lc = execute('language collate') | |
28 " With the following locales, the accentuated letters are ordered | 27 " With the following locales, the accentuated letters are ordered |
29 " similarly to the non-accentuated letters... | 28 " similarly to the non-accentuated letters... |
30 if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"' | 29 if v:collate =~? '^\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8$' |
31 call assert_equal(['a', 'A', 'ä', 'Ä', 'o', 'O', 'ô', 'Ô', 'œ', 'œ', 'p', 'P'], | 30 call assert_equal(['a', 'A', 'ä', 'Ä', 'o', 'O', 'ô', 'Ô', 'œ', 'œ', 'p', 'P'], |
32 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) | 31 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) |
33 " ... whereas with a Swedish locale, the accentuated letters are ordered | 32 " ... whereas with a Swedish locale, the accentuated letters are ordered |
34 " after Z. | 33 " after Z. |
35 elseif lc =~? '"sv.*utf-\?8"' | 34 elseif v:collate =~? '^sv.*utf-\?8$' |
36 call assert_equal(['a', 'A', 'o', 'O', 'p', 'P', 'ä', 'Ä', 'œ', 'œ', 'ô', 'Ô'], | 35 call assert_equal(['a', 'A', 'o', 'O', 'p', 'P', 'ä', 'Ä', 'œ', 'œ', 'ô', 'Ô'], |
37 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) | 36 \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l')) |
38 endif | 37 endif |
39 endif | 38 endif |
39 endfunc | |
40 | |
41 func Test_sort_null_string() | |
42 " null strings are sorted as empty strings. | |
43 call assert_equal(['', 'a', 'b'], sort(['b', test_null_string(), 'a'])) | |
40 endfunc | 44 endfunc |
41 | 45 |
42 func Test_sort_numeric() | 46 func Test_sort_numeric() |
43 call assert_equal([1, 2, 3], sort([3, 2, 1], 'n')) | 47 call assert_equal([1, 2, 3], sort([3, 2, 1], 'n')) |
44 call assert_equal([3, 13, 28], sort([13, 28, 3], 'n')) | 48 call assert_equal([3, 13, 28], sort([13, 28, 3], 'n')) |
1227 \ ] | 1231 \ ] |
1228 | 1232 |
1229 " With the following locales, the accentuated letters are ordered | 1233 " With the following locales, the accentuated letters are ordered |
1230 " similarly to the non-accentuated letters. | 1234 " similarly to the non-accentuated letters. |
1231 " This does not appear to work on Mac | 1235 " This does not appear to work on Mac |
1232 let lc = execute('language collate') | 1236 if v:collate =~? '^\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8$' && !has('mac') |
1233 if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"' && !has('mac') | |
1234 let tests += [ | 1237 let tests += [ |
1235 \ { | 1238 \ { |
1236 \ 'name' : 'sort with locale', | 1239 \ 'name' : 'sort with locale', |
1237 \ 'cmd' : '%sort l', | 1240 \ 'cmd' : '%sort l', |
1238 \ 'input' : [ | 1241 \ 'input' : [ |