comparison src/testdir/test_vim9_assign.vim @ 23523:b0a6e7325169 v8.2.2304

patch 8.2.2304: Vim9: no test for unletting an imported variable Commit: https://github.com/vim/vim/commit/0acbf5ae6632b36c2d2f93406478270ef21f528b Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 5 20:58:25 2021 +0100 patch 8.2.2304: Vim9: no test for unletting an imported variable Problem: Vim9: no test for unletting an imported variable. Solution: Add a test. Fix line number in error.
author Bram Moolenaar <Bram@vim.org>
date Tue, 05 Jan 2021 21:00:06 +0100
parents 36bf9a6fbd4c
children f39a18a42aed
comparison
equal deleted inserted replaced
23522:32ad1f147776 23523:b0a6e7325169
1347 assert_true(exists('s:somevar')) 1347 assert_true(exists('s:somevar'))
1348 unlet s:somevar 1348 unlet s:somevar
1349 assert_false(exists('s:somevar')) 1349 assert_false(exists('s:somevar'))
1350 unlet! s:somevar 1350 unlet! s:somevar
1351 1351
1352 CheckDefExecFailure([
1353 'var dd = 111',
1354 'unlet dd',
1355 ], 'E1081:', 2)
1356
1352 # dict unlet 1357 # dict unlet
1353 var dd = {a: 1, b: 2, c: 3} 1358 var dd = {a: 1, b: 2, c: 3}
1354 unlet dd['a'] 1359 unlet dd['a']
1355 unlet dd.c 1360 unlet dd.c
1356 assert_equal({b: 2}, dd) 1361 assert_equal({b: 2}, dd)
1365 var dl = [{a: 1, b: 2}, {c: 3}] 1370 var dl = [{a: 1, b: 2}, {c: 3}]
1366 unlet dl[0]['b'] 1371 unlet dl[0]['b']
1367 assert_equal([{a: 1}, {c: 3}], dl) 1372 assert_equal([{a: 1}, {c: 3}], dl)
1368 1373
1369 CheckDefExecFailure([ 1374 CheckDefExecFailure([
1370 'var ll = test_null_list()', 1375 'var ll = test_null_list()',
1371 'unlet ll[0]', 1376 'unlet ll[0]',
1372 ], 'E684:') 1377 ], 'E684:', 2)
1373 CheckDefExecFailure([ 1378 CheckDefExecFailure([
1374 'var ll = [1]', 1379 'var ll = [1]',
1375 'unlet ll[2]', 1380 'unlet ll[2]',
1376 ], 'E684:') 1381 ], 'E684:', 2)
1377 CheckDefExecFailure([ 1382 CheckDefExecFailure([
1378 'var dd = test_null_dict()', 1383 'var ll = [1]',
1379 'unlet dd["a"]', 1384 'unlet ll[g:astring]',
1380 ], 'E716:') 1385 ], 'E39:', 2)
1381 CheckDefExecFailure([ 1386 CheckDefExecFailure([
1382 'var dd = {a: 1}', 1387 'var dd = test_null_dict()',
1383 'unlet dd["b"]', 1388 'unlet dd["a"]',
1384 ], 'E716:') 1389 ], 'E716:', 2)
1390 CheckDefExecFailure([
1391 'var dd = {a: 1}',
1392 'unlet dd["b"]',
1393 ], 'E716:', 2)
1394 CheckDefExecFailure([
1395 'var dd = {a: 1}',
1396 'unlet dd[g:alist]',
1397 ], 'E1105:', 2)
1385 1398
1386 # can compile unlet before variable exists 1399 # can compile unlet before variable exists
1387 g:someDict = {key: 'val'} 1400 g:someDict = {key: 'val'}
1388 var k = 'key' 1401 var k = 'key'
1389 unlet g:someDict[k] 1402 unlet g:someDict[k]
1424 ' unlet s:svar', 1437 ' unlet s:svar',
1425 'enddef', 1438 'enddef',
1426 'defcompile', 1439 'defcompile',
1427 ], 'E1081:') 1440 ], 'E1081:')
1428 1441
1442 writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim')
1443 var lines =<< trim END
1444 vim9script
1445 import svar from './XunletExport.vim'
1446 def UnletSvar()
1447 unlet svar
1448 enddef
1449 defcompile
1450 END
1451 CheckScriptFailure(lines, 'E1081:', 1)
1452 delete('XunletExport.vim')
1453
1429 $ENVVAR = 'foobar' 1454 $ENVVAR = 'foobar'
1430 assert_equal('foobar', $ENVVAR) 1455 assert_equal('foobar', $ENVVAR)
1431 unlet $ENVVAR 1456 unlet $ENVVAR
1432 assert_equal('', $ENVVAR) 1457 assert_equal('', $ENVVAR)
1433 enddef 1458 enddef