diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-16 20:03:43 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-16 20:03:43 +0200 |
commit | 84cf6bd81bec93b49166cd48fccc7087fdbaa6fc (patch) | |
tree | 63d744fbf9ac7db5246a60b48aa0396aaaa22c18 /src/testdir/test_functions.vim | |
parent | 9af78769eeae0318e07aa8b6af4d6e2244481ca7 (diff) | |
download | vim-git-84cf6bd81bec93b49166cd48fccc7087fdbaa6fc.tar.gz |
patch 8.2.0988: getting directory contents is always case sortedv8.2.0988
Problem: Getting directory contents is always case sorted.
Solution: Add sort options and v:collate. (Christian Brabandt, closes #6229)
Diffstat (limited to 'src/testdir/test_functions.vim')
-rw-r--r-- | src/testdir/test_functions.vim | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index d9f8b9ac0..cefeaf7f9 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -1937,6 +1937,85 @@ func Test_readdirex() eval 'Xdir'->delete('rf') endfunc +func Test_readdirex_sort() + CheckUnix + " Skip tests on Mac OS X and Cygwin (does not allow several files with different casing) + if has("osxdarwin") || has("osx") || has("macunix") || has("win32unix") + throw 'Skipped: Test_readdirex_sort on systems that do not allow this using the default filesystem' + endif + let _collate = v:collate + call mkdir('Xdir2') + call writefile(['1'], 'Xdir2/README.txt') + call writefile(['2'], 'Xdir2/Readme.txt') + call writefile(['3'], 'Xdir2/readme.txt') + + " 1) default + let files = readdirex('Xdir2')->map({-> v:val.name}) + let default = copy(files) + call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort using default') + + " 2) no sorting + let files = readdirex('Xdir2', 1, #{sort: 'none'})->map({-> v:val.name}) + let unsorted = copy(files) + call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], sort(files), 'unsorted') + + " 3) sort by case (same as default) + let files = readdirex('Xdir2', 1, #{sort: 'case'})->map({-> v:val.name}) + call assert_equal(default, files, 'sort by case') + + " 4) sort by ignoring case + let files = readdirex('Xdir2', 1, #{sort: 'icase'})->map({-> v:val.name}) + call assert_equal(unsorted->sort('i'), files, 'sort by icase') + + " 5) Default Collation + let collate = v:collate + lang collate C + let files = readdirex('Xdir2', 1, #{sort: 'collate'})->map({-> v:val.name}) + call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort by C collation') + + " 6) Collation de_DE + " Switch locale, this may not work on the CI system, if the locale isn't + " available + try + lang collate de_DE + let files = readdirex('Xdir2', 1, #{sort: 'collate'})->map({-> v:val.name}) + call assert_equal(['readme.txt', 'Readme.txt', 'README.txt'], files, 'sort by de_DE collation') + catch + throw 'Skipped: de_DE collation is not available' + + finally + exe 'lang collate' collate + eval 'Xdir2'->delete('rf') + endtry +endfunc + +func Test_readdir_sort() + " some more cases for testing sorting for readdirex + let dir = 'Xdir3' + call mkdir(dir) + call writefile(['1'], dir .. '/README.txt') + call writefile(['2'], dir .. '/Readm.txt') + call writefile(['3'], dir .. '/read.txt') + call writefile(['4'], dir .. '/Z.txt') + call writefile(['5'], dir .. '/a.txt') + call writefile(['6'], dir .. '/b.txt') + + " 1) default + let files = readdir(dir) + let default = copy(files) + call assert_equal(default->sort(), files, 'sort using default') + + " 2) sort by case (same as default) + let files = readdir(dir, '1', #{sort: 'case'}) + call assert_equal(default, files, 'sort using default') + + " 3) sort by ignoring case + let files = readdir(dir, '1', #{sort: 'icase'}) + call assert_equal(default->sort('i'), files, 'sort by ignoring case') + + eval dir->delete('rf') +endfunc + func Test_delete_rf() call mkdir('Xdir') call writefile([], 'Xdir/foo.txt') |