summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_sort.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-01 13:57:44 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-01 13:57:44 +0100
commit55e29611d20bca14fa5efc61385bc8a6b7acd9e2 (patch)
treeab93029caf0fe68c139d7b7d02c67fe11abf02b7 /src/testdir/test_sort.vim
parent963734e316bd17dd7290abcac28b875435d06381 (diff)
patch 8.2.1933: cannot sort using locale orderingv8.2.1933
Problem: Cannot sort using locale ordering. Solution: Add a flag for :sort and sort() to use the locale. (Dominique Pellé, closes #7237)
Diffstat (limited to 'src/testdir/test_sort.vim')
-rw-r--r--src/testdir/test_sort.vim70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim
index d76132ee57..93190a940c 100644
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -15,6 +15,25 @@ 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]))
+
+ call assert_equal(['A', 'O', 'P', 'a', 'o', 'p', 'Ä', 'Ô', 'ä', 'ô', 'œ', 'œ'],
+ \ sort(['A', 'O', 'P', 'a', 'o', 'p', 'Ä', 'Ô', 'ä', 'ô', 'œ', 'œ']))
+
+ call assert_equal(['A', 'a', 'o', 'O', 'p', 'P', 'Ä', 'Ô', 'ä', 'ô', 'œ', 'œ'],
+ \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'i'))
+
+ let lc = execute('language collate')
+ " With the following locales, the accentuated letters are ordered
+ " similarly to the non-accentuated letters...
+ if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"'
+ call assert_equal(['a', 'A', 'ä', 'Ä', 'o', 'O', 'ô', 'Ô', 'œ', 'œ', 'p', 'P'],
+ \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l'))
+ " ... whereas with a Swedish locale, the accentuated letters are ordered
+ " after Z.
+ elseif lc =~? '"sv.*utf-\?8"'
+ call assert_equal(['a', 'A', 'o', 'O', 'p', 'P', 'ä', 'Ä', 'œ', 'œ', 'ô', 'Ô'],
+ \ sort(['A', 'a', 'o', 'O', 'œ', 'œ', 'p', 'P', 'Ä', 'ä', 'ô', 'Ô'], 'l'))
+ endif
endfunc
func Test_sort_numeric()
@@ -1204,6 +1223,57 @@ func Test_sort_cmd()
\ },
\ ]
+ " With the following locales, the accentuated letters are ordered
+ " similarly to the non-accentuated letters...
+ let lc = execute('language collate')
+ if lc =~? '"\(en\|es\|de\|fr\|it\|nl\).*\.utf-\?8"'
+ let tests += [
+ \ {
+ \ 'name' : 'sort with locale',
+ \ 'cmd' : '%sort l',
+ \ 'input' : [
+ \ 'A',
+ \ 'E',
+ \ 'O',
+ \ 'À',
+ \ 'È',
+ \ 'É',
+ \ 'Ô',
+ \ 'Œ',
+ \ 'Z',
+ \ 'a',
+ \ 'e',
+ \ 'o',
+ \ 'à',
+ \ 'è',
+ \ 'é',
+ \ 'ô',
+ \ 'œ',
+ \ 'z'
+ \ ],
+ \ 'expected' : [
+ \ 'a',
+ \ 'A',
+ \ 'à',
+ \ 'À',
+ \ 'e',
+ \ 'E',
+ \ 'é',
+ \ 'É',
+ \ 'è',
+ \ 'È',
+ \ 'o',
+ \ 'O',
+ \ 'ô',
+ \ 'Ô',
+ \ 'œ',
+ \ 'Œ',
+ \ 'z',
+ \ 'Z'
+ \ ]
+ \ },
+ \ ]
+ endif
if has('float')
let tests += [
\ {