annotate src/testdir/test_listdict.vim @ 15949:d8ab4fa99341 v8.1.0980

patch 8.1.0980: extend() insufficiently tested commit https://github.com/vim/vim/commit/58d63a0a2364e1f06a80550f9f5038145b339171 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 25 05:56:31 2019 +0100 patch 8.1.0980: extend() insufficiently tested Problem: extend() insufficiently tested. Solution: Add more tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/4040)
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 Feb 2019 06:00:04 +0100
parents dff66c4670b1
children 6604ecb7a615
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for the List and Dict types
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func TearDown()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Run garbage collection after every test
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 call test_garbagecollect_now()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " Tests for List type
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " List creation
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 func Test_list_create()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " Creating List directly with different types
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal("[1, 'as''d', [1, 2, function('strlen')], {'a': 1}]", string(l))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal({'a' : 1}, l[-1])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_equal(1, l[-4])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let x = 10
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let x = l[-5]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_match('E684:', v:exception)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call assert_equal(10, x)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 " List slices
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 func Test_list_slice()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[:])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_equal(['as''d', [1, 2, function('strlen')], {'a': 1}], l[1:])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call assert_equal([], l[8:-1])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " List identity
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 func Test_list_identity()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let ll = l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let lx = copy(l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call assert_true(l == ll)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call assert_false(l isnot ll)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call assert_true(l is ll)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call assert_true(l == lx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_false(l is lx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_true(l isnot lx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 " removing items with :unlet
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 func Test_list_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 unlet l[2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call assert_equal([1, 'as''d', {'a': 1}], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let l = range(8)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 unlet l[:3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 unlet l[1:]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 call assert_equal([4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " removing items out of range: silently skip items that don't exist
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call assert_fails('unlet l[2:1]', 'E684')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 unlet l[2:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call assert_equal([0, 1, 3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 unlet l[2:3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call assert_equal([0, 1], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 unlet l[2:4]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_equal([0, 1], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 unlet l[2:5]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 call assert_equal([0, 1], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 call assert_fails('unlet l[-1:2]', 'E684')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 unlet l[-2:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 call assert_equal([0, 1, 3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 unlet l[-3:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 call assert_equal([0, 3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 unlet l[-4:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 call assert_equal([3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 unlet l[-5:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 call assert_equal([3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 unlet l[-6:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 call assert_equal([3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 " assignment to a list
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 func Test_list_assign()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 let l = [0, 1, 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 let [va, vb] = l[2:3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 call assert_equal([2, 3], [va, vb])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 call assert_fails('let [va, vb] = l', 'E687')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call assert_fails('let [va, vb] = l[1:1]', 'E688')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 " test for range assign
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 func Test_list_range_assign()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 let l = [0]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 let l[:] = [1, 2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 call assert_equal([1, 2], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
109 " Test removing items in list
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
110 func Test_list_func_remove()
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
111 " Test removing 1 element
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
112 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
113 call assert_equal(1, remove(l, 0))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
114 call assert_equal([2, 3, 4], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
115
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
116 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
117 call assert_equal(2, remove(l, 1))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
118 call assert_equal([1, 3, 4], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
119
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
120 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
121 call assert_equal(4, remove(l, -1))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
122 call assert_equal([1, 2, 3], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
123
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
124 " Test removing range of element(s)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
125 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
126 call assert_equal([3], remove(l, 2, 2))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
127 call assert_equal([1, 2, 4], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
128
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
129 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
130 call assert_equal([2, 3], remove(l, 1, 2))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
131 call assert_equal([1, 4], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
132
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
133 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
134 call assert_equal([2, 3], remove(l, -3, -2))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
135 call assert_equal([1, 4], l)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
136
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
137 " Test invalid cases
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
138 let l = [1, 2, 3, 4]
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
139 call assert_fails("call remove(l, 5)", 'E684:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
140 call assert_fails("call remove(l, 1, 5)", 'E684:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
141 call assert_fails("call remove(l, 3, 2)", 'E16:')
15571
4af72c724093 patch 8.1.0793: incorrect error messages for functions that take a Blob
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
142 call assert_fails("call remove(1, 0)", 'E896:')
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
143 call assert_fails("call remove(l, l)", 'E745:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
144 endfunc
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
145
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 " Tests for Dictionary type
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 func Test_dict()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 " Creating Dictionary directly with different types
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 call assert_equal('asd', d.1)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 call assert_equal(['-1', '1', 'b'], sort(keys(d)))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 call assert_equal(['asd', [1, 2, function('strlen')], {'a': 1}], values(d))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 let v = []
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 for [key, val] in items(d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 call extend(v, [key, val])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 unlet key val
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 call assert_equal(['1','asd','b',[1, 2, function('strlen')],'-1',{'a': 1}], v)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 call extend(d, {3:33, 1:99})
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 call extend(d, {'b':'bbb', 'c':'ccc'}, "keep")
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 call filter(d, 'v:key =~ ''[ac391]''')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 " Dictionary identity
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 func Test_dict_identity()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 let dd = d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 let dx = copy(d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 call assert_true(d == dd)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 call assert_false(d isnot dd)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 call assert_true(d is dd)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 call assert_true(d == dx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 call assert_false(d is dx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 call assert_true(d isnot dx)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 " removing items with :unlet
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 func Test_dict_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 let d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 unlet d.b
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 unlet d[-1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 call assert_equal({'1': 99, '3': 33}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 " manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 func Test_dict_big()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 let d = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 for i in range(1500)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 let d[i] = 3000 - i
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 call assert_equal([3000, 2900, 2001, 1600, 1501], [d[0], d[100], d[999], d[1400], d[1499]])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 let str = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 let n = d[1500]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 let str=substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 call assert_equal('Vim(let):E716: 1500', str)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 " lookup each items
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 for i in range(1500)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 call assert_equal(3000 - i, d[i])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 let i += 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 " delete even items
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 while i >= 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 let i -= 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 unlet d[i]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 endwhile
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 call assert_equal('NONE', get(d, 1500 - 100, 'NONE'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 call assert_equal(2999, d[1])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 " delete odd items, checking value, one intentionally wrong
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221 let d[33] = 999
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222 let i = 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
223 while i < 1500
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 if i != 33
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
225 call assert_equal(3000 - i, d[i])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 else
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 call assert_equal(999, d[i])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 unlet d[i]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 let i += 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231 endwhile
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232 call assert_equal({}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 unlet d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 " Dictionary function
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 func Test_dict_func()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 let d = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 func d.func(a) dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 return a:a . len(self.data)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 let d.data = [1,2,3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 call assert_equal('len: 3', d.func('len: '))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 let x = d.func('again: ')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 call assert_equal('again: 3', x)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 let Fn = d.func
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 call assert_equal('xxx3', Fn('xxx'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250 " Function in script-local List or Dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251 func Test_script_local_dict_func()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 let g:dict = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 function g:dict.func() dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 return 'g:dict.func' . self.foo[1] . self.foo[0]('asdf')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 let g:dict.foo = ['-', 2, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 call insert(g:dict.foo, function('strlen'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 call assert_equal('g:dict.func-4', g:dict.func())
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259 unlet g:dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
260 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
261
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
262 " Test removing items in la dictionary
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
263 func Test_dict_func_remove()
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
264 let d = {1:'a', 2:'b', 3:'c'}
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
265 call assert_equal('b', remove(d, 2))
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
266 call assert_equal({1:'a', 3:'c'}, d)
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
267
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
268 call assert_fails("call remove(d, 1, 2)", 'E118:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
269 call assert_fails("call remove(d, 'a')", 'E716:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
270 call assert_fails("call remove(d, [])", 'E730:')
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
271 endfunc
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
272
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 " Nasty: remove func from Dict that's being called (works)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 func Test_dict_func_remove_in_use()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275 let d = {1:1}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276 func d.func(a)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
277 return "a:" . a:a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
278 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
279 let expected = 'a:' . string(get(d, 'func'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 call assert_equal(expected, d.func(string(remove(d, 'func'))))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
282
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
283 " Nasty: deepcopy() dict that refers to itself (fails when noref used)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
284 func Test_dict_deepcopy()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
285 let d = {1:1, 2:2}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
286 let l = [4, d, 6]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
287 let d[3] = l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
288 let dc = deepcopy(d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
289 call assert_fails('call deepcopy(d, 1)', 'E698')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
290 let l2 = [0, l, l, 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
291 let l[1] = l2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
292 let l3 = deepcopy(l2)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
293 call assert_true(l3[1] is l3[2])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
294 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
295
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
296 " Locked variables
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 func Test_list_locked_var()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
298 let expected = [
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
299 \ [['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
300 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
301 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 \ [['1000-000', 'ppppppF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 \ [['1100-100', 'ppFppFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 \ [['1110-110', 'pFFpFFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 \ ['0010-010', 'pFppFpp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
310 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 \ [['1111-111', 'FFFFFFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312 \ ['0011-011', 'FFpFFpp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 \ ['0000-000', 'ppppppp']]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 \ ]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 for depth in range(5)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 for u in range(3)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 unlet! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
318 let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 exe "lockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320 if u == 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 exe "unlockvar l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 elseif u == 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 exe "unlockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
325 let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 call assert_equal(expected[depth][u][0], ps)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 let ps = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 let l[1][1][0] = 99
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
330 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
333 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
335 let l[1][1] = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
340 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 let l[1] = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
342 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
344 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 let l[2]['6'][7] = 99
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 let l[2][6] = {99: 99}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 let l[2] = {99: 99}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
361 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
362 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
364 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365 let l = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
366 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
367 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
369 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
370 call assert_equal(expected[depth][u][1], ps)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
371 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
372 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
373 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 " Unletting locked variables
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 func Test_list_locked_var_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
377 let expected = [
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378 \ [['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
379 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
381 \ [['1000-000', 'ppFppFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 \ [['1100-100', 'pFFpFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
386 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387 \ [['1110-110', 'FFFFFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 \ ['0010-010', 'FppFppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
389 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 \ [['1111-111', 'FFFFFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
391 \ ['0011-011', 'FppFppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
392 \ ['0000-000', 'ppppppp']]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 \ ]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
394
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
395 for depth in range(5)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
396 for u in range(3)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
397 unlet! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
399 exe "lockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
400 if u == 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 exe "unlockvar l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 elseif u == 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 exe "unlockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 call assert_equal(expected[depth][u][0], ps)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
407 let ps = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409 unlet l[2]['6'][7]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
411 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
413 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
414 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415 unlet l[2][6]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
416 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
417 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
418 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
419 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
421 unlet l[2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
422 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427 unlet l[1][1][0]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
429 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
430 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433 unlet l[1][1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 unlet l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
440 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
445 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 call assert_equal(expected[depth][u][1], ps)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 " Locked variables and :unlet or list / dict functions
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 " No :unlet after lock on dict:
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 func Test_dict_lock_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
459 unlet! d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 let d = {'a': 99, 'b': 100}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
461 lockvar 1 d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
462 call assert_fails('unlet d.a', 'E741')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
463 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465 " unlet after lock on dict item
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 func Test_dict_item_lock_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 unlet! d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 let d = {'a': 99, 'b': 100}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 lockvar d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470 unlet d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 call assert_equal({'b' : 100}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
473
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 " filter() after lock on dict item
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 func Test_dict_lock_filter()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 unlet! d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 let d = {'a': 99, 'b': 100}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
478 lockvar d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 call filter(d, 'v:key != "a"')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 call assert_equal({'b' : 100}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 " map() after lock on dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484 func Test_dict_lock_map()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 unlet! d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 let d = {'a': 99, 'b': 100}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 lockvar 1 d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 call map(d, 'v:val + 200')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 call assert_equal({'a' : 299, 'b' : 300}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 " No extend() after lock on dict item
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 func Test_dict_lock_extend()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 unlet! d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 let d = {'a': 99, 'b': 100}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 lockvar d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 call assert_fails("call extend(d, {'a' : 123})", 'E741')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498 call assert_equal({'a': 99, 'b': 100}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 " No remove() of write-protected scope-level variable
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
502 func Tfunc1(this_is_a_long_parameter_name)
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
503 call assert_fails("call remove(a:, 'this_is_a_long_parameter_name')", 'E742')
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
504 endfunc
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 func Test_dict_scope_var_remove()
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
506 call Tfunc1('testval')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 " No extend() of write-protected scope-level variable
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
510 func Test_dict_scope_var_extend()
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
511 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
512 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
513
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
514 func Tfunc2(this_is_a_long_parameter_name)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 endfunc
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
517 func Test_dict_scope_var_extend_overwrite()
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
518 call Tfunc2('testval')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 " No :unlet of variable in locked scope
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 func Test_lock_var_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 let b:testvar = 123
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 lockvar 1 b:
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 call assert_fails('unlet b:testvar', 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526 unlockvar 1 b:
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 unlet! b:testvar
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
530 " No :let += of locked list variable
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 func Test_let_lock_list()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 let l = ['a', 'b', 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 lockvar 1 l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 call assert_fails("let l += ['x']", 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 call assert_equal(['a', 'b', 3], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 let l = [1, 2, 3, 4]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
539 lockvar! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 call assert_equal([1, 2, 3, 4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 unlockvar l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 call assert_fails('unlet l[0:1]', 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 call assert_equal([1, 2, 3, 4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 call assert_fails('unlet l[1:2]', 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 call assert_equal([1, 2, 3, 4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 unlockvar l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 call assert_fails('let l[0:1] = [0, 1]', 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 call assert_equal([1, 2, 3, 4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 call assert_fails('let l[1:2] = [0, 1]', 'E741:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
550 call assert_equal([1, 2, 3, 4], l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 " lockvar/islocked() triggering script autoloading
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 func Test_lockvar_script_autoload()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 let old_rtp = &rtp
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 set rtp+=./sautest
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 lockvar g:footest#x
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559 unlockvar g:footest#x
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
560 call assert_equal(-1, islocked('g:footest#x'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
561 call assert_equal(0, exists('g:footest#x'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 call assert_equal(1, g:footest#x)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 let &rtp = old_rtp
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 " a:000 function argument test
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 func s:arg_list_test(...)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 call assert_fails('let a:000 = [1, 2]', 'E46:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 call assert_fails('let a:000[0] = 9', 'E742:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 call assert_fails('let a:000[2] = [9, 10]', 'E742:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 call assert_fails('let a:000[3] = {9 : 10}', 'E742:')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 " now the tests that should pass
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 let a:000[2][1] = 9
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 call extend(a:000[2], [5, 6])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 let a:000[3][5] = 8
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 let a:000[3]['a'] = 12
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 call assert_equal([1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}], a:000)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 func Test_func_arg_list()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 call s:arg_list_test(1, 2, [3, 4], {5: 6})
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
585 " Tests for reverse(), sort(), uniq()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586 func Test_reverse_sort_uniq()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 call assert_equal(['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5], uniq(copy(l)))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(l))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(reverse(l)))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(l))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 call assert_equal([[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'], reverse(sort(l)))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(reverse(sort(l))))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 call assert_equal(['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]], uniq(sort(l)))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
595
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
596 let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
15571
4af72c724093 patch 8.1.0793: incorrect error messages for functions that take a Blob
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
603
15579
391ac26c9412 patch 8.1.0797: error E898 is used twice
Bram Moolenaar <Bram@vim.org>
parents: 15571
diff changeset
604 call assert_fails('call reverse("")', 'E899:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 " splitting a string to a List
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 func Test_str_split()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 call assert_equal(['aa', 'bb'], split(' aa bb '))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 call assert_equal(['aa', 'bb'], split(' aa bb ', '\W\+', 0))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 call assert_equal(['', 'aa', 'bb', ''], split(' aa bb ', '\W\+', 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 call assert_equal(['', '', 'aa', '', 'bb', '', ''], split(' aa bb ', '\W', 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 call assert_equal(['aa', '', 'bb'], split(':aa::bb:', ':', 0))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 call assert_equal(['', 'aa', '', 'bb', ''], split(':aa::bb:', ':', 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615 call assert_equal(['aa', '', 'bb', 'cc', ''], split('aa,,bb, cc,', ',\s*', 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 call assert_equal(['a', 'b', 'c'], split('abc', '\zs'))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 " compare recursively linked list and dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 func Test_listdict_compare()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 let l = [1, 2, 3, 4]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 let d = {'1': 1, '2': l, '3': 3}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 let l[1] = d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 call assert_true(l == l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626 call assert_true(d == d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 call assert_false(l != deepcopy(l))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 call assert_false(d != deepcopy(d))
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 " compare complex recursively linked list and dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 func Test_listdict_compare_complex()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 let l = []
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 call add(l, l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 let dict4 = {"l": l}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 call add(dict4.l, dict4)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 let lcopy = deepcopy(l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 let dict4copy = deepcopy(dict4)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 call assert_true(l == lcopy)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 call assert_true(dict4 == dict4copy)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 func Test_listdict_extend()
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
644 " Test extend() with lists
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
645
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
646 " Pass the same List to extend()
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
647 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
648 call assert_equal([1, 2, 3, 1, 2, 3], extend(l, l))
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
649 call assert_equal([1, 2, 3, 1, 2, 3], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
650
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
651 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
652 call assert_equal([1, 2, 3, 4, 5, 6], extend(l, [4, 5, 6]))
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
653 call assert_equal([1, 2, 3, 4, 5, 6], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
654
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
655 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
656 call extend(l, [4, 5, 6], 0)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
657 call assert_equal([4, 5, 6, 1, 2, 3], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
658
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
659 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
660 call extend(l, [4, 5, 6], 1)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
661 call assert_equal([1, 4, 5, 6, 2, 3], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
662
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
663 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
664 call extend(l, [4, 5, 6], 3)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
665 call assert_equal([1, 2, 3, 4, 5, 6], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
666
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
667 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
668 call extend(l, [4, 5, 6], -1)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
669 call assert_equal([1, 2, 4, 5, 6, 3], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
670
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
671 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
672 call extend(l, [4, 5, 6], -3)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
673 call assert_equal([4, 5, 6, 1, 2, 3], l)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
674
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
675 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
676 call assert_fails("call extend(l, [4, 5, 6], 4)", 'E684:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
677 call assert_fails("call extend(l, [4, 5, 6], -4)", 'E684:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
678 call assert_fails("call extend(l, [4, 5, 6], 1.2)", 'E805:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
679
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
680 " Test extend() with dictionaries.
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
681
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682 " Pass the same Dict to extend()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
683 let d = { 'a': {'b': 'B'}}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
684 call extend(d, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
685 call assert_equal({'a': {'b': 'B'}}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
686
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
687 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
688 call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, extend(d, {'b': 0, 'c':'C'}))
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
689 call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, d)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
690
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
691 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
692 call extend(d, {'a': 'A', 'b': 0, 'c': 'C'}, "force")
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
693 call assert_equal({'a': 'A', 'b': 0, 'c': 'C'}, d)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
694
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
695 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
696 call extend(d, {'b': 0, 'c':'C'}, "keep")
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
697 call assert_equal({'a': 'A', 'b': 'B', 'c': 'C'}, d)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
698
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
699 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
700 call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
701 call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'xxx')", 'E475:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
702 call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E806:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
703 call assert_equal({'a': 'A', 'b': 'B'}, d)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
704
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
705 call assert_fails("call extend([1, 2], 1)", 'E712:')
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
706 call assert_fails("call extend([1, 2], {})", 'E712:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 endfunc
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
708
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
709 func s:check_scope_dict(x, fixed)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
710 func s:gen_cmd(cmd, x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
711 return substitute(a:cmd, '\<x\ze:', a:x, 'g')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
712 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
713
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
714 let cmd = s:gen_cmd('let x:foo = 1', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
715 if a:fixed
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
716 call assert_fails(cmd, 'E461')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
717 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
718 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
719 exe s:gen_cmd('call assert_equal(1, x:foo)', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
720 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
721
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
722 let cmd = s:gen_cmd('let x:["bar"] = 2', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
723 if a:fixed
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
724 call assert_fails(cmd, 'E461')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
725 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
726 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
727 exe s:gen_cmd('call assert_equal(2, x:bar)', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
728 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
729
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
730 let cmd = s:gen_cmd('call extend(x:, {"baz": 3})', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
731 if a:fixed
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
732 call assert_fails(cmd, 'E742')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
733 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
734 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
735 exe s:gen_cmd('call assert_equal(3, x:baz)', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
736 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
737
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
738 if a:fixed
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
739 if a:x ==# 'a'
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
740 call assert_fails('unlet a:x', 'E795')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
741 call assert_fails('call remove(a:, "x")', 'E742')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
742 elseif a:x ==# 'v'
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
743 call assert_fails('unlet v:count', 'E795')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
744 call assert_fails('call remove(v:, "count")', 'E742')
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
745 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
746 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
747 exe s:gen_cmd('unlet x:foo', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
748 exe s:gen_cmd('unlet x:bar', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
749 exe s:gen_cmd('call remove(x:, "baz")', a:x)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
750 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
751
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
752 delfunc s:gen_cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
753 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
754
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
755 func Test_scope_dict()
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
756 " Test for g:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
757 call s:check_scope_dict('g', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
758
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
759 " Test for s:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
760 call s:check_scope_dict('s', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
761
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
762 " Test for l:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
763 call s:check_scope_dict('l', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
764
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
765 " Test for a:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
766 call s:check_scope_dict('a', v:true)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
767
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
768 " Test for b:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
769 call s:check_scope_dict('b', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
770
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
771 " Test for w:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
772 call s:check_scope_dict('w', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
773
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
774 " Test for t:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
775 call s:check_scope_dict('t', v:false)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
776
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
777 " Test for v:
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
778 call s:check_scope_dict('v', v:true)
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
779 endfunc