annotate src/testdir/test_listdict.vim @ 25330:820395d1137b v8.2.3202

patch 8.2.3202: Vim9: tests are only executed for legacy script Commit: https://github.com/vim/vim/commit/5dd839ce20466eea52e59ecf86456f1ab370d2bd Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 22 18:48:53 2021 +0200 patch 8.2.3202: Vim9: tests are only executed for legacy script Problem: Vim9: tests are only executed for legacy script. Solution: Run more tests also for Vim9 script. Fix uncovered problems.
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Jul 2021 19:00:05 +0200
parents a386f83499ed
children e8e2c4d33b9b
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
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
3 source vim9.vim
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
4
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 func TearDown()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " 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
7 call test_garbagecollect_now()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 endfunc
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 " Tests for List type
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " List creation
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 func Test_list_create()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " 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
15 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
16 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
17 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
18 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
19 let x = 10
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let x = l[-5]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 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
24 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call assert_equal(10, x)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
21556
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
28 " This was allowed in legacy Vim script
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
29 let s:list_with_spaces = [1 , 2 , 3]
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
30
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " List slices
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 func Test_list_slice()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 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
34 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
35 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
36 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
37 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
38 call assert_equal([], l[8:-1])
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
39 call assert_equal([], l[0:-10])
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
40 " perform an operation on a list slice
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
41 let l = [1, 2, 3]
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
42 let l[:1] += [1, 2]
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
43 let l[2:] -= [1]
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
44 call assert_equal([2, 4, 2], l)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 " List identity
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 func Test_list_identity()
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
49 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
50 VAR l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
51 VAR ll = l
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
52 VAR lx = copy(l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
53 call assert_true(l == ll)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
54 call assert_false(l isnot ll)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
55 call assert_true(l is ll)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
56 call assert_true(l == lx)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
57 call assert_false(l is lx)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
58 call assert_true(l isnot lx)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
59 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
60 call CheckLegacyAndVim9Success(lines)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 " removing items with :unlet
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 func Test_list_unlet()
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
65 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
66 VAR l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
67 unlet l[2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
68 call assert_equal([1, 'as''d', {'a': 1}], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
69 LET l = range(8)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
70 unlet l[: 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
71 unlet l[1 :]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
72 call assert_equal([4], l)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
74 #" removing items out of range: silently skip items that don't exist
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
75 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
76 unlet l[2 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
77 call assert_equal([0, 1, 3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
78 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
79 unlet l[2 : 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
80 call assert_equal([0, 1], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
81 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
82 unlet l[2 : 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
83 call assert_equal([0, 1], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
84 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
85 unlet l[2 : 5]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
86 call assert_equal([0, 1], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
87 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
88 unlet l[-2 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
89 call assert_equal([0, 1, 3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
90 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
91 unlet l[-3 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
92 call assert_equal([0, 3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
93 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
94 unlet l[-4 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
95 call assert_equal([3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
96 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
97 unlet l[-5 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
98 call assert_equal([3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
99 LET l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
100 unlet l[-6 : 2]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
101 call assert_equal([3], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
102 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
103 call CheckLegacyAndVim9Success(lines)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
104
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 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
106 unlet l[2:2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 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
108 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
109 unlet l[2:3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 call assert_equal([0, 1], l)
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
111
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
112 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
113 VAR l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
114 unlet l[2 : 1]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
115 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
116 call CheckLegacyAndVim9Failure(lines, 'E684:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
117
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
118 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
119 VAR l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
120 unlet l[-1 : 2]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
121 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
122 call CheckLegacyAndVim9Failure(lines, 'E684:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 " assignment to a list
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 func Test_list_assign()
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
127 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
128 VAR l = [0, 1, 2, 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
129 VAR va = 0
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
130 VAR vb = 0
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
131 LET [va, vb] = l[2 : 3]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
132 call assert_equal([2, 3], [va, vb])
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
133 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
134 call CheckLegacyAndVim9Success(lines)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
135
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
136 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
137 let l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
138 let [va, vb] = l
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
139 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
140 call CheckScriptFailure(lines, 'E687:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
141 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
142 var l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
143 var va = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
144 var vb = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
145 [va, vb] = l
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
146 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
147 call CheckScriptFailure(['vim9script'] + lines, 'E687:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
148 call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
149
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
150 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
151 let l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
152 let [va, vb] = l[1:1]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
153 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
154 call CheckScriptFailure(lines, 'E688:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
155 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
156 var l = [0, 1, 2, 3]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
157 var va = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
158 var vb = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
159 [va, vb] = l[1 : 1]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
160 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
161 call CheckScriptFailure(['vim9script'] + lines, 'E688:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
162 call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 " test for range assign
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 func Test_list_range_assign()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 let l = [0]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 let l[:] = [1, 2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 call assert_equal([1, 2], l)
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
170 let l[-4:-1] = [5, 6]
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
171 call assert_equal([5, 6], l)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
174 " 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
175 func Test_list_func_remove()
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
176 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
177 #" Test removing 1 element
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
178 VAR l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
179 call assert_equal(1, remove(l, 0))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
180 call assert_equal([2, 3, 4], l)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
181
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
182 LET l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
183 call assert_equal(2, remove(l, 1))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
184 call assert_equal([1, 3, 4], l)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
185
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
186 LET l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
187 call assert_equal(4, remove(l, -1))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
188 call assert_equal([1, 2, 3], l)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
189
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
190 #" Test removing range of element(s)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
191 LET l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
192 call assert_equal([3], remove(l, 2, 2))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
193 call assert_equal([1, 2, 4], l)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
194
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
195 LET l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
196 call assert_equal([2, 3], remove(l, 1, 2))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
197 call assert_equal([1, 4], l)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
198
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
199 LET l = [1, 2, 3, 4]
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
200 call assert_equal([2, 3], remove(l, -3, -2))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
201 call assert_equal([1, 4], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
202 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
203 call CheckLegacyAndVim9Success(lines)
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
204
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
205 " Test invalid cases
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
206 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
207 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
208 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
209 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
210 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
211 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
212 endfunc
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
213
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
214 " List add() function
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
215 func Test_list_add()
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
216 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
217 VAR l = []
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
218 call add(l, 1)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
219 call add(l, [2, 3])
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
220 call add(l, [])
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
221 call add(l, test_null_list())
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
222 call add(l, {'k': 3})
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
223 call add(l, {})
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
224 call add(l, test_null_dict())
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
225 call assert_equal([1, [2, 3], [], [], {'k': 3}, {}, {}], l)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
226 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
227 call CheckLegacyAndVim9Success(lines)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
228
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
229 " weird legacy behavior
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
230 call assert_equal(1, add(test_null_list(), 4))
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
231 endfunc
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
232
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 " Tests for Dictionary type
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 func Test_dict()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 " Creating Dictionary directly with different types
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
237 let lines =<< trim END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
238 VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}, }
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
239 call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
240 call assert_equal('asd', d.1)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
241 call assert_equal(['-1', '1', 'b'], sort(keys(d)))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
242 call assert_equal(['asd', [1, 2, function('strlen')], {'a': 1}], values(d))
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
243 call extend(d, {3: 33, 1: 99})
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
244 call extend(d, {'b': 'bbb', 'c': 'ccc'}, "keep")
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
245 call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
246 END
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
247 call CheckLegacyAndVim9Success(lines)
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
248
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 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
250 call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d))
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
251
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 let v = []
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 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
254 call extend(v, [key, val])
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 unlet key val
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 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
258
25308
a386f83499ed patch 8.2.3191: Vim9: not enough code is tested
Bram Moolenaar <Bram@vim.org>
parents: 25036
diff changeset
259 call extend(d, {3: 33, 1: 99})
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
260 call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737:')
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
261
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
262 " duplicate key
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
263 call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
264 " missing comma
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
265 call assert_fails("let d = {'k' : 10 'k' : 20}", 'E722:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
266 " missing curly brace
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
267 call assert_fails("let d = {'k' : 10,", 'E723:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
268 " invalid key
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
269 call assert_fails('let d = #{++ : 10}', 'E15:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
270 " wrong type for key
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
271 call assert_fails('let d={[] : 10}', 'E730:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
272 " undefined variable as value
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
273 call assert_fails("let d={'k' : i}", 'E121:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
275
21556
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
276 " This was allowed in legacy Vim script
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
277 let s:dict_with_spaces = {'one' : 1 , 'two' : 2 , 'three' : 3}
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
278 let s:dict_with_spaces_lit = #{one : 1 , two : 2 , three : 3}
963913d80284 patch 8.2.1328: no space allowed before comma in list
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
279
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
280 " Dictionary identity
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
281 func Test_dict_identity()
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
282 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
283 VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1}, }
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
284 VAR dd = d
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
285 VAR dx = copy(d)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
286 call assert_true(d == dd)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
287 call assert_false(d isnot dd)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
288 call assert_true(d is dd)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
289 call assert_true(d == dx)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
290 call assert_false(d is dx)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
291 call assert_true(d isnot dx)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
292 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
293 call CheckLegacyAndVim9Success(lines)
12788
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 " removing items with :unlet
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
297 func Test_dict_unlet()
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
298 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
299 VAR d = {'b': 'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
300 unlet d.b
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
301 unlet d[-1]
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
302 call assert_equal({'1': 99, '3': 33}, d)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
303 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
304 call CheckLegacyAndVim9Success(lines)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 " 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
308 func Test_dict_big()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 let d = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
310 for i in range(1500)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 let d[i] = 3000 - i
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
312 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 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
314 let str = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 let n = d[1500]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 catch
22754
837756417c5e patch 8.2.1925: list/dict test fails
Bram Moolenaar <Bram@vim.org>
parents: 22547
diff changeset
318 let str = substitute(v:exception, '\v(.{14}).*( "\d{4}").*', '\1\2', '')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
319 endtry
22754
837756417c5e patch 8.2.1925: list/dict test fails
Bram Moolenaar <Bram@vim.org>
parents: 22547
diff changeset
320 call assert_equal('Vim(let):E716: "1500"', str)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 " lookup each items
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323 for i in range(1500)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
324 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
325 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 let i += 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328 " delete even items
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
329 while i >= 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
330 let i -= 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
331 unlet d[i]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
332 endwhile
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
333 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
334 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
335
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
336 " 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
337 let d[33] = 999
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 let i = 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339 while i < 1500
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
340 if i != 33
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
341 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
342 else
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
343 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
344 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 unlet d[i]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 let i += 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 endwhile
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 call assert_equal({}, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 unlet d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352 " Dictionary function
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 func Test_dict_func()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
354 let d = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 func d.func(a) dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
356 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
357 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358 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
359 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
360 let x = d.func('again: ')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
361 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
362 let Fn = d.func
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
363 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
364 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
365
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
366 func Test_dict_assign()
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
367 let d = {}
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
368 let d.1 = 1
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
369 let d._ = 2
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
370 call assert_equal({'1': 1, '_': 2}, d)
25036
3b8d3b383fd6 patch 8.2.3055: strange error for assigning to "x.key" on non-dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24822
diff changeset
371
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
372 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
373 VAR d = {}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
374 LET d.a = 1
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
375 LET d._ = 2
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
376 call assert_equal({'a': 1, '_': 2}, d)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
377 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
378 call CheckLegacyAndVim9Success(lines)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
379
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
380 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
381 let n = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
382 let n.key = 3
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
383 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
384 call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
385 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
386 vim9script
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
387 var n = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
388 n.key = 3
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
389 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
390 call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
391 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
392 var n = 0
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
393 n.key = 3
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
394 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
395 call CheckDefFailure(lines, 'E1141:')
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
396 endfunc
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
397
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
398 " 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
399 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
400 let g:dict = {}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
401 function g:dict.func() dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402 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
403 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 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
405 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
406 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
407 unlet g:dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
408 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
409
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
410 " Test removing items in a dictionary
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
411 func Test_dict_func_remove()
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
412 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
413 VAR d = {1: 'a', 2: 'b', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
414 call assert_equal('b', remove(d, 2))
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
415 call assert_equal({1: 'a', 3: 'c'}, d)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
416 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
417 call CheckLegacyAndVim9Success(lines)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
418
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
419 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
420 VAR d = {1: 'a', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
421 call remove(d, 1, 2)
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
422 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
423 call CheckLegacyAndVim9Failure(lines, 'E118:')
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
424
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
425 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
426 VAR d = {1: 'a', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
427 call remove(d, 'a')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
428 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
429 call CheckLegacyAndVim9Failure(lines, 'E716:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
430
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
431 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
432 let d = {1: 'a', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
433 call remove(d, [])
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
434 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
435 call CheckScriptFailure(lines, 'E730:')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
436 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
437 vim9script
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
438 var d = {1: 'a', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
439 call remove(d, [])
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
440 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
441 call CheckScriptFailure(lines, 'E1174: String required for argument 2')
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
442 let lines =<< trim END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
443 var d = {1: 'a', 3: 'c'}
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
444 call remove(d, [])
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
445 END
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
446 call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
14856
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
447 endfunc
c5a2fb8b221d patch 8.1.0440: remove() with a range not sufficiently tested
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
448
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449 " 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
450 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
451 let d = {1:1}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 func d.func(a)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 return "a:" . a:a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 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
456 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
457 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 15949
diff changeset
459 func Test_dict_literal_keys()
17413
40417757dffd patch 8.1.1705: using ~{} for a literal dict is not nice
Bram Moolenaar <Bram@vim.org>
parents: 17387
diff changeset
460 call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)
17387
2558f90045e5 patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
461
25330
820395d1137b patch 8.2.3202: Vim9: tests are only executed for legacy script
Bram Moolenaar <Bram@vim.org>
parents: 25308
diff changeset
462 " why *{} cannot be used for a literal dictionary
17387
2558f90045e5 patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
463 let blue = 'blue'
2558f90045e5 patch 8.1.1692: using *{} for literal dict is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 17375
diff changeset
464 call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
17368
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 15949
diff changeset
465 endfunc
6604ecb7a615 patch 8.1.1683: dictionary with string keys is longer than needed
Bram Moolenaar <Bram@vim.org>
parents: 15949
diff changeset
466
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 " 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
468 func Test_dict_deepcopy()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469 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
470 let l = [4, d, 6]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 let d[3] = l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 let dc = deepcopy(d)
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
473 call assert_fails('call deepcopy(d, 1)', 'E698:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 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
475 let l[1] = l2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 let l3 = deepcopy(l2)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
477 call assert_true(l3[1] is l3[2])
22101
0ee66f232839 patch 8.2.1600: Vim9: cannot use "true" with deepcopy()
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
478 call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
479 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481 " Locked variables
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 func Test_list_locked_var()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 let expected = [
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22101
diff changeset
484 \ [['1000-000', 'ppppppF'],
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 \ [['1000-000', 'ppppppF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
489 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 \ [['1100-100', 'ppFppFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493 \ [['1110-110', 'pFFpFFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 \ ['0010-010', 'pFppFpp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 \ [['1111-111', 'FFFFFFF'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 \ ['0011-011', 'FFpFFpp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
498 \ ['0000-000', 'ppppppp']]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 \ ]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 for depth in range(5)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 for u in range(3)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 unlet! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 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
504 exe "lockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 if u == 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 exe "unlockvar l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 elseif u == 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 exe "unlockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
509 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 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]")
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22101
diff changeset
511 call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
512 let ps = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
513 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 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
515 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
517 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 let l[1][1] = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
524 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
525 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526 let l[1] = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
527 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
530 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 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
533 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 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
539 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 let l[2] = {99: 99}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
550 let l = [99]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
551 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 endtry
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22101
diff changeset
555 call assert_equal(expected[depth][u][1], ps, 'depth: ' .. depth)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 endfor
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
558 call assert_fails("let x=islocked('a b')", 'E488:')
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
559 let mylist = [1, 2, 3]
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
560 call assert_fails("let x = islocked('mylist[1:2]')", 'E786:')
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
561 let mydict = {'k' : 'v'}
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
562 call assert_fails("let x = islocked('mydict.a')", 'E716:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 " Unletting locked variables
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 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
567 let expected = [
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22101
diff changeset
568 \ [['1000-000', 'ppppppp'],
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571 \ [['1000-000', 'ppFppFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574 \ [['1100-100', 'pFFpFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 \ ['0000-000', 'ppppppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 \ [['1110-110', 'FFFFFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578 \ ['0010-010', 'FppFppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 \ ['0000-000', 'ppppppp']],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 \ [['1111-111', 'FFFFFFp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 \ ['0011-011', 'FppFppp'],
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 \ ['0000-000', 'ppppppp']]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 \ ]
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 for depth in range(5)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586 for u in range(3)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 unlet! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588 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
589 exe "lockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 if u == 1
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 exe "unlockvar l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 elseif u == 2
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 exe "unlockvar " . depth . " l"
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 endif
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
595 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]")
22298
07e48ee8c3bb patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents: 22101
diff changeset
596 call assert_equal(expected[depth][u][0], ps, 'depth: ' .. depth)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 let ps = ''
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 unlet l[2]['6'][7]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 unlet l[2][6]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
609 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
611 unlet l[2]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
612 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
615 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
616 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 unlet l[1][1][0]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 unlet l[1][1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
627 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
629 unlet l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 try
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 let ps .= 'p'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 catch
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 let ps .= 'F'
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 endtry
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 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
641 endfor
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642 endfor
24695
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
643 " Deleting a list range should fail if the range is locked
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
644 let l = [1, 2, 3, 4]
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
645 lockvar l[1:2]
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
646 call assert_fails('unlet l[1:2]', 'E741:')
13efbfc53054 patch 8.2.2886: various pieces of code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 24618
diff changeset
647 unlet l
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
648 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
649
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
650 " 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
651
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
652 " 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
653 func Test_dict_lock_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
654 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
655 lockvar 1 d
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
656 call assert_fails('unlet d.a', 'E741:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
657 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
658
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
659 " 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
660 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
661 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
662 lockvar d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
663 unlet d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
664 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
665 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 " 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
668 func Test_dict_lock_filter()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
669 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
670 lockvar d.a
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 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
672 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
673 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
674
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
675 " map() after lock on dict
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
676 func Test_dict_lock_map()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
677 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
678 lockvar 1 d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
679 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
680 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
681 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
682
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
683 " 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
684 func Test_dict_lock_extend()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
685 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
686 lockvar d.a
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
687 call assert_fails("call extend(d, {'a' : 123})", 'E741:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
688 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
689 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
690
20136
fdf94ab9929b patch 8.2.0623: typo in test comment
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
691 " Cannot use += with a locked dict
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
692 func Test_dict_lock_operator()
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
693 let d = {}
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
694 lockvar d
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
695 call assert_fails("let d += {'k' : 10}", 'E741:')
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
696 unlockvar d
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
697 endfunc
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
698
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
699 " 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
700 func Tfunc1(this_is_a_long_parameter_name)
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
701 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
702 endfunc
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
703 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
704 call Tfunc1('testval')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
705 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
706
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
707 " 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
708 func Test_dict_scope_var_extend()
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
709 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
710 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
711
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14856
diff changeset
712 func Tfunc2(this_is_a_long_parameter_name)
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
713 call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 endfunc
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
715 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
716 call Tfunc2('testval')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 " 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
720 func Test_lock_var_unlet()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 let b:testvar = 123
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 lockvar 1 b:
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 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
724 unlockvar 1 b:
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 unlet! b:testvar
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 " 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
729 func Test_let_lock_list()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730 let l = ['a', 'b', 3]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
731 lockvar 1 l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732 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
733 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
734
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 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
737 lockvar! l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
738 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
739 unlockvar l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
740 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
741 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
742 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
743 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
744 unlockvar l[1]
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 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
746 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
747 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
748 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
749 unlet l
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
750 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
751
19689
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
752 " Locking part of the list
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
753 func Test_let_lock_list_items()
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
754 let l = [1, 2, 3, 4]
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
755 lockvar l[2:]
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
756 call assert_equal(0, islocked('l[0]'))
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
757 call assert_equal(1, islocked('l[2]'))
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
758 call assert_equal(1, islocked('l[3]'))
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
759 call assert_fails('let l[2] = 10', 'E741:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
760 call assert_fails('let l[3] = 20', 'E741:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
761 unlet l
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
762 endfunc
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
763
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
764 " lockvar/islocked() triggering script autoloading
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
765 func Test_lockvar_script_autoload()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
766 let old_rtp = &rtp
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
767 set rtp+=./sautest
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
768 lockvar g:footest#x
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769 unlockvar g:footest#x
17914
af3d441845cd patch 8.1.1953: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17413
diff changeset
770 call assert_equal(-1, 'g:footest#x'->islocked())
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 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
772 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
773 let &rtp = old_rtp
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
775
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
776 " a:000 function argument test
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
777 func s:arg_list_test(...)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
778 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
779 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
780 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
781 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
782
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
783 " 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
784 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
785 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
786 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
787 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
788 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
789 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
790
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
791 func Test_func_arg_list()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
792 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
793 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
794
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
795 " Tests for reverse(), sort(), uniq()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
796 func Test_reverse_sort_uniq()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
797 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
798 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
799 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
800 call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(reverse(l)))
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
801 if has('float')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
802 call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(l))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
803 call assert_equal([[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'], reverse(sort(l)))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
804 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))))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
805 call assert_equal(['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]], uniq(sort(l)))
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
806
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
807 let l = [7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
808 call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255], sort(copy(l), 'n'))
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
809
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
810 let l = [7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
811 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))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
812 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'))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
813 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)))
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
814 endif
15571
4af72c724093 patch 8.1.0793: incorrect error messages for functions that take a Blob
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
815
15579
391ac26c9412 patch 8.1.0797: error E898 is used twice
Bram Moolenaar <Bram@vim.org>
parents: 15571
diff changeset
816 call assert_fails('call reverse("")', 'E899:')
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21064
diff changeset
817 call assert_fails('call uniq([1, 2], {x, y -> []})', 'E745:')
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
818 call assert_fails("call sort([1, 2], function('min'), 1)", "E715:")
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
819 call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:")
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21064
diff changeset
820 call assert_fails("call sort([1, 2], function('min'))", "E118:")
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
821 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
822
20649
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
823 " reduce a list or a blob
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
824 func Test_reduce()
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
825 call assert_equal(1, reduce([], { acc, val -> acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
826 call assert_equal(10, reduce([1, 3, 5], { acc, val -> acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
827 call assert_equal(2 * (2 * ((2 * 1) + 2) + 3) + 4, reduce([2, 3, 4], { acc, val -> 2 * acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
828 call assert_equal('a x y z', ['x', 'y', 'z']->reduce({ acc, val -> acc .. ' ' .. val}, 'a'))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
829 call assert_equal(#{ x: 1, y: 1, z: 1 }, ['x', 'y', 'z']->reduce({ acc, val -> extend(acc, { val: 1 }) }, {}))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
830 call assert_equal([0, 1, 2, 3], reduce([1, 2, 3], function('add'), [0]))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
831
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
832 let l = ['x', 'y', 'z']
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
833 call assert_equal(42, reduce(l, function('get'), #{ x: #{ y: #{ z: 42 } } }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
834 call assert_equal(['x', 'y', 'z'], l)
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
835
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
836 call assert_equal(1, reduce([1], { acc, val -> acc + val }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
837 call assert_equal('x y z', reduce(['x', 'y', 'z'], { acc, val -> acc .. ' ' .. val }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
838 call assert_equal(120, range(1, 5)->reduce({ acc, val -> acc * val }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
839 call assert_fails("call reduce([], { acc, val -> acc + val })", 'E998: Reduce of an empty List with no initial value')
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
840
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
841 call assert_equal(1, reduce(0z, { acc, val -> acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
842 call assert_equal(1 + 0xaf + 0xbf + 0xcf, reduce(0zAFBFCF, { acc, val -> acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
843 call assert_equal(2 * (2 * 1 + 0xaf) + 0xbf, 0zAFBF->reduce({ acc, val -> 2 * acc + val }, 1))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
844
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
845 call assert_equal(0xff, reduce(0zff, { acc, val -> acc + val }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
846 call assert_equal(2 * (2 * 0xaf + 0xbf) + 0xcf, reduce(0zAFBFCF, { acc, val -> 2 * acc + val }))
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
847 call assert_fails("call reduce(0z, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
848
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
849 call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E897:')
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
850 call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E897:')
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
851 call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E897:')
22510
7060df0b8ebf patch 8.2.1803: a few failures are not tested
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
852 call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E117:')
7060df0b8ebf patch 8.2.1803: a few failures are not tested
Bram Moolenaar <Bram@vim.org>
parents: 22375
diff changeset
853 call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E39:')
21000
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
854
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
855 let g:lut = [1, 2, 3, 4]
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
856 func EvilRemove()
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
857 call remove(g:lut, 1)
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
858 return 1
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
859 endfunc
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
860 call assert_fails("call reduce(g:lut, { acc, val -> EvilRemove() }, 1)", 'E742:')
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
861 unlet g:lut
3b29ac3394dc patch 8.2.1051: crash when changing a list while using reduce() on it
Bram Moolenaar <Bram@vim.org>
parents: 20649
diff changeset
862 delfunc EvilRemove
21064
6dc8625889fe patch 8.2.1083: crash when using reduce() on a NULL list
Bram Moolenaar <Bram@vim.org>
parents: 21000
diff changeset
863
6dc8625889fe patch 8.2.1083: crash when using reduce() on a NULL list
Bram Moolenaar <Bram@vim.org>
parents: 21000
diff changeset
864 call assert_equal(42, reduce(test_null_list(), function('add'), 42))
6dc8625889fe patch 8.2.1083: crash when using reduce() on a NULL list
Bram Moolenaar <Bram@vim.org>
parents: 21000
diff changeset
865 call assert_equal(42, reduce(test_null_blob(), function('add'), 42))
22794
42bb78d46354 patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents: 22754
diff changeset
866
42bb78d46354 patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents: 22754
diff changeset
867 " should not crash
42bb78d46354 patch 8.2.1945: crash when passing NULL function to reduce()
Bram Moolenaar <Bram@vim.org>
parents: 22754
diff changeset
868 call assert_fails('echo reduce([1], test_null_function())', 'E1132:')
24618
4aebea72c397 patch 8.2.2848: crash whn calling partial
Bram Moolenaar <Bram@vim.org>
parents: 24396
diff changeset
869 call assert_fails('echo reduce([1], test_null_partial())', 'E1132:')
20649
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
870 endfunc
1fa0ace0ba65 patch 8.2.0878: no reduce() function
Bram Moolenaar <Bram@vim.org>
parents: 20158
diff changeset
871
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
872 " splitting a string to a List using split()
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
873 func Test_str_split()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
874 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
875 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
876 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
877 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
878 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
879 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
880 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
881 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
882 call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1))
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
883 call assert_fails("call split('abc', [])", 'E730:')
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
884 call assert_fails("call split('abc', 'b', [])", 'E745:')
22375
595ea7f099cd patch 8.2.1736: failure to compile a pattern not tested much
Bram Moolenaar <Bram@vim.org>
parents: 22298
diff changeset
885 call assert_equal(['abc'], split('abc', '\\%('))
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
886 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
887
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
888 " 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
889 func Test_listdict_compare()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
890 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
891 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
892 let l[1] = d
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
893 call assert_true(l == l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
894 call assert_true(d == d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
895 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
896 call assert_false(d != deepcopy(d))
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
897
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
898 " comparison errors
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
899 call assert_fails('echo [1, 2] =~ {}', 'E691:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
900 call assert_fails('echo [1, 2] =~ [1, 2]', 'E692:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
901 call assert_fails('echo {} =~ 5', 'E735:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
902 call assert_fails('echo {} =~ {}', 'E736:')
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
903 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
904
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
905 " 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
906 func Test_listdict_compare_complex()
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
907 let l = []
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
908 call add(l, l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
909 let dict4 = {"l": l}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
910 call add(dict4.l, dict4)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
911 let lcopy = deepcopy(l)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
912 let dict4copy = deepcopy(dict4)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
913 call assert_true(l == lcopy)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
914 call assert_true(dict4 == dict4copy)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
915 endfunc
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
916
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
917 " Test for extending lists and dictionaries
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
918 func Test_listdict_extend()
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
919 " Test extend() with lists
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
920
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
921 " Pass the same List to extend()
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
922 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
923 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
924 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
925
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
926 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
927 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
928 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
929
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
930 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
931 call extend(l, [4, 5, 6], 0)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
932 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
933
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
934 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
935 call extend(l, [4, 5, 6], 1)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
936 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
937
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
938 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
939 call extend(l, [4, 5, 6], 3)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
940 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
941
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
942 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
943 call extend(l, [4, 5, 6], -1)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
944 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
945
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
946 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
947 call extend(l, [4, 5, 6], -3)
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
948 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
949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
950 let l = [1, 2, 3]
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
951 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
952 call assert_fails("call extend(l, [4, 5, 6], -4)", 'E684:')
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
953 if has('float')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
954 call assert_fails("call extend(l, [4, 5, 6], 1.2)", 'E805:')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
955 endif
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
956
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
957 " Test extend() with dictionaries.
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
958
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
959 " 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
960 let d = { 'a': {'b': 'B'}}
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
961 call extend(d, d)
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
962 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
963
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
964 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
965 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
966 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
967
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
968 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
969 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
970 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
971
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
972 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
973 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
974 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
975
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
976 let d = {'a': 'A', 'b': 'B'}
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
977 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
978 call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'xxx')", 'E475:')
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
979 if has('float')
24822
5f8dd7b3ae41 patch 8.2.2949: tests failing because no error for float to string conversion
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
980 call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E475:')
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17914
diff changeset
981 endif
15949
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
982 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
983
d8ab4fa99341 patch 8.1.0980: extend() insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
984 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
985 call assert_fails("call extend([1, 2], {})", 'E712:')
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
986
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
987 " Extend g: dictionary with an invalid variable name
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
988 call assert_fails("call extend(g:, {'-!' : 10})", 'E461:')
24396
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
989
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
990 " Extend a list with itself.
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
991 let l = [1, 5, 7]
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
992 call extend(l, l, 0)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
993 call assert_equal([1, 5, 7, 1, 5, 7], l)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
994 let l = [1, 5, 7]
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
995 call extend(l, l, 1)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
996 call assert_equal([1, 1, 5, 7, 5, 7], l)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
997 let l = [1, 5, 7]
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
998 call extend(l, l, 2)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
999 call assert_equal([1, 5, 1, 5, 7, 7], l)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
1000 let l = [1, 5, 7]
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
1001 call extend(l, l, 3)
d406858354a6 patch 8.2.2738: extending a list with itself can give wrong result
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
1002 call assert_equal([1, 5, 7, 1, 5, 7], l)
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1003 endfunc
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1004
23588
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1005 func Test_listdict_extendnew()
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1006 " Test extendnew() with lists
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1007 let l = [1, 2, 3]
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1008 call assert_equal([1, 2, 3, 4, 5], extendnew(l, [4, 5]))
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1009 call assert_equal([1, 2, 3], l)
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1010
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1011 " Test extend() with dictionaries.
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1012 let d = {'a': {'b': 'B'}}
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1013 call assert_equal({'a': {'b': 'B'}, 'c': 'cc'}, extendnew(d, {'c': 'cc'}))
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1014 call assert_equal({'a': {'b': 'B'}}, d)
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1015 endfunc
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 22806
diff changeset
1016
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1017 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
1018 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
1019 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
1020 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1021
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1022 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
1023 if a:fixed
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1024 call assert_fails(cmd, 'E461:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1025 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1026 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1027 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
1028 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1029
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1030 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
1031 if a:fixed
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1032 call assert_fails(cmd, 'E461:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1033 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1034 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1035 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
1036 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1037
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1038 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
1039 if a:fixed
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1040 call assert_fails(cmd, 'E742:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1041 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1042 exe cmd
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1043 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
1044 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1045
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1046 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
1047 if a:x ==# 'a'
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1048 call assert_fails('unlet a:x', 'E795:')
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1049 call assert_fails('call remove(a:, "x")', 'E742:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1050 elseif a:x ==# 'v'
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1051 call assert_fails('unlet v:count', 'E795:')
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21556
diff changeset
1052 call assert_fails('call remove(v:, "count")', 'E742:')
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1053 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1054 else
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1055 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
1056 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
1057 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
1058 endif
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1059
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1060 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
1061 endfunc
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1062
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1063 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
1064 " 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
1065 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
1066
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1067 " 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
1068 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
1069
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1070 " 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
1071 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
1072
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1073 " 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
1074 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
1075
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1076 " 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
1077 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
1078
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1079 " 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
1080 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
1081
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1082 " 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
1083 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
1084
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15579
diff changeset
1085 " 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
1086 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
1087 endfunc
19689
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1088
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1089 " Test for deep nesting of lists (> 100)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1090 func Test_deep_nested_list()
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1091 let deep_list = []
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1092 let l = deep_list
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1093 for i in range(102)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1094 let newlist = []
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1095 call add(l, newlist)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1096 let l = newlist
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1097 endfor
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1098 call add(l, 102)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1099
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1100 call assert_fails('let m = deepcopy(deep_list)', 'E698:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1101 call assert_fails('lockvar 110 deep_list', 'E743:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1102 call assert_fails('unlockvar 110 deep_list', 'E743:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1103 call assert_fails('let x = execute("echo deep_list")', 'E724:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1104 call test_garbagecollect_now()
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1105 unlet deep_list
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1106 endfunc
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1107
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1108 " Test for deep nesting of dicts (> 100)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1109 func Test_deep_nested_dict()
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1110 let deep_dict = {}
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1111 let d = deep_dict
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1112 for i in range(102)
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1113 let newdict = {}
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1114 let d.k = newdict
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1115 let d = newdict
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1116 endfor
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1117 let d.k = 'v'
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1118
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1119 call assert_fails('let m = deepcopy(deep_dict)', 'E698:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1120 call assert_fails('lockvar 110 deep_dict', 'E743:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1121 call assert_fails('unlockvar 110 deep_dict', 'E743:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1122 call assert_fails('let x = execute("echo deep_dict")', 'E724:')
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1123 call test_garbagecollect_now()
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1124 unlet deep_dict
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1125 endfunc
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1126
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1127 " List and dict indexing tests
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1128 func Test_listdict_index()
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1129 call assert_fails('echo function("min")[0]', 'E695:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1130 call assert_fails('echo v:true[0]', 'E909:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1131 let d = {'k' : 10}
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1132 call assert_fails('echo d.', 'E15:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1133 call assert_fails('echo d[1:2]', 'E719:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1134 call assert_fails("let v = [4, 6][{-> 1}]", 'E729:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1135 call assert_fails("let v = range(5)[2:[]]", 'E730:')
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21064
diff changeset
1136 call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:'])
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1137 call assert_fails("let v = range(5)[2:3", 'E111:')
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1138 call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1139 call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1140 call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:')
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1141 let l = [1, 2, 3]
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1142 call assert_fails("let l[i] = 3", 'E121:')
24822
5f8dd7b3ae41 patch 8.2.2949: tests failing because no error for float to string conversion
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
1143 call assert_fails("let l[1.1] = 4", 'E805:')
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1144 call assert_fails("let l[:i] = [4, 5]", 'E121:')
24822
5f8dd7b3ae41 patch 8.2.2949: tests failing because no error for float to string conversion
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
1145 call assert_fails("let l[:3.2] = [4, 5]", 'E805:')
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1146 let t = test_unknown()
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1147 call assert_fails("echo t[0]", 'E685:')
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1148 endfunc
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1149
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1150 " Test for a null list
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1151 func Test_null_list()
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1152 let l = test_null_list()
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1153 call assert_equal(0, join(test_null_list()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1154 call assert_equal('', join(l))
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1155 call assert_equal(0, len(l))
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1156 call assert_equal(1, empty(l))
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1157 call assert_fails('let s = join([1, 2], [])', 'E730:')
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1158 call assert_equal([], split(test_null_string()))
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1159 call assert_equal([], l[:2])
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1160 call assert_true([] == l)
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1161 call assert_equal('[]', string(l))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1162 call assert_equal(0, sort(test_null_list()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1163 call assert_equal([], sort(l))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1164 call assert_equal(0, uniq(test_null_list()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1165 call assert_equal([], uniq(l))
22547
159a637fe5b4 patch 8.2.1822: list test doesn't fail
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
1166 let k = [] + l
159a637fe5b4 patch 8.2.1822: list test doesn't fail
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
1167 call assert_equal([], k)
159a637fe5b4 patch 8.2.1822: list test doesn't fail
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
1168 let k = l + []
159a637fe5b4 patch 8.2.1822: list test doesn't fail
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
1169 call assert_equal([], k)
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1170 call assert_equal(0, len(copy(l)))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1171 call assert_equal(0, count(l, 5))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1172 call assert_equal([], deepcopy(l))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1173 call assert_equal(5, get(l, 2, 5))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1174 call assert_equal(-1, index(l, 2, 5))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1175 call assert_equal(0, insert(test_null_list(), 2, -1))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1176 call assert_fails('call insert(l, 2, -1)', 'E684:')
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1177 call assert_equal(0, min(l))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1178 call assert_equal(0, max(l))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1179 call assert_equal(0, remove(test_null_list(), 0, 2))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1180 call assert_fails('call remove(l, 0, 2)', 'E684:')
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1181 call assert_equal([], repeat(l, 2))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1182 call assert_equal(0, reverse(test_null_list()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1183 call assert_equal([], reverse(l))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1184 call assert_equal(0, sort(test_null_list()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1185 call assert_equal([], sort(l))
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1186 call assert_equal('[]', string(l))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1187 call assert_fails('call extend(test_null_list(), test_null_list())', 'E1134:')
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1188 call assert_equal([], extend(l, l, 0))
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1189 lockvar l
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1190 call assert_equal(1, islocked('l'))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1191 unlockvar l
20109
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1192 endfunc
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1193
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1194 " Test for a null dict
e82996ad131f patch 8.2.0610: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
1195 func Test_null_dict()
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1196 call assert_equal(test_null_dict(), test_null_dict())
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1197 let d = test_null_dict()
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1198 call assert_equal({}, d)
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1199 call assert_equal(0, len(d))
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1200 call assert_equal(1, empty(d))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1201 call assert_equal(0, items(test_null_dict()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1202 call assert_equal([], items(d))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1203 call assert_equal(0, keys(test_null_dict()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1204 call assert_equal([], keys(d))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1205 call assert_equal(0, values(test_null_dict()))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1206 call assert_equal([], values(d))
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1207 call assert_false(has_key(d, 'k'))
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1208 call assert_equal('{}', string(d))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1209 call assert_fails('let x = d[10]', 'E716:')
20128
0b35a7ffceb2 patch 8.2.0619: null dict is not handled like an empty dict
Bram Moolenaar <Bram@vim.org>
parents: 20109
diff changeset
1210 call assert_equal({}, {})
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1211 call assert_equal(0, len(copy(d)))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1212 call assert_equal(0, count(d, 'k'))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1213 call assert_equal({}, deepcopy(d))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1214 call assert_equal(20, get(d, 'k', 20))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1215 call assert_equal(0, min(d))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1216 call assert_equal(0, max(d))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1217 call assert_equal(0, remove(test_null_dict(), 'k'))
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1218 call assert_fails("call remove(d, 'k')", 'E716:')
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1219 call assert_equal('{}', string(d))
22806
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1220 call assert_fails('call extend(test_null_dict(), test_null_dict())', 'E1133:')
690b84a6a7ce patch 8.2.1951: test for list and dict fails
Bram Moolenaar <Bram@vim.org>
parents: 22794
diff changeset
1221 call assert_equal({}, extend(d, d, 'keep'))
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1222 lockvar d
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1223 call assert_equal(1, islocked('d'))
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
1224 unlockvar d
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1225 endfunc
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19689
diff changeset
1226
19689
da98d2ed8dc5 patch 8.2.0401: not enough test coverage for evalvars.c
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
1227 " vim: shiftwidth=2 sts=2 expandtab