annotate src/testdir/test_filter_map.vim @ 27457:4c16acb2525f v8.2.4257

patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 21:45:34 2022 +0000 patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Problem: Vim9: finding global function without g: prefix but not finding global variable is inconsistent. Solution: Require using g: for a global function. Change the vim9.vim script into a Vim9 script with exports. Fix that import in legacy script does not work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:00:05 +0100
parents 6f43253463cc
children 5848a0867b26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26907
diff changeset
3 import './vim9.vim' as v9
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
4
9416
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " list with expression string
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Test_filter_map_list_expr_string()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " filter()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 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
9 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
10 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
11
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " map()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 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
14 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
15 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
16 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
17 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 " dict with expression string
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 func Test_filter_map_dict_expr_string()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 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
22
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 " filter()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 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
25 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
26 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
27
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 " map()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 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
30 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
31 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
32 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 " list with funcref
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 func Test_filter_map_list_expr_funcref()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " filter()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 func! s:filter1(index, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 return a:val > 1
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 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
41
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 func! s:filter2(index, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 return a:index > 1
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 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
46
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 " map()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 func! s:filter3(index, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 return a:val * 2
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 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
52
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 func! s:filter4(index, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 return a:index * 2
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 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
57 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
17936
7f3283683d97 patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
59 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
60 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
61 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
62 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
63
745c02392844 patch 8.1.1968: crash when using nested map()
Bram Moolenaar <Bram@vim.org>
parents: 17936
diff changeset
64 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
65 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
66 endfunc
7f3283683d97 patch 8.1.1964: crash when using nested map() and filter()
Bram Moolenaar <Bram@vim.org>
parents: 15478
diff changeset
67
9416
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 " dict with funcref
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 func Test_filter_map_dict_expr_funcref()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 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
71
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 " filter()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 func! s:filter1(key, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 return a:val > 1
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 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
77
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 func! s:filter2(key, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 return a:key > "bar"
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 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
82
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 " map()
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 func! s:filter3(key, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 return a:val * 2
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 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
88
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 func! s:filter4(key, val) abort
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 return a:key[0]
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endfunc
cbf052ccb120 commit https://github.com/vim/vim/commit/b33c7eb5b813cb631b2b0ca5c4029e1788a09bde
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 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
93 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
94
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19233
diff changeset
95 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
96 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
97 call assert_fails('call filter([1], "42 +")', 'E15:')
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
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
148 " Test for using map(), filter() and mapnew() with a string
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
149 func Test_filter_map_string()
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
150 " filter()
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
151 let lines =<< trim END
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
152 VAR s = "abc"
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
153 call filter(s, '"b" != v:val')
26907
6f43253463cc patch 8.2.3982: some lines of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
154 call assert_equal('abc', s)
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
155 call assert_equal('ac', filter('abc', '"b" != v:val'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
156 call assert_equal('あいうえお', filter('あxいxうxえxお', '"x" != v:val'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
157 call assert_equal('あa😊💕💕b💕', filter('あxax😊x💕💕b💕x', '"x" != v:val'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
158 call assert_equal('xxxx', filter('あxax😊x💕💕b💕x', '"x" == v:val'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
159 VAR t = "%),:;>?]}’”†‡…‰,‱‼⁇⁈⁉℃℉,、。〉》」,』】〕〗〙〛,!),.:,;?,]}"
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
160 VAR u = "%):;>?]}’”†‡…‰‱‼⁇⁈⁉℃℉、。〉》」』】〕〗〙〛!),.:;?]}"
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
161 call assert_equal(u, filter(t, '"," != v:val'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
162 call assert_equal('', filter('abc', '0'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
163 call assert_equal('ac', filter('abc', LSTART i, x LMIDDLE "b" != x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
164 call assert_equal('あいうえお', filter('あxいxうxえxお', LSTART i, x LMIDDLE "x" != x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
165 call assert_equal('', filter('abc', LSTART i, x LMIDDLE v:false LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
166 call assert_equal('', filter('', "v:val == 'a'"))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
167 call assert_equal('', filter(test_null_string(), "v:val == 'a'"))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
168 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26907
diff changeset
169 call v9.CheckLegacyAndVim9Success(lines)
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
170
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
171 " map()
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
172 let lines =<< trim END
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
173 VAR s = "abc"
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
174 call map(s, 'nr2char(char2nr(v:val) + 2)')
26907
6f43253463cc patch 8.2.3982: some lines of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
175 call assert_equal('abc', s)
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
176 call assert_equal('cde', map('abc', 'nr2char(char2nr(v:val) + 2)'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
177 call assert_equal('[あ][i][う][え][お]', map('あiうえお', '"[" .. v:val .. "]"'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
178 call assert_equal('[あ][a][😊][,][‱][‼][⁇][⁈][⁉][💕][b][💕][c][💕]', map('あa😊,‱‼⁇⁈⁉💕b💕c💕', '"[" .. v:val .. "]"'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
179 call assert_equal('', map('abc', '""'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
180 call assert_equal('cde', map('abc', LSTART i, x LMIDDLE nr2char(char2nr(x) + 2) LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
181 call assert_equal('[あ][i][う][え][お]', map('あiうえお', LSTART i, x LMIDDLE '[' .. x .. ']' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
182 call assert_equal('', map('abc', LSTART i, x LMIDDLE '' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
183 call assert_equal('', map('', "v:val == 'a'"))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
184 call assert_equal('', map(test_null_string(), "v:val == 'a'"))
26684
2126feddeda6 patch 8.2.3871: list.c contains code for dict and blob
Bram Moolenaar <Bram@vim.org>
parents: 26585
diff changeset
185 call assert_fails('echo map("abc", "10")', 'E928:')
26759
31c23760d590 patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents: 26684
diff changeset
186 call assert_fails('echo map("abc", "a10")', 'E121:')
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
187 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26907
diff changeset
188 call v9.CheckLegacyAndVim9Success(lines)
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
189
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
190 " mapnew()
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
191 let lines =<< trim END
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
192 VAR s = "abc"
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
193 call mapnew(s, 'nr2char(char2nr(v:val) + 2)')
26907
6f43253463cc patch 8.2.3982: some lines of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
194 call assert_equal('abc', s)
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
195 call assert_equal('cde', mapnew('abc', 'nr2char(char2nr(v:val) + 2)'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
196 call assert_equal('[あ][i][う][え][お]', mapnew('あiうえお', '"[" .. v:val .. "]"'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
197 call assert_equal('[あ][a][😊][,][‱][‼][⁇][⁈][⁉][💕][b][💕][c][💕]', mapnew('あa😊,‱‼⁇⁈⁉💕b💕c💕', '"[" .. v:val .. "]"'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
198 call assert_equal('', mapnew('abc', '""'))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
199 call assert_equal('cde', mapnew('abc', LSTART i, x LMIDDLE nr2char(char2nr(x) + 2) LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
200 call assert_equal('[あ][i][う][え][お]', mapnew('あiうえお', LSTART i, x LMIDDLE '[' .. x .. ']' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
201 call assert_equal('', mapnew('abc', LSTART i, x LMIDDLE '' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
202 call assert_equal('', mapnew('', "v:val == 'a'"))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
203 call assert_equal('', mapnew(test_null_string(), "v:val == 'a'"))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
204 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26907
diff changeset
205 call v9.CheckLegacyAndVim9Success(lines)
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
206
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
207 let lines =<< trim END
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
208 #" map() and filter()
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
209 call assert_equal('[あ][⁈][a][😊][⁉][💕][💕][b][💕]', map(filter('あx⁈ax😊x⁉💕💕b💕x', '"x" != v:val'), '"[" .. v:val .. "]"'))
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
210
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
211 #" patterns-composing(\Z)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
212 call assert_equal('ॠॠ', filter('ऊॠॡ,ऊॠॡ', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0x0960) LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
213 call assert_equal('àà', filter('càt,càt', LSTART i, x LMIDDLE x =~ '\Za' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
214 call assert_equal('ÅÅ', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xc5) LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
215 call assert_equal('öö', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xf6) LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
216 call assert_equal('ऊ@ॡ', map('ऊॠॡ', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0x0960) ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
217 call assert_equal('c@t', map('càt', LSTART i, x LMIDDLE x =~ '\Za' ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
218 call assert_equal('@ström', map('Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xc5) ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
219 call assert_equal('Åstr@m', map('Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xf6) ? '@' : x LEND))
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
220
26585
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
221 #" patterns-composing(\%C)
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
222 call assert_equal('ॠॠ', filter('ऊॠॡ,ऊॠॡ', LSTART i, x LMIDDLE x =~ nr2char(0x0960) .. '\%C' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
223 call assert_equal('àà', filter('càt,càt', LSTART i, x LMIDDLE x =~ 'a' .. '\%C' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
224 call assert_equal('ÅÅ', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ nr2char(0xc5) .. '\%C' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
225 call assert_equal('öö', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ nr2char(0xf6) .. '\%C' LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
226 call assert_equal('ऊ@ॡ', map('ऊॠॡ', LSTART i, x LMIDDLE x =~ nr2char(0x0960) .. '\%C' ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
227 call assert_equal('c@t', map('càt', LSTART i, x LMIDDLE x =~ 'a' .. '\%C' ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
228 call assert_equal('@ström', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xc5) .. '\%C' ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
229 call assert_equal('Åstr@m', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xf6) .. '\%C' ? '@' : x LEND))
0d2a709e2ff0 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 26578
diff changeset
230 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26907
diff changeset
231 call v9.CheckLegacyAndVim9Success(lines)
26578
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
232 endfunc
06693d1afc48 patch 8.2.3818: cannot filter or map characters in a string
Bram Moolenaar <Bram@vim.org>
parents: 23058
diff changeset
233
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19233
diff changeset
234 " vim: shiftwidth=2 sts=2 expandtab