comparison src/testdir/test_vim9_assign.vim @ 23033:b98003d73150 v8.2.2063

patch 8.2.2063: Vim9: only one level of indexing supported Commit: https://github.com/vim/vim/commit/dc234caff22131bdc1ff9ea50d67e11843d0d73e Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 28 18:52:33 2020 +0100 patch 8.2.2063: Vim9: only one level of indexing supported Problem: Vim9: only one level of indexing supported. Solution: Handle more than one index in an assignment.
author Bram Moolenaar <Bram@vim.org>
date Sat, 28 Nov 2020 19:00:04 +0100
parents 5ff7125e81fc
children 75241f4377a4
comparison
equal deleted inserted replaced
23032:52326852b941 23033:b98003d73150
221 CheckDefFailure(['v:errmsg += 123'], 'E1012:') 221 CheckDefFailure(['v:errmsg += 123'], 'E1012:')
222 222
223 var text =<< trim END 223 var text =<< trim END
224 some text 224 some text
225 END 225 END
226 enddef
227
228 def Test_assign_index()
229 # list of list
230 var l1: list<number>
231 l1[0] = 123
232 assert_equal([123], l1)
233
234 var l2: list<list<number>>
235 l2[0] = []
236 l2[0][0] = 123
237 assert_equal([[123]], l2)
238
239 var l3: list<list<list<number>>>
240 l3[0] = []
241 l3[0][0] = []
242 l3[0][0][0] = 123
243 assert_equal([[[123]]], l3)
244
245 var lines =<< trim END
246 var l3: list<list<number>>
247 l3[0] = []
248 l3[0][0] = []
249 END
250 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 3)
251
252 # dict of dict
253 var d1: dict<number>
254 d1.one = 1
255 assert_equal({one: 1}, d1)
256
257 var d2: dict<dict<number>>
258 d2.one = {}
259 d2.one.two = 123
260 assert_equal({one: {two: 123}}, d2)
261
262 var d3: dict<dict<dict<number>>>
263 d3.one = {}
264 d3.one.two = {}
265 d3.one.two.three = 123
266 assert_equal({one: {two: {three: 123}}}, d3)
267
268 lines =<< trim END
269 var d3: dict<dict<number>>
270 d3.one = {}
271 d3.one.two = {}
272 END
273 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got dict<unknown>', 3)
274
275 # list of dict
276 var ld: list<dict<number>>
277 ld[0] = {}
278 ld[0].one = 123
279 assert_equal([{one: 123}], ld)
280
281 lines =<< trim END
282 var ld: list<dict<number>>
283 ld[0] = []
284 END
285 CheckDefFailure(lines, 'E1012: Type mismatch; expected dict<number> but got list<unknown>', 2)
286
287 # dict of list
288 var dl: dict<list<number>>
289 dl.one = []
290 dl.one[0] = 123
291 assert_equal({one: [123]}, dl)
292
293 lines =<< trim END
294 var dl: dict<list<number>>
295 dl.one = {}
296 END
297 CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2)
226 enddef 298 enddef
227 299
228 def Test_extend_list() 300 def Test_extend_list()
229 var lines =<< trim END 301 var lines =<< trim END
230 vim9script 302 vim9script