Mercurial > vim
comparison src/testdir/test_vim9_import.vim @ 27457:4c16acb2525f v8.2.4257
patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 29 21:45:34 2022 +0000
patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Problem: Vim9: finding global function without g: prefix but not finding
global variable is inconsistent.
Solution: Require using g: for a global function. Change the vim9.vim
script into a Vim9 script with exports. Fix that import in legacy
script does not work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 Jan 2022 23:00:05 +0100 |
parents | 1a6421c5be20 |
children | a14c4d3e3260 |
comparison
equal
deleted
inserted
replaced
27456:a8e2d91995ce | 27457:4c16acb2525f |
---|---|
1 " Test import/export of the Vim9 script language. | 1 " Test import/export of the Vim9 script language. |
2 " Also the autoload mechanism. | 2 " Also the autoload mechanism. |
3 | 3 |
4 source check.vim | 4 source check.vim |
5 source term_util.vim | 5 source term_util.vim |
6 source vim9.vim | 6 import './vim9.vim' as v9 |
7 | 7 |
8 let s:export_script_lines =<< trim END | 8 let s:export_script_lines =<< trim END |
9 vim9script | 9 vim9script |
10 var name: string = 'bob' | 10 var name: string = 'bob' |
11 def Concat(arg: string): string | 11 def Concat(arg: string): string |
31 return s .. 'some' | 31 return s .. 'some' |
32 enddef | 32 enddef |
33 export var AddRef = AddSome | 33 export var AddRef = AddSome |
34 END | 34 END |
35 | 35 |
36 def Undo_export_script_lines() | 36 def s:Undo_export_script_lines() |
37 unlet g:result | 37 unlet g:result |
38 unlet g:localname | 38 unlet g:localname |
39 enddef | 39 enddef |
40 | 40 |
41 def Test_vim9_import_export() | 41 def Test_vim9_import_export() |
409 const Goo = lib.G() | 409 const Goo = lib.G() |
410 assert_equal(42, Goo) | 410 assert_equal(42, Goo) |
411 enddef | 411 enddef |
412 DoTest() | 412 DoTest() |
413 END | 413 END |
414 CheckScriptSuccess(lines) | 414 v9.CheckScriptSuccess(lines) |
415 | 415 |
416 delete('Xlib.vim') | 416 delete('Xlib.vim') |
417 enddef | 417 enddef |
418 | 418 |
419 def Test_import_fails() | 419 def Test_import_fails() |
420 writefile([], 'Xfoo.vim') | 420 writefile([], 'Xfoo.vim') |
421 var lines =<< trim END | 421 var lines =<< trim END |
422 import './Xfoo.vim' as foo | 422 import './Xfoo.vim' as foo |
423 foo = 'bar' | 423 foo = 'bar' |
424 END | 424 END |
425 CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use foo itself']) | 425 v9.CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use foo itself']) |
426 lines =<< trim END | 426 lines =<< trim END |
427 vim9script | 427 vim9script |
428 import './Xfoo.vim' as foo | 428 import './Xfoo.vim' as foo |
429 var that = foo | 429 var that = foo |
430 END | 430 END |
431 CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') | 431 v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') |
432 lines =<< trim END | 432 lines =<< trim END |
433 vim9script | 433 vim9script |
434 import './Xfoo.vim' as foo | 434 import './Xfoo.vim' as foo |
435 var that: any | 435 var that: any |
436 that += foo | 436 that += foo |
437 END | 437 END |
438 CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') | 438 v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') |
439 lines =<< trim END | 439 lines =<< trim END |
440 vim9script | 440 vim9script |
441 import './Xfoo.vim' as foo | 441 import './Xfoo.vim' as foo |
442 foo += 9 | 442 foo += 9 |
443 END | 443 END |
444 CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') | 444 v9.CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') |
445 | 445 |
446 lines =<< trim END | 446 lines =<< trim END |
447 vim9script | 447 vim9script |
448 import './Xfoo.vim' as 9foo | 448 import './Xfoo.vim' as 9foo |
449 END | 449 END |
450 CheckScriptFailure(lines, 'E1047:') | 450 v9.CheckScriptFailure(lines, 'E1047:') |
451 lines =<< trim END | 451 lines =<< trim END |
452 vim9script | 452 vim9script |
453 import './Xfoo.vim' as the#foo | 453 import './Xfoo.vim' as the#foo |
454 END | 454 END |
455 CheckScriptFailure(lines, 'E1047:') | 455 v9.CheckScriptFailure(lines, 'E1047:') |
456 lines =<< trim END | 456 lines =<< trim END |
457 vim9script | 457 vim9script |
458 import './Xfoo.vim' as g:foo | 458 import './Xfoo.vim' as g:foo |
459 END | 459 END |
460 CheckScriptFailure(lines, 'E1047:') | 460 v9.CheckScriptFailure(lines, 'E1047:') |
461 | 461 |
462 delete('Xfoo.vim') | 462 delete('Xfoo.vim') |
463 | 463 |
464 lines =<< trim END | 464 lines =<< trim END |
465 vim9script | 465 vim9script |
472 | 472 |
473 lines =<< trim END | 473 lines =<< trim END |
474 import './Xthat.vim' as That | 474 import './Xthat.vim' as That |
475 That() | 475 That() |
476 END | 476 END |
477 CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself']) | 477 v9.CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself']) |
478 | 478 |
479 lines =<< trim END | 479 lines =<< trim END |
480 vim9script | 480 vim9script |
481 import './Xthat.vim' as That | 481 import './Xthat.vim' as That |
482 def Func() | 482 def Func() |
483 echo That() | 483 echo That() |
484 enddef | 484 enddef |
485 Func() | 485 Func() |
486 END | 486 END |
487 CheckScriptFailure(lines, 'E1236: Cannot use That itself') | 487 v9.CheckScriptFailure(lines, 'E1236: Cannot use That itself') |
488 | 488 |
489 lines =<< trim END | 489 lines =<< trim END |
490 import './Xthat.vim' as one | 490 import './Xthat.vim' as one |
491 import './Xthat.vim' as two | 491 import './Xthat.vim' as two |
492 END | 492 END |
493 CheckScriptFailure(lines, 'E1262:') | 493 v9.CheckScriptFailure(lines, 'E1262:') |
494 | 494 |
495 delete('Xthat.vim') | 495 delete('Xthat.vim') |
496 | 496 |
497 mkdir('Ximport') | 497 mkdir('Ximport') |
498 | 498 |
499 writefile(['vim9script'], 'Ximport/.vim') | 499 writefile(['vim9script'], 'Ximport/.vim') |
500 lines =<< trim END | 500 lines =<< trim END |
501 vim9script | 501 vim9script |
502 import './Ximport/.vim' | 502 import './Ximport/.vim' |
503 END | 503 END |
504 CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"') | 504 v9.CheckScriptFailure(lines, 'E1261: Cannot import .vim without using "as"') |
505 lines =<< trim END | 505 lines =<< trim END |
506 vim9script | 506 vim9script |
507 import './Ximport/.vim' as vim | 507 import './Ximport/.vim' as vim |
508 END | 508 END |
509 CheckScriptSuccess(lines) | 509 v9.CheckScriptSuccess(lines) |
510 | 510 |
511 writefile(['vim9script'], 'Ximport/.vimrc') | 511 writefile(['vim9script'], 'Ximport/.vimrc') |
512 lines =<< trim END | 512 lines =<< trim END |
513 vim9script | 513 vim9script |
514 import './Ximport/.vimrc' | 514 import './Ximport/.vimrc' |
515 END | 515 END |
516 CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim') | 516 v9.CheckScriptFailure(lines, 'E1257: Imported script must use "as" or end in .vim') |
517 lines =<< trim END | 517 lines =<< trim END |
518 vim9script | 518 vim9script |
519 import './Ximport/.vimrc' as vimrc | 519 import './Ximport/.vimrc' as vimrc |
520 END | 520 END |
521 CheckScriptSuccess(lines) | 521 v9.CheckScriptSuccess(lines) |
522 | 522 |
523 delete('Ximport', 'rf') | 523 delete('Ximport', 'rf') |
524 enddef | 524 enddef |
525 | 525 |
526 func g:Trigger() | 526 func g:Trigger() |
624 | 624 |
625 command -nargs=1 -complete=customlist,Xscript.Complete Cmd echo 'ok' | 625 command -nargs=1 -complete=customlist,Xscript.Complete Cmd echo 'ok' |
626 feedkeys(":Cmd ab\<Tab>\<C-B>#\<CR>", 'xnt') | 626 feedkeys(":Cmd ab\<Tab>\<C-B>#\<CR>", 'xnt') |
627 assert_equal('#Cmd abcd', @:) | 627 assert_equal('#Cmd abcd', @:) |
628 END | 628 END |
629 CheckScriptSuccess(lines) | 629 v9.CheckScriptSuccess(lines) |
630 | 630 |
631 delcommand Cmd | 631 delcommand Cmd |
632 delete('Xscript.vim') | 632 delete('Xscript.vim') |
633 enddef | 633 enddef |
634 | 634 |
663 assert_equal('no', g:completion_loaded) | 663 assert_equal('no', g:completion_loaded) |
664 feedkeys("i\<C-X>\<C-T>\<C-N>\<Esc>", 'xt') | 664 feedkeys("i\<C-X>\<C-T>\<C-N>\<Esc>", 'xt') |
665 assert_equal('experiment', getline(1)) | 665 assert_equal('experiment', getline(1)) |
666 assert_equal('yes', g:completion_loaded) | 666 assert_equal('yes', g:completion_loaded) |
667 END | 667 END |
668 CheckScriptSuccess(lines) | 668 v9.CheckScriptSuccess(lines) |
669 | 669 |
670 set thesaurusfunc= | 670 set thesaurusfunc= |
671 bwipe! | 671 bwipe! |
672 delete('Xdir', 'rf') | 672 delete('Xdir', 'rf') |
673 &rtp = save_rtp | 673 &rtp = save_rtp |
696 return 'g@' | 696 return 'g@' |
697 enddef | 697 enddef |
698 feedkeys("\<F3>l", 'xt') | 698 feedkeys("\<F3>l", 'xt') |
699 assert_equal('yes', g:opfunc_called) | 699 assert_equal('yes', g:opfunc_called) |
700 END | 700 END |
701 CheckScriptSuccess(lines) | 701 v9.CheckScriptSuccess(lines) |
702 | 702 |
703 set opfunc= | 703 set opfunc= |
704 bwipe! | 704 bwipe! |
705 delete('Xdir', 'rf') | 705 delete('Xdir', 'rf') |
706 nunmap <F3> | 706 nunmap <F3> |
730 return 'g@' | 730 return 'g@' |
731 enddef | 731 enddef |
732 feedkeys("\<F3>l", 'xt') | 732 feedkeys("\<F3>l", 'xt') |
733 assert_equal('yes', g:opfunc_called) | 733 assert_equal('yes', g:opfunc_called) |
734 END | 734 END |
735 CheckScriptSuccess(lines) | 735 v9.CheckScriptSuccess(lines) |
736 | 736 |
737 set opfunc= | 737 set opfunc= |
738 bwipe! | 738 bwipe! |
739 delete('Xdir', 'rf') | 739 delete('Xdir', 'rf') |
740 nunmap <F3> | 740 nunmap <F3> |
767 &debug = 'throw' | 767 &debug = 'throw' |
768 END | 768 END |
769 new | 769 new |
770 setline(1, ['# one', 'text', '# two', 'text']) | 770 setline(1, ['# one', 'text', '# two', 'text']) |
771 g:fold_loaded = 'no' | 771 g:fold_loaded = 'no' |
772 CheckScriptSuccess(lines) | 772 v9.CheckScriptSuccess(lines) |
773 assert_equal('no', g:fold_loaded) | 773 assert_equal('no', g:fold_loaded) |
774 redraw | 774 redraw |
775 assert_equal('yes', g:fold_loaded) | 775 assert_equal('yes', g:fold_loaded) |
776 | 776 |
777 # Check that script context of 'foldexpr' is copied to another buffer. | 777 # Check that script context of 'foldexpr' is copied to another buffer. |
808 import './Xdiffexpr' as diff | 808 import './Xdiffexpr' as diff |
809 | 809 |
810 set diffexpr=diff.DiffExpr() | 810 set diffexpr=diff.DiffExpr() |
811 set diffopt=foldcolumn:0 | 811 set diffopt=foldcolumn:0 |
812 END | 812 END |
813 CheckScriptSuccess(lines) | 813 v9.CheckScriptSuccess(lines) |
814 | 814 |
815 enew! | 815 enew! |
816 call setline(1, ['one', 'two', 'three']) | 816 call setline(1, ['one', 'two', 'three']) |
817 diffthis | 817 diffthis |
818 | 818 |
840 lines =<< trim END | 840 lines =<< trim END |
841 vim9script | 841 vim9script |
842 import './Xpatchexpr' as patch | 842 import './Xpatchexpr' as patch |
843 set patchexpr=patch.TPatch() | 843 set patchexpr=patch.TPatch() |
844 END | 844 END |
845 CheckScriptSuccess(lines) | 845 v9.CheckScriptSuccess(lines) |
846 | 846 |
847 call writefile(['input file'], 'Xinput') | 847 call writefile(['input file'], 'Xinput') |
848 call writefile(['diff file'], 'Xdiff') | 848 call writefile(['diff file'], 'Xdiff') |
849 :%bwipe! | 849 :%bwipe! |
850 edit Xinput | 850 edit Xinput |
871 lines =<< trim END | 871 lines =<< trim END |
872 vim9script | 872 vim9script |
873 import './Xformatter' as format | 873 import './Xformatter' as format |
874 set formatexpr=format.MyFormatExpr() | 874 set formatexpr=format.MyFormatExpr() |
875 END | 875 END |
876 CheckScriptSuccess(lines) | 876 v9.CheckScriptSuccess(lines) |
877 | 877 |
878 new | 878 new |
879 setline(1, ['a', 'b', 'c']) | 879 setline(1, ['a', 'b', 'c']) |
880 normal gqG | 880 normal gqG |
881 assert_equal('yes', g:did_format) | 881 assert_equal('yes', g:did_format) |
901 lines =<< trim END | 901 lines =<< trim END |
902 vim9script | 902 vim9script |
903 import './Xinclude.vim' | 903 import './Xinclude.vim' |
904 set includeexpr=Xinclude.DoSub() | 904 set includeexpr=Xinclude.DoSub() |
905 END | 905 END |
906 CheckScriptSuccess(lines) | 906 v9.CheckScriptSuccess(lines) |
907 | 907 |
908 setline(1, ['Xthatfile']) | 908 setline(1, ['Xthatfile']) |
909 exe "normal \<C-W>f" | 909 exe "normal \<C-W>f" |
910 assert_equal('Xthisfile', expand('%')) | 910 assert_equal('Xthisfile', expand('%')) |
911 | 911 |
929 vim9script | 929 vim9script |
930 import './Xindenter' as indent | 930 import './Xindenter' as indent |
931 set indentexpr=indent.GetIndent() | 931 set indentexpr=indent.GetIndent() |
932 set debug=throw | 932 set debug=throw |
933 END | 933 END |
934 CheckScriptSuccess(lines) | 934 v9.CheckScriptSuccess(lines) |
935 | 935 |
936 new | 936 new |
937 setline(1, 'hello') | 937 setline(1, 'hello') |
938 normal == | 938 normal == |
939 assert_equal(' hello', getline(1)) | 939 assert_equal(' hello', getline(1)) |
962 lines =<< trim END | 962 lines =<< trim END |
963 vim9script | 963 vim9script |
964 import './Xprint.vim' | 964 import './Xprint.vim' |
965 set printexpr=Xprint.PrintFile() | 965 set printexpr=Xprint.PrintFile() |
966 END | 966 END |
967 CheckScriptSuccess(lines) | 967 v9.CheckScriptSuccess(lines) |
968 | 968 |
969 help | 969 help |
970 hardcopy dummy args | 970 hardcopy dummy args |
971 assert_equal('yes', g:printed) | 971 assert_equal('yes', g:printed) |
972 | 972 |
989 lines =<< trim END | 989 lines =<< trim END |
990 vim9script | 990 vim9script |
991 import './Xconvert.vim' as conv | 991 import './Xconvert.vim' as conv |
992 set charconvert=conv.MakeUpper() | 992 set charconvert=conv.MakeUpper() |
993 END | 993 END |
994 CheckScriptSuccess(lines) | 994 v9.CheckScriptSuccess(lines) |
995 | 995 |
996 writefile(['one', 'two'], 'Xfile') | 996 writefile(['one', 'two'], 'Xfile') |
997 new Xfile | 997 new Xfile |
998 write ++enc=ucase Xfile1 | 998 write ++enc=ucase Xfile1 |
999 assert_equal(['ONE', 'TWO'], readfile('Xfile1')) | 999 assert_equal(['ONE', 'TWO'], readfile('Xfile1')) |
1022 lines =<< trim END | 1022 lines =<< trim END |
1023 vim9script | 1023 vim9script |
1024 import './Xsuggest.vim' as sugg | 1024 import './Xsuggest.vim' as sugg |
1025 set spell spellsuggest=expr:sugg.MySuggest() | 1025 set spell spellsuggest=expr:sugg.MySuggest() |
1026 END | 1026 END |
1027 CheckScriptSuccess(lines) | 1027 v9.CheckScriptSuccess(lines) |
1028 | 1028 |
1029 set verbose=1 # report errors | 1029 set verbose=1 # report errors |
1030 call assert_equal(['Fox', 'Fop'], spellsuggest('Fo', 2)) | 1030 call assert_equal(['Fox', 'Fop'], spellsuggest('Fo', 2)) |
1031 | 1031 |
1032 delete('Xsuggest.vim') | 1032 delete('Xsuggest.vim') |
1054 enddef | 1054 enddef |
1055 | 1055 |
1056 import autoload 'shadow.vim' | 1056 import autoload 'shadow.vim' |
1057 assert_equal('Shadow()', shadow.Shadow()) | 1057 assert_equal('Shadow()', shadow.Shadow()) |
1058 END | 1058 END |
1059 CheckScriptSuccess(lines) | 1059 v9.CheckScriptSuccess(lines) |
1060 | 1060 |
1061 delfunc g:Shadow | 1061 delfunc g:Shadow |
1062 bwipe! | 1062 bwipe! |
1063 delete('Xdir', 'rf') | 1063 delete('Xdir', 'rf') |
1064 &rtp = save_rtp | 1064 &rtp = save_rtp |
1065 enddef | 1065 enddef |
1066 | 1066 |
1067 def Test_export_fails() | 1067 def Test_export_fails() |
1068 CheckScriptFailure(['export var some = 123'], 'E1042:') | 1068 v9.CheckScriptFailure(['export var some = 123'], 'E1042:') |
1069 CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:') | 1069 v9.CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:') |
1070 CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:') | 1070 v9.CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:') |
1071 | 1071 |
1072 assert_fails('export something', 'E1043:') | 1072 assert_fails('export something', 'E1043:') |
1073 enddef | 1073 enddef |
1074 | 1074 |
1075 func Test_import_fails_without_script() | 1075 func Test_import_fails_without_script() |
1086 return 0 | 1086 return 0 |
1087 enddef | 1087 enddef |
1088 END | 1088 END |
1089 writefile(export, 'XexportCmd.vim') | 1089 writefile(export, 'XexportCmd.vim') |
1090 | 1090 |
1091 var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', { | 1091 var buf = g:RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', { |
1092 rows: 6, wait_for_ruler: 0}) | 1092 rows: 6, wait_for_ruler: 0}) |
1093 WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5))) | 1093 g:WaitForAssert(() => assert_match('^E1094:', term_getline(buf, 5))) |
1094 | 1094 |
1095 delete('XexportCmd.vim') | 1095 delete('XexportCmd.vim') |
1096 StopVimInTerminal(buf) | 1096 g:StopVimInTerminal(buf) |
1097 enddef | 1097 enddef |
1098 | 1098 |
1099 def Test_vim9_reload_noclear() | 1099 def Test_vim9_reload_noclear() |
1100 var lines =<< trim END | 1100 var lines =<< trim END |
1101 vim9script | 1101 vim9script |
1346 def TestDirect() | 1346 def TestDirect() |
1347 var x: list<number> = filter.FastFilterDirect() | 1347 var x: list<number> = filter.FastFilterDirect() |
1348 enddef | 1348 enddef |
1349 TestDirect() | 1349 TestDirect() |
1350 END | 1350 END |
1351 CheckScriptSuccess(lines) | 1351 v9.CheckScriptSuccess(lines) |
1352 delete('Xfilter.vim') | 1352 delete('Xfilter.vim') |
1353 enddef | 1353 enddef |
1354 | 1354 |
1355 def Test_import_absolute() | 1355 def Test_import_absolute() |
1356 var import_lines = [ | 1356 var import_lines = [ |
1459 import './XexportedFunc.vim' as Func | 1459 import './XexportedFunc.vim' as Func |
1460 def Func() | 1460 def Func() |
1461 echo 'local to function' | 1461 echo 'local to function' |
1462 enddef | 1462 enddef |
1463 END | 1463 END |
1464 CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"') | 1464 v9.CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"') |
1465 | 1465 |
1466 lines =<< trim END | 1466 lines =<< trim END |
1467 vim9script | 1467 vim9script |
1468 import './XexportedFunc.vim' as Func | 1468 import './XexportedFunc.vim' as Func |
1469 def Outer() | 1469 def Outer() |
1471 echo 'local to function' | 1471 echo 'local to function' |
1472 enddef | 1472 enddef |
1473 enddef | 1473 enddef |
1474 defcompile | 1474 defcompile |
1475 END | 1475 END |
1476 CheckScriptFailure(lines, 'E1236:') | 1476 v9.CheckScriptFailure(lines, 'E1236:') |
1477 | 1477 |
1478 delete('XexportedFunc.vim') | 1478 delete('XexportedFunc.vim') |
1479 enddef | 1479 enddef |
1480 | 1480 |
1481 def Test_source_vim9_from_legacy() | 1481 def Test_source_vim9_from_legacy() |
1694 assert_equal('testmorename', prefixed.GetDef()) | 1694 assert_equal('testmorename', prefixed.GetDef()) |
1695 assert_equal('name', prefixed.name) | 1695 assert_equal('name', prefixed.name) |
1696 assert_equal('final', prefixed.fname) | 1696 assert_equal('final', prefixed.fname) |
1697 assert_equal('const', prefixed.cname) | 1697 assert_equal('const', prefixed.cname) |
1698 END | 1698 END |
1699 CheckScriptSuccess(lines) | 1699 v9.CheckScriptSuccess(lines) |
1700 # can source it again, autoload script not loaded again | 1700 # can source it again, autoload script not loaded again |
1701 g:expected_loaded = 1 | 1701 g:expected_loaded = 1 |
1702 CheckScriptSuccess(lines) | 1702 v9.CheckScriptSuccess(lines) |
1703 | 1703 |
1704 # can also get the items by autoload name | 1704 # can also get the items by autoload name |
1705 lines =<< trim END | 1705 lines =<< trim END |
1706 call assert_equal('test', prefixed#Gettest()) | 1706 call assert_equal('test', prefixed#Gettest()) |
1707 call assert_equal('testmorename', prefixed#GetFunc()) | 1707 call assert_equal('testmorename', prefixed#GetFunc()) |
1708 call assert_equal('name', prefixed#name) | 1708 call assert_equal('name', prefixed#name) |
1709 call assert_equal('final', prefixed#fname) | 1709 call assert_equal('final', prefixed#fname) |
1710 call assert_equal('const', prefixed#cname) | 1710 call assert_equal('const', prefixed#cname) |
1711 END | 1711 END |
1712 CheckScriptSuccess(lines) | 1712 v9.CheckScriptSuccess(lines) |
1713 | 1713 |
1714 unlet g:prefixed_loaded | 1714 unlet g:prefixed_loaded |
1715 unlet g:expected_loaded | 1715 unlet g:expected_loaded |
1716 delete('Xdir', 'rf') | 1716 delete('Xdir', 'rf') |
1717 &rtp = save_rtp | 1717 &rtp = save_rtp |
1735 var lines =<< trim END | 1735 var lines =<< trim END |
1736 vim9script | 1736 vim9script |
1737 import autoload 'notExport1.vim' | 1737 import autoload 'notExport1.vim' |
1738 echo notExport1.notFound | 1738 echo notExport1.notFound |
1739 END | 1739 END |
1740 CheckScriptFailure(lines, 'E1048: Item not found in script: notFound') | 1740 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notFound') |
1741 | 1741 |
1742 lines =<< trim END | 1742 lines =<< trim END |
1743 vim9script | 1743 vim9script |
1744 import autoload 'notExport1.vim' | 1744 import autoload 'notExport1.vim' |
1745 echo notExport1.notExported | 1745 echo notExport1.notExported |
1746 END | 1746 END |
1747 CheckScriptFailure(lines, 'E1049: Item not exported in script: notExported') | 1747 v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: notExported') |
1748 | 1748 |
1749 lines =<< trim END | 1749 lines =<< trim END |
1750 vim9script | 1750 vim9script |
1751 import autoload 'notExport1.vim' | 1751 import autoload 'notExport1.vim' |
1752 echo notExport1.NotFunc() | 1752 echo notExport1.NotFunc() |
1753 END | 1753 END |
1754 CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc') | 1754 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc') |
1755 | 1755 |
1756 lines =<< trim END | 1756 lines =<< trim END |
1757 vim9script | 1757 vim9script |
1758 import autoload 'notExport1.vim' | 1758 import autoload 'notExport1.vim' |
1759 echo notExport1.NotExport() | 1759 echo notExport1.NotExport() |
1760 END | 1760 END |
1761 CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport') | 1761 v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport') |
1762 | 1762 |
1763 lines =<< trim END | 1763 lines =<< trim END |
1764 vim9script | 1764 vim9script |
1765 import autoload 'notExport1.vim' | 1765 import autoload 'notExport1.vim' |
1766 echo 'text'->notExport1.NotFunc() | 1766 echo 'text'->notExport1.NotFunc() |
1767 END | 1767 END |
1768 CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc') | 1768 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: NotFunc') |
1769 | 1769 |
1770 lines =<< trim END | 1770 lines =<< trim END |
1771 vim9script | 1771 vim9script |
1772 import autoload 'notExport1.vim' | 1772 import autoload 'notExport1.vim' |
1773 echo 'text'->notExport1.NotExport() | 1773 echo 'text'->notExport1.NotExport() |
1774 END | 1774 END |
1775 CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport') | 1775 v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: NotExport') |
1776 | 1776 |
1777 # using a :def function we use a different autoload script every time so that | 1777 # using a :def function we use a different autoload script every time so that |
1778 # the function is compiled without the script loaded | 1778 # the function is compiled without the script loaded |
1779 writefile(exportLines, 'Xdir/autoload/notExport2.vim') | 1779 writefile(exportLines, 'Xdir/autoload/notExport2.vim') |
1780 lines =<< trim END | 1780 lines =<< trim END |
1783 def Testit() | 1783 def Testit() |
1784 echo notExport2.notFound | 1784 echo notExport2.notFound |
1785 enddef | 1785 enddef |
1786 Testit() | 1786 Testit() |
1787 END | 1787 END |
1788 CheckScriptFailure(lines, 'E1048: Item not found in script: notExport2#notFound') | 1788 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notExport2#notFound') |
1789 | 1789 |
1790 writefile(exportLines, 'Xdir/autoload/notExport3.vim') | 1790 writefile(exportLines, 'Xdir/autoload/notExport3.vim') |
1791 lines =<< trim END | 1791 lines =<< trim END |
1792 vim9script | 1792 vim9script |
1793 import autoload 'notExport3.vim' | 1793 import autoload 'notExport3.vim' |
1795 echo notExport3.notExported | 1795 echo notExport3.notExported |
1796 enddef | 1796 enddef |
1797 Testit() | 1797 Testit() |
1798 END | 1798 END |
1799 # don't get E1049 because it is too complicated to figure out | 1799 # don't get E1049 because it is too complicated to figure out |
1800 CheckScriptFailure(lines, 'E1048: Item not found in script: notExport3#notExported') | 1800 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: notExport3#notExported') |
1801 | 1801 |
1802 writefile(exportLines, 'Xdir/autoload/notExport4.vim') | 1802 writefile(exportLines, 'Xdir/autoload/notExport4.vim') |
1803 lines =<< trim END | 1803 lines =<< trim END |
1804 vim9script | 1804 vim9script |
1805 import autoload 'notExport4.vim' | 1805 import autoload 'notExport4.vim' |
1806 def Testit() | 1806 def Testit() |
1807 echo notExport4.NotFunc() | 1807 echo notExport4.NotFunc() |
1808 enddef | 1808 enddef |
1809 Testit() | 1809 Testit() |
1810 END | 1810 END |
1811 CheckScriptFailure(lines, 'E117: Unknown function: notExport4#NotFunc') | 1811 v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport4#NotFunc') |
1812 | 1812 |
1813 writefile(exportLines, 'Xdir/autoload/notExport5.vim') | 1813 writefile(exportLines, 'Xdir/autoload/notExport5.vim') |
1814 lines =<< trim END | 1814 lines =<< trim END |
1815 vim9script | 1815 vim9script |
1816 import autoload 'notExport5.vim' | 1816 import autoload 'notExport5.vim' |
1817 def Testit() | 1817 def Testit() |
1818 echo notExport5.NotExport() | 1818 echo notExport5.NotExport() |
1819 enddef | 1819 enddef |
1820 Testit() | 1820 Testit() |
1821 END | 1821 END |
1822 CheckScriptFailure(lines, 'E117: Unknown function: notExport5#NotExport') | 1822 v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport5#NotExport') |
1823 | 1823 |
1824 writefile(exportLines, 'Xdir/autoload/notExport6.vim') | 1824 writefile(exportLines, 'Xdir/autoload/notExport6.vim') |
1825 lines =<< trim END | 1825 lines =<< trim END |
1826 vim9script | 1826 vim9script |
1827 import autoload 'notExport6.vim' | 1827 import autoload 'notExport6.vim' |
1828 def Testit() | 1828 def Testit() |
1829 echo 'text'->notExport6.NotFunc() | 1829 echo 'text'->notExport6.NotFunc() |
1830 enddef | 1830 enddef |
1831 Testit() | 1831 Testit() |
1832 END | 1832 END |
1833 CheckScriptFailure(lines, 'E117: Unknown function: notExport6#NotFunc') | 1833 v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport6#NotFunc') |
1834 | 1834 |
1835 writefile(exportLines, 'Xdir/autoload/notExport7.vim') | 1835 writefile(exportLines, 'Xdir/autoload/notExport7.vim') |
1836 lines =<< trim END | 1836 lines =<< trim END |
1837 vim9script | 1837 vim9script |
1838 import autoload 'notExport7.vim' | 1838 import autoload 'notExport7.vim' |
1839 def Testit() | 1839 def Testit() |
1840 echo 'text'->notExport7.NotExport() | 1840 echo 'text'->notExport7.NotExport() |
1841 enddef | 1841 enddef |
1842 Testit() | 1842 Testit() |
1843 END | 1843 END |
1844 CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport') | 1844 v9.CheckScriptFailure(lines, 'E117: Unknown function: notExport7#NotExport') |
1845 | 1845 |
1846 delete('Xdir', 'rf') | 1846 delete('Xdir', 'rf') |
1847 &rtp = save_rtp | 1847 &rtp = save_rtp |
1848 enddef | 1848 enddef |
1849 | 1849 |
1878 call another.Getother() | 1878 call another.Getother() |
1879 assert_equal('other', g:result) | 1879 assert_equal('other', g:result) |
1880 | 1880 |
1881 assert_equal('arg', call('another.RetArg', ['arg'])) | 1881 assert_equal('arg', call('another.RetArg', ['arg'])) |
1882 END | 1882 END |
1883 CheckScriptSuccess(lines) | 1883 v9.CheckScriptSuccess(lines) |
1884 | 1884 |
1885 unlet g:result | 1885 unlet g:result |
1886 delete('Xdir', 'rf') | 1886 delete('Xdir', 'rf') |
1887 &rtp = save_rtp | 1887 &rtp = save_rtp |
1888 enddef | 1888 enddef |
2023 vim9script | 2023 vim9script |
2024 def Xscriptname#Func() | 2024 def Xscriptname#Func() |
2025 enddef | 2025 enddef |
2026 END | 2026 END |
2027 writefile(lines, 'Xscriptname.vim') | 2027 writefile(lines, 'Xscriptname.vim') |
2028 CheckScriptFailure(lines, 'E1263:') | 2028 v9.CheckScriptFailure(lines, 'E1263:') |
2029 | 2029 |
2030 delete('Xscriptname.vim') | 2030 delete('Xscriptname.vim') |
2031 enddef | 2031 enddef |
2032 | 2032 |
2033 def Test_import_autoload_postponed() | 2033 def Test_import_autoload_postponed() |
2054 echo postponed.variable | 2054 echo postponed.variable |
2055 echo postponed.Function() | 2055 echo postponed.Function() |
2056 enddef | 2056 enddef |
2057 defcompile | 2057 defcompile |
2058 END | 2058 END |
2059 CheckScriptSuccess(lines) | 2059 v9.CheckScriptSuccess(lines) |
2060 assert_false(exists('g:loaded_postponed')) | 2060 assert_false(exists('g:loaded_postponed')) |
2061 CheckScriptSuccess(lines + ['Tryit()']) | 2061 v9.CheckScriptSuccess(lines + ['Tryit()']) |
2062 assert_equal('true', g:loaded_postponed) | 2062 assert_equal('true', g:loaded_postponed) |
2063 | 2063 |
2064 unlet g:loaded_postponed | 2064 unlet g:loaded_postponed |
2065 delete('Xdir', 'rf') | 2065 delete('Xdir', 'rf') |
2066 &rtp = save_rtp | 2066 &rtp = save_rtp |
2092 def Tryit() | 2092 def Tryit() |
2093 echo override.doesNotExist | 2093 echo override.doesNotExist |
2094 enddef | 2094 enddef |
2095 defcompile | 2095 defcompile |
2096 END | 2096 END |
2097 CheckScriptFailure(lines, 'E1048: Item not found in script: doesNotExist', 1) | 2097 v9.CheckScriptFailure(lines, 'E1048: Item not found in script: doesNotExist', 1) |
2098 | 2098 |
2099 test_override('autoload', 0) | 2099 test_override('autoload', 0) |
2100 unlet g:loaded_override | 2100 unlet g:loaded_override |
2101 delete('Xdir', 'rf') | 2101 delete('Xdir', 'rf') |
2102 &rtp = save_rtp | 2102 &rtp = save_rtp |
2128 | 2128 |
2129 nnoremap <silent> <expr> tt toggle.Toggle() | 2129 nnoremap <silent> <expr> tt toggle.Toggle() |
2130 nnoremap <silent> xx <ScriptCmd>toggle.Doit()<CR> | 2130 nnoremap <silent> xx <ScriptCmd>toggle.Doit()<CR> |
2131 nnoremap <silent> yy <Cmd>toggle.Doit()<CR> | 2131 nnoremap <silent> yy <Cmd>toggle.Doit()<CR> |
2132 END | 2132 END |
2133 CheckScriptSuccess(lines) | 2133 v9.CheckScriptSuccess(lines) |
2134 assert_false(exists("g:toggle_loaded")) | 2134 assert_false(exists("g:toggle_loaded")) |
2135 assert_false(exists("g:toggle_called")) | 2135 assert_false(exists("g:toggle_called")) |
2136 assert_match('\d A: \f*[/\\]toggle.vim', execute('scriptnames')) | 2136 assert_match('\d A: \f*[/\\]toggle.vim', execute('scriptnames')) |
2137 | 2137 |
2138 feedkeys("tt", 'xt') | 2138 feedkeys("tt", 'xt') |
2157 def Test_vim9script_autoload_fails() | 2157 def Test_vim9script_autoload_fails() |
2158 var lines =<< trim END | 2158 var lines =<< trim END |
2159 vim9script autoload | 2159 vim9script autoload |
2160 var n = 0 | 2160 var n = 0 |
2161 END | 2161 END |
2162 CheckScriptFailure(lines, 'E475: Invalid argument: autoload') | 2162 v9.CheckScriptFailure(lines, 'E475: Invalid argument: autoload') |
2163 | 2163 |
2164 lines =<< trim END | 2164 lines =<< trim END |
2165 vim9script noclear noclear | 2165 vim9script noclear noclear |
2166 var n = 0 | 2166 var n = 0 |
2167 END | 2167 END |
2168 CheckScriptFailure(lines, 'E983: Duplicate argument: noclear') | 2168 v9.CheckScriptFailure(lines, 'E983: Duplicate argument: noclear') |
2169 enddef | 2169 enddef |
2170 | 2170 |
2171 def Test_import_autoload_fails() | 2171 def Test_import_autoload_fails() |
2172 var lines =<< trim END | 2172 var lines =<< trim END |
2173 vim9script | 2173 vim9script |
2174 import autoload autoload 'prefixed.vim' | 2174 import autoload autoload 'prefixed.vim' |
2175 END | 2175 END |
2176 CheckScriptFailure(lines, 'E121: Undefined variable: autoload') | 2176 v9.CheckScriptFailure(lines, 'E121: Undefined variable: autoload') |
2177 | 2177 |
2178 lines =<< trim END | 2178 lines =<< trim END |
2179 vim9script | 2179 vim9script |
2180 import autoload './doesNotExist.vim' | 2180 import autoload './doesNotExist.vim' |
2181 END | 2181 END |
2182 CheckScriptFailure(lines, 'E1264:') | 2182 v9.CheckScriptFailure(lines, 'E1264:') |
2183 | 2183 |
2184 lines =<< trim END | 2184 lines =<< trim END |
2185 vim9script | 2185 vim9script |
2186 import autoload '/dir/doesNotExist.vim' | 2186 import autoload '/dir/doesNotExist.vim' |
2187 END | 2187 END |
2188 CheckScriptFailure(lines, 'E1264:') | 2188 v9.CheckScriptFailure(lines, 'E1264:') |
2189 | 2189 |
2190 lines =<< trim END | 2190 lines =<< trim END |
2191 vim9script | 2191 vim9script |
2192 import autoload 'doesNotExist.vim' | 2192 import autoload 'doesNotExist.vim' |
2193 END | 2193 END |
2194 CheckScriptFailure(lines, 'E1053: Could not import "doesNotExist.vim"') | 2194 v9.CheckScriptFailure(lines, 'E1053: Could not import "doesNotExist.vim"') |
2195 enddef | 2195 enddef |
2196 | 2196 |
2197 " test disassembling an auto-loaded function starting with "debug" | 2197 " test disassembling an auto-loaded function starting with "debug" |
2198 def Test_vim9_autoload_disass() | 2198 def Test_vim9_autoload_disass() |
2199 mkdir('Xdir/autoload', 'p') | 2199 mkdir('Xdir/autoload', 'p') |
2221 assert_equal('debug', debugit#test()) | 2221 assert_equal('debug', debugit#test()) |
2222 disass debugit#test | 2222 disass debugit#test |
2223 assert_equal('profile', profileit#test()) | 2223 assert_equal('profile', profileit#test()) |
2224 disass profileit#test | 2224 disass profileit#test |
2225 END | 2225 END |
2226 CheckScriptSuccess(lines) | 2226 v9.CheckScriptSuccess(lines) |
2227 | 2227 |
2228 delete('Xdir', 'rf') | 2228 delete('Xdir', 'rf') |
2229 &rtp = save_rtp | 2229 &rtp = save_rtp |
2230 enddef | 2230 enddef |
2231 | 2231 |
2272 lines =<< trim END | 2272 lines =<< trim END |
2273 vim9script | 2273 vim9script |
2274 import autoload 'CaseSensitive.vim' | 2274 import autoload 'CaseSensitive.vim' |
2275 assert_equal('done', CaseSensitive.CaseSensitive()) | 2275 assert_equal('done', CaseSensitive.CaseSensitive()) |
2276 END | 2276 END |
2277 CheckScriptSuccess(lines) | 2277 v9.CheckScriptSuccess(lines) |
2278 | 2278 |
2279 if !has('fname_case') | 2279 if !has('fname_case') |
2280 lines =<< trim END | 2280 lines =<< trim END |
2281 vim9script | 2281 vim9script |
2282 import autoload 'CaseSensitive.vim' | 2282 import autoload 'CaseSensitive.vim' |
2283 import autoload 'casesensitive.vim' | 2283 import autoload 'casesensitive.vim' |
2284 END | 2284 END |
2285 CheckScriptFailure(lines, 'E1262:') | 2285 v9.CheckScriptFailure(lines, 'E1262:') |
2286 endif | 2286 endif |
2287 | 2287 |
2288 delete('Xdir', 'rf') | 2288 delete('Xdir', 'rf') |
2289 &rtp = save_rtp | 2289 &rtp = save_rtp |
2290 enddef | 2290 enddef |
2318 call crash#func() | 2318 call crash#func() |
2319 call writefile(['ok'], 'Xdidit') | 2319 call writefile(['ok'], 'Xdidit') |
2320 qall! | 2320 qall! |
2321 END | 2321 END |
2322 writefile(lines, 'Xscript') | 2322 writefile(lines, 'Xscript') |
2323 RunVim([], [], '-S Xscript') | 2323 g:RunVim([], [], '-S Xscript') |
2324 assert_equal(['ok'], readfile('Xdidit')) | 2324 assert_equal(['ok'], readfile('Xdidit')) |
2325 | 2325 |
2326 delete('Xdidit') | 2326 delete('Xdidit') |
2327 delete('Xscript') | 2327 delete('Xscript') |
2328 delete('Xruntime', 'rf') | 2328 delete('Xruntime', 'rf') |
2329 | 2329 |
2330 lines =<< trim END | 2330 lines =<< trim END |
2331 vim9script | 2331 vim9script |
2332 var foo#bar = 'asdf' | 2332 var foo#bar = 'asdf' |
2333 END | 2333 END |
2334 CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2) | 2334 v9.CheckScriptFailure(lines, 'E461: Illegal variable name: foo#bar', 2) |
2335 enddef | 2335 enddef |
2336 | 2336 |
2337 | 2337 |
2338 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker | 2338 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |