Mercurial > vim
annotate src/testdir/test_filter_map.vim @ 26234:92bad8cd95d5 v8.2.3648
patch 8.2.3648: "verbose pwd" is incorrect after dropping files on Vim
Commit: https://github.com/vim/vim/commit/4671e88d7d3ed12206d9cdd8892fe3b2cbc0d6ab
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 22 17:21:48 2021 +0000
patch 8.2.3648: "verbose pwd" is incorrect after dropping files on Vim
Problem: "verbose pwd" is incorrect after dropping files on Vim.
Solution: Set the chdir reason to "drop".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 22 Nov 2021 18:30:05 +0100 |
parents | 77f181975381 |
children | 06693d1afc48 |
rev | line source |
---|---|
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test filter() and map() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 " list with expression string |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 func Test_filter_map_list_expr_string() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 " filter() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1')) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1')) |
9442
4fe3772969cf
commit https://github.com/vim/vim/commit/a06ec8f345eabb66e5b7d7c0192cfebdde63115d
Christian Brabandt <cb@256bit.org>
parents:
9416
diff
changeset
|
8 call assert_equal([], filter([1, 2, 3, 4], 0)) |
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 " map() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], 'v:val * 2')) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], 'v:key * 2')) |
9442
4fe3772969cf
commit https://github.com/vim/vim/commit/a06ec8f345eabb66e5b7d7c0192cfebdde63115d
Christian Brabandt <cb@256bit.org>
parents:
9416
diff
changeset
|
13 call assert_equal([9, 9, 9, 9], map([1, 2, 3, 4], 9)) |
21620
46956b6811a1
patch 8.2.1360: stray error for white space after expression
Bram Moolenaar <Bram@vim.org>
parents:
20550
diff
changeset
|
14 call assert_equal([7, 7, 7], map([1, 2, 3], ' 7 ')) |
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 " dict with expression string |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 func Test_filter_map_dict_expr_string() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 let dict = {"foo": 1, "bar": 2, "baz": 3} |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 " filter() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), 'v:val > 1')) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), 'v:key > "bar"')) |
9442
4fe3772969cf
commit https://github.com/vim/vim/commit/a06ec8f345eabb66e5b7d7c0192cfebdde63115d
Christian Brabandt <cb@256bit.org>
parents:
9416
diff
changeset
|
24 call assert_equal({}, filter(copy(dict), 0)) |
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 " map() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), 'v:val * 2')) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), 'v:key[0]')) |
9442
4fe3772969cf
commit https://github.com/vim/vim/commit/a06ec8f345eabb66e5b7d7c0192cfebdde63115d
Christian Brabandt <cb@256bit.org>
parents:
9416
diff
changeset
|
29 call assert_equal({"foo": 9, "bar": 9, "baz": 9}, map(copy(dict), 9)) |
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 " list with funcref |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 func Test_filter_map_list_expr_funcref() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 " filter() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 func! s:filter1(index, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 return a:val > 1 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 call assert_equal([2, 3, 4], filter([1, 2, 3, 4], function('s:filter1'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 func! s:filter2(index, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 return a:index > 1 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 call assert_equal([3, 4], filter([1, 2, 3, 4], function('s:filter2'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 " map() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 func! s:filter3(index, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 return a:val * 2 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], function('s:filter3'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 func! s:filter4(index, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 return a:index * 2 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], function('s:filter4'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 |
17936
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
57 func Test_filter_map_nested() |
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
58 let x = {"x":10} |
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
59 let r = map(range(2), 'filter(copy(x), "1")') |
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
60 call assert_equal([x, x], r) |
17944
745c02392844
patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents:
17936
diff
changeset
|
61 |
745c02392844
patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents:
17936
diff
changeset
|
62 let r = map(copy(x), 'filter(copy(x), "1")') |
745c02392844
patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents:
17936
diff
changeset
|
63 call assert_equal({"x": x}, r) |
17936
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
64 endfunc |
7f3283683d97
patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents:
15478
diff
changeset
|
65 |
9416
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 " dict with funcref |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 func Test_filter_map_dict_expr_funcref() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 let dict = {"foo": 1, "bar": 2, "baz": 3} |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
70 " filter() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
71 func! s:filter1(key, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 return a:val > 1 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), function('s:filter1'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 func! s:filter2(key, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 return a:key > "bar" |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), function('s:filter2'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
81 " map() |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 func! s:filter3(key, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 return a:val * 2 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
85 call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), function('s:filter3'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 func! s:filter4(key, val) abort |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 return a:key[0] |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 endfunc |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), function('s:filter4'))) |
cbf052ccb120
commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
91 endfunc |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
9442
diff
changeset
|
92 |
20109
e82996ad131f
patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
19233
diff
changeset
|
93 func Test_map_filter_fails() |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
9442
diff
changeset
|
94 call assert_fails('call map([1], "42 +")', 'E15:') |
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
9442
diff
changeset
|
95 call assert_fails('call filter([1], "42 +")', 'E15:') |
20550
09143ab0fbbd
patch 8.2.0829: filter() may give misleading error message
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
96 call assert_fails("let l = map('abc', '\"> \" . v:val')", 'E896:') |
09143ab0fbbd
patch 8.2.0829: filter() may give misleading error message
Bram Moolenaar <Bram@vim.org>
parents:
20158
diff
changeset
|
97 call assert_fails("let l = filter('abc', '\"> \" . v:val')", 'E896:') |
20109
e82996ad131f
patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
19233
diff
changeset
|
98 call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:') |
e82996ad131f
patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
19233
diff
changeset
|
99 call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:') |
20128
0b35a7ffceb2
patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents:
20109
diff
changeset
|
100 call assert_fails("let l = filter([1, 2], {})", 'E731:') |
22608
f140b9036aa5
patch 8.2.1852: map() returing zero for NULL list is unexpected
Bram Moolenaar <Bram@vim.org>
parents:
21620
diff
changeset
|
101 call assert_equal(test_null_list(), filter(test_null_list(), 0)) |
f140b9036aa5
patch 8.2.1852: map() returing zero for NULL list is unexpected
Bram Moolenaar <Bram@vim.org>
parents:
21620
diff
changeset
|
102 call assert_equal(test_null_dict(), filter(test_null_dict(), 0)) |
f140b9036aa5
patch 8.2.1852: map() returing zero for NULL list is unexpected
Bram Moolenaar <Bram@vim.org>
parents:
21620
diff
changeset
|
103 call assert_equal(test_null_list(), map(test_null_list(), '"> " .. v:val')) |
f140b9036aa5
patch 8.2.1852: map() returing zero for NULL list is unexpected
Bram Moolenaar <Bram@vim.org>
parents:
21620
diff
changeset
|
104 call assert_equal(test_null_dict(), map(test_null_dict(), '"> " .. v:val')) |
20156
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
105 call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_function())) |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
106 call assert_fails("let l = filter([1, 2], function('min'))", 'E118:') |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
107 call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_partial())) |
49694eceaa55
patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents:
20128
diff
changeset
|
108 call assert_fails("let l = filter([1, 2], {a, b, c -> 1})", 'E119:') |
15478
051937ebaf22
patch 8.1.0747: map() with a bad expression doesn't give an error
Bram Moolenaar <Bram@vim.org>
parents:
9442
diff
changeset
|
109 endfunc |
19233
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
110 |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
111 func Test_map_and_modify() |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
112 let l = ["abc"] |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
113 " cannot change the list halfway a map() |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
114 call assert_fails('call map(l, "remove(l, 0)[0]")', 'E741:') |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
115 |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
116 let d = #{a: 1, b: 2, c: 3} |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
117 call assert_fails('call map(d, "remove(d, v:key)[0]")', 'E741:') |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
118 call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:') |
04c164c971a3
patch 8.2.0175: crash when removing list element in map()
Bram Moolenaar <Bram@vim.org>
parents:
17944
diff
changeset
|
119 endfunc |
20109
e82996ad131f
patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
19233
diff
changeset
|
120 |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
121 func Test_mapnew_dict() |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
122 let din = #{one: 1, two: 2} |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
123 let dout = mapnew(din, {k, v -> string(v)}) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
124 call assert_equal(#{one: 1, two: 2}, din) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
125 call assert_equal(#{one: '1', two: '2'}, dout) |
23058
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
126 |
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
127 const dconst = #{one: 1, two: 2, three: 3} |
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
128 call assert_equal(#{one: 2, two: 3, three: 4}, mapnew(dconst, {_, v -> v + 1})) |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
129 endfunc |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
130 |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
131 func Test_mapnew_list() |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
132 let lin = [1, 2, 3] |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
133 let lout = mapnew(lin, {k, v -> string(v)}) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
134 call assert_equal([1, 2, 3], lin) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
135 call assert_equal(['1', '2', '3'], lout) |
23058
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
136 |
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
137 const lconst = [1, 2, 3] |
77f181975381
patch 8.2.2075: error for const argument to mapnew()
Bram Moolenaar <Bram@vim.org>
parents:
22844
diff
changeset
|
138 call assert_equal([2, 3, 4], mapnew(lconst, {_, v -> v + 1})) |
22844
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
139 endfunc |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
140 |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
141 func Test_mapnew_blob() |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
142 let bin = 0z123456 |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
143 let bout = mapnew(bin, {k, v -> k == 1 ? 0x99 : v}) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
144 call assert_equal(0z123456, bin) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
145 call assert_equal(0z129956, bout) |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
146 endfunc |
36fc73078bce
patch 8.2.1969: Vim9: map() may change the list or dict item type
Bram Moolenaar <Bram@vim.org>
parents:
22608
diff
changeset
|
147 |
20109
e82996ad131f
patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
19233
diff
changeset
|
148 " vim: shiftwidth=2 sts=2 expandtab |