comparison src/testdir/test_vim9_script.vim @ 19623:2fee087c94cb v8.2.0368

patch 8.2.0368: Vim9: import that redefines local variable does not fail Commit: https://github.com/vim/vim/commit/5269bd2a724fdb8c16c9635ef744a670f1bc8bd5 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 9 19:25:27 2020 +0100 patch 8.2.0368: Vim9: import that redefines local variable does not fail Problem: Vim9: import that redefines local variable does not fail. Solution: Check for already defined symbols.
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Mar 2020 19:30:04 +0100
parents 043989a2f449
children ad37a198a708
comparison
equal deleted inserted replaced
19622:684f747f0568 19623:2fee087c94cb
360 export def Exported(): string 360 export def Exported(): string
361 return 'Exported' 361 return 'Exported'
362 enddef 362 enddef
363 END 363 END
364 364
365 def Test_vim9script() 365 def Test_vim9_import_export()
366 let import_script_lines =<< trim END 366 let import_script_lines =<< trim END
367 vim9script 367 vim9script
368 import {exported, Exported} from './Xexport.vim' 368 import {exported, Exported} from './Xexport.vim'
369 g:imported = exported 369 g:imported = exported
370 exported += 3 370 exported += 3
447 import name from './Xexport.vim' 447 import name from './Xexport.vim'
448 END 448 END
449 writefile(import_not_exported_lines, 'Ximport.vim') 449 writefile(import_not_exported_lines, 'Ximport.vim')
450 assert_fails('source Ximport.vim', 'E1049:') 450 assert_fails('source Ximport.vim', 'E1049:')
451 451
452 " try to import something that is already defined
453 let import_already_defined =<< trim END
454 vim9script
455 let exported = 'something'
456 import exported from './Xexport.vim'
457 END
458 writefile(import_already_defined, 'Ximport.vim')
459 assert_fails('source Ximport.vim', 'E1073:')
460
461 " try to import something that is already defined
462 import_already_defined =<< trim END
463 vim9script
464 let exported = 'something'
465 import * as exported from './Xexport.vim'
466 END
467 writefile(import_already_defined, 'Ximport.vim')
468 assert_fails('source Ximport.vim', 'E1073:')
469
470 " try to import something that is already defined
471 import_already_defined =<< trim END
472 vim9script
473 let exported = 'something'
474 import {exported} from './Xexport.vim'
475 END
476 writefile(import_already_defined, 'Ximport.vim')
477 assert_fails('source Ximport.vim', 'E1073:')
478
452 " import a very long name, requires making a copy 479 " import a very long name, requires making a copy
453 let import_long_name_lines =<< trim END 480 let import_long_name_lines =<< trim END
454 vim9script 481 vim9script
455 import name012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 from './Xexport.vim' 482 import name012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 from './Xexport.vim'
456 END 483 END
480 507
481 let import_missing_comma_lines =<< trim END 508 let import_missing_comma_lines =<< trim END
482 vim9script 509 vim9script
483 import {exported name} from './Xexport.vim' 510 import {exported name} from './Xexport.vim'
484 END 511 END
485 writefile(import_missing_comma_lines, 'Ximport.vim') 512 writefile(import_missing_comma_lines, 'Ximport3.vim')
486 assert_fails('source Ximport.vim', 'E1046:') 513 assert_fails('source Ximport3.vim', 'E1046:')
487 514
488 delete('Ximport.vim') 515 delete('Ximport.vim')
516 delete('Ximport3.vim')
489 delete('Xexport.vim') 517 delete('Xexport.vim')
490 518
491 " Check that in a Vim9 script 'cpo' is set to the Vim default. 519 " Check that in a Vim9 script 'cpo' is set to the Vim default.
492 set cpo&vi 520 set cpo&vi
493 let cpo_before = &cpo 521 let cpo_before = &cpo