Mercurial > vim
annotate src/testdir/test_sort.vim @ 8461:988ddc5742f5 v7.4.1521
commit https://github.com/vim/vim/commit/8322e1f06e8fa39a6bb790a7d8d7db5d7aff3366
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 8 19:20:04 2016 +0100
patch 7.4.1521
Problem: File permission test fails on MS-Windows.
Solution: Expect a different permission.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 08 Mar 2016 19:30:05 +0100 |
parents | 2c40b40c3220 |
children | 881564b89f9b |
rev | line source |
---|---|
7291
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test sort() |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
8202
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
3 :func Compare1(a, b) abort |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
4 call sort(range(3), 'Compare2') |
8208
c11aaa31a0ed
commit https://github.com/vim/vim/commit/0bb6108eb4e1ecaed437bc507f514f5da7816d9e
Christian Brabandt <cb@256bit.org>
parents:
8202
diff
changeset
|
5 return a:a - a:b |
8202
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
6 :endfunc |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
7 |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
8 :func Compare2(a, b) abort |
8208
c11aaa31a0ed
commit https://github.com/vim/vim/commit/0bb6108eb4e1ecaed437bc507f514f5da7816d9e
Christian Brabandt <cb@256bit.org>
parents:
8202
diff
changeset
|
9 return a:a - a:b |
8202
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
10 :endfunc |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
11 |
7291
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 func Test_sort_strings() |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 " numbers compared as strings |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 call assert_equal([1, 2, 3], sort([3, 2, 1])) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 call assert_equal([13, 28, 3], sort([3, 28, 13])) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 endfunc |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 func Test_sort_numeric() |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 call assert_equal([1, 2, 3], sort([3, 2, 1], 'n')) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 call assert_equal([3, 13, 28], sort([13, 28, 3], 'n')) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 " strings are not sorted |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 call assert_equal(['13', '28', '3'], sort(['13', '28', '3'], 'n')) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 endfunc |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 func Test_sort_numbers() |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 call assert_equal([3, 13, 28], sort([13, 28, 3], 'N')) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N')) |
6ffc75d807bd
commit https://github.com/vim/vim/commit/b00da1d6d1655cb6e415f84ecc3be5ff3b790811
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 endfunc |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7291
diff
changeset
|
29 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7291
diff
changeset
|
30 func Test_sort_float() |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7291
diff
changeset
|
31 call assert_equal([0.28, 3, 13.5], sort([13.5, 0.28, 3], 'f')) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7291
diff
changeset
|
32 endfunc |
8202
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
33 |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
34 func Test_sort_nested() |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
35 " test ability to call sort() from a compare function |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
36 call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1')) |
c16aa03d8db5
commit https://github.com/vim/vim/commit/0b962473ddc7cee3cb45253dea273573bcca9bf9
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
37 endfunc |
8344
2aa24f702b8d
commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
Christian Brabandt <cb@256bit.org>
parents:
8208
diff
changeset
|
38 |
2aa24f702b8d
commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
Christian Brabandt <cb@256bit.org>
parents:
8208
diff
changeset
|
39 func Test_sort_default() |
2aa24f702b8d
commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
Christian Brabandt <cb@256bit.org>
parents:
8208
diff
changeset
|
40 " docs say omitted, empty or zero argument sorts on string representation. |
8352
2c40b40c3220
commit https://github.com/vim/vim/commit/51d1d536802b5d8232d47e56f165ba8a009529b5
Christian Brabandt <cb@256bit.org>
parents:
8344
diff
changeset
|
41 call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"])) |
2c40b40c3220
commit https://github.com/vim/vim/commit/51d1d536802b5d8232d47e56f165ba8a009529b5
Christian Brabandt <cb@256bit.org>
parents:
8344
diff
changeset
|
42 call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], '')) |
2c40b40c3220
commit https://github.com/vim/vim/commit/51d1d536802b5d8232d47e56f165ba8a009529b5
Christian Brabandt <cb@256bit.org>
parents:
8344
diff
changeset
|
43 call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 0)) |
2c40b40c3220
commit https://github.com/vim/vim/commit/51d1d536802b5d8232d47e56f165ba8a009529b5
Christian Brabandt <cb@256bit.org>
parents:
8344
diff
changeset
|
44 call assert_equal(['2', 'A', 'a', 'AA', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 1)) |
8344
2aa24f702b8d
commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
Christian Brabandt <cb@256bit.org>
parents:
8208
diff
changeset
|
45 call assert_fails('call sort([3.3, 1, "2"], 3)', "E474") |
2aa24f702b8d
commit https://github.com/vim/vim/commit/5131c144feb046c5e2b72e6c172159d80ce06b3c
Christian Brabandt <cb@256bit.org>
parents:
8208
diff
changeset
|
46 endfunc |