annotate src/testdir/test_vim9_script.vim @ 19726:ad37a198a708 v8.2.0419

patch 8.2.0419: various memory leaks in Vim9 script code Commit: https://github.com/vim/vim/commit/20431c9dbb592ebe0666bf042af7d2b373107372 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 20 18:39:46 2020 +0100 patch 8.2.0419: various memory leaks in Vim9 script code Problem: Various memory leaks in Vim9 script code. Solution: Fix the leaks. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/5814)
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 Mar 2020 18:45:04 +0100
parents 2fee087c94cb
children 41a1ea967a97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test various aspects of the Vim9 script language.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
3 source check.vim
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
4 source view_util.vim
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
5
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 " Check that "lines" inside ":def" results in an "error" message.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func CheckDefFailure(lines, error)
19185
17d878a2ddaa patch 8.2.0151: detecting a script was already sourced is unreliable
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
8 call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 call assert_fails('so Xdef', a:error, a:lines)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 call delete('Xdef')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 func CheckScriptFailure(lines, error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 call writefile(a:lines, 'Xdef')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 call assert_fails('so Xdef', a:error, a:lines)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 call delete('Xdef')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 def Test_syntax()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 let var = 234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 let other: list<string> = ['asdf']
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 func Test_def_basic()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 def SomeFunc(): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 return 'yes'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 call assert_equal('yes', SomeFunc())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
31 let s:appendToMe = 'xxx'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
32 let s:addToMe = 111
19449
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
33 let g:existing = 'yes'
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
34
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 def Test_assignment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let bool1: bool = true
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 assert_equal(v:true, bool1)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 let bool2: bool = false
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 assert_equal(v:false, bool2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
19521
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
41 let list1: list<bool> = [false, true, false]
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 let list2: list<number> = [1, 2, 3]
19521
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
43 let list3: list<string> = ['sdf', 'asdf']
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
44 let list4: list<any> = ['yes', true, 1234]
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
45 let list5: list<blob> = [0z01, 0z02]
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46
19467
f41e46f02c8c patch 8.2.0291: Vim9: assigning [] to list<string> doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 19459
diff changeset
47 let listS: list<string> = []
f41e46f02c8c patch 8.2.0291: Vim9: assigning [] to list<string> doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 19459
diff changeset
48 let listN: list<number> = []
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
19521
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
50 let dict1: dict<bool> = #{one: false, two: true}
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let dict2: dict<number> = #{one: 1, two: 2}
19521
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
52 let dict3: dict<string> = #{key: 'value'}
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
53 let dict4: dict<any> = #{one: 1, two: '2'}
860b39ed0e0b patch 8.2.0318: Vim9: types not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19511
diff changeset
54 let dict5: dict<blob> = #{one: 0z01, tw: 0z02}
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
55
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
56 if has('channel')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
57 let chan1: channel
19564
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
58 let job1: job
19572
6b6e97d0185e patch 8.2.0343: Vim9: using wrong instruction, limited test coverage
Bram Moolenaar <Bram@vim.org>
parents: 19568
diff changeset
59 let job2: job = job_start('willfail')
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
60 endif
19564
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
61 if has('float')
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
62 let float1: float = 3.4
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
63 endif
19566
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19564
diff changeset
64 let funky1: func
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19564
diff changeset
65 let funky2: func = function('len')
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19564
diff changeset
66 let party1: partial
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19564
diff changeset
67 let party2: partial = funcref('Test_syntax')
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
68
19579
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19572
diff changeset
69 " type becomes list<any>
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19572
diff changeset
70 let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
71 " type becomes dict<any>
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
72 let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
19579
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19572
diff changeset
73
19449
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
74 g:newvar = 'new'
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
75 assert_equal('new', g:newvar)
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
76
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
77 assert_equal('yes', g:existing)
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
78 g:existing = 'no'
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
79 assert_equal('no', g:existing)
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
80
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
81 v:char = 'abc'
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
82 assert_equal('abc', v:char)
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
83
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
84 $ENVVAR = 'foobar'
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
85 assert_equal('foobar', $ENVVAR)
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
86 $ENVVAR = ''
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
87
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
88 s:appendToMe ..= 'yyy'
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
89 assert_equal('xxxyyy', s:appendToMe)
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
90 s:addToMe += 222
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
91 assert_equal(333, s:addToMe)
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19451
diff changeset
92 s:newVar = 'new'
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19451
diff changeset
93 assert_equal('new', s:newVar)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 func Test_assignment_failure()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 call CheckDefFailure(['let var=234'], 'E1004:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 call CheckDefFailure(['let var =234'], 'E1004:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 call CheckDefFailure(['let var= 234'], 'E1004:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 call CheckDefFailure(['let true = 1'], 'E1034:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 call CheckDefFailure(['let false = 1'], 'E1034:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 call CheckDefFailure(['let var: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 call CheckDefFailure(['let var: dict<string> = #{key: 123}'], 'expected dict<string> but got dict<number>')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 call CheckDefFailure(['let var: dict<number> = #{key: "xx"}'], 'expected dict<number> but got dict<string>')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 call CheckDefFailure(['let var = feedkeys("0")'], 'E1031:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 call CheckDefFailure(['let var: number = feedkeys("0")'], 'expected number but got void')
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
112
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
113 call CheckDefFailure(['let var: dict <number>'], 'E1007:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
114 call CheckDefFailure(['let var: dict<number'], 'E1009:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
115
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
116 call CheckDefFailure(['let var: ally'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
117 call CheckDefFailure(['let var: bram'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
118 call CheckDefFailure(['let var: cathy'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
119 call CheckDefFailure(['let var: dom'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
120 call CheckDefFailure(['let var: freddy'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
121 call CheckDefFailure(['let var: john'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
122 call CheckDefFailure(['let var: larry'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
123 call CheckDefFailure(['let var: ned'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
124 call CheckDefFailure(['let var: pam'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
125 call CheckDefFailure(['let var: sam'], 'E1010:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
126 call CheckDefFailure(['let var: vim'], 'E1010:')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 func Test_const()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 call CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 call CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 call CheckDefFailure(['const two'], 'E1021:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 def Test_block()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 let outer = 1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 let inner = 2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 assert_equal(1, outer)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 assert_equal(2, inner)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 assert_equal(1, outer)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 func Test_block_failure()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 call CheckDefFailure(['{', 'let inner = 1', '}', 'echo inner'], 'E1001:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 def ReturnString(): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return 'string'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 def ReturnNumber(): number
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 return 123
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
19469
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
157 let g:notNumber = 'string'
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
158
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
159 def ReturnGlobal(): number
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
160 return g:notNumber
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
161 enddef
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
162
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 def Test_return_string()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 assert_equal('string', ReturnString())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 assert_equal(123, ReturnNumber())
19469
55656a51d2af patch 8.2.0292: Vim9: CHECKNR and CHECKTYPE instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
166 assert_fails('call ReturnGlobal()', 'E1029: Expected number but got string')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 func Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 let g:counter += 1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 def Test_call_ufunc_count()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 g:counter = 1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 " works with and without :call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 assert_equal(4, g:counter)
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
180 call assert_equal(4, g:counter)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 unlet g:counter
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 def MyVarargs(arg: string, ...rest: list<string>): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 let res = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 for s in rest
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 res ..= ',' .. s
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 endfor
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 return res
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 def Test_call_varargs()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 assert_equal('one', MyVarargs('one'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 assert_equal('one,two', MyVarargs('one', 'two'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 assert_equal('one,two,three', MyVarargs('one', 'two', 'three'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
198 def MyDefaultArgs(name = 'string'): string
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
199 return name
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
200 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
201
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
202 def Test_call_default_args()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
203 assert_equal('string', MyDefaultArgs())
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
204 assert_equal('one', MyDefaultArgs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
205 assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
206 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
207
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
208 func Test_call_default_args_from_func()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
209 call assert_equal('string', MyDefaultArgs())
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
210 call assert_equal('one', MyDefaultArgs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
211 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
212 endfunc
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
213
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
214 func TakesOneArg(arg)
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
215 echo a:arg
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
216 endfunc
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
217
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
218 def Test_call_wrong_arg_count()
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
219 call CheckDefFailure(['TakesOneArg()'], 'E119:')
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
220 call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:')
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
221 enddef
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
222
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
223 " Default arg and varargs
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
224 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
225 let res = one .. ',' .. two
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
226 for s in rest
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
227 res ..= ',' .. s
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
228 endfor
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
229 return res
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
230 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
231
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
232 def Test_call_def_varargs()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
233 call assert_fails('call MyDefVarargs()', 'E119:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
234 assert_equal('one,foo', MyDefVarargs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
235 assert_equal('one,two', MyDefVarargs('one', 'two'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
236 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
237 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
238
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
239 def Test_using_var_as_arg()
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
240 call writefile(['def Func(x: number)', 'let x = 234', 'enddef'], 'Xdef')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
241 call assert_fails('so Xdef', 'E1006:')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
242 call delete('Xdef')
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
243 enddef
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19532
diff changeset
244
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
245 def Test_call_func_defined_later()
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
246 call assert_equal('one', DefinedLater('one'))
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
247 call assert_fails('call NotDefined("one")', 'E117:')
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
248 enddef
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
249
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
250 func DefinedLater(arg)
19295
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
251 return a:arg
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
252 endfunc
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
253
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
254 def FuncWithForwardCall()
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
255 return DefinedEvenLater("yes")
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
256 enddef
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
257
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
258 def DefinedEvenLater(arg: string): string
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
259 return arg
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
260 enddef
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
261
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
262 def Test_error_in_nested_function()
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
263 " Error in called function requires unwinding the call stack.
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
264 assert_fails('call FuncWithForwardCall()', 'E1029')
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
265 enddef
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
266
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 def Test_return_type_wrong()
19185
17d878a2ddaa patch 8.2.0151: detecting a script was already sourced is unreliable
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
268 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
17d878a2ddaa patch 8.2.0151: detecting a script was already sourced is unreliable
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
269 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number')
17d878a2ddaa patch 8.2.0151: detecting a script was already sourced is unreliable
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
270 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string')
17d878a2ddaa patch 8.2.0151: detecting a script was already sourced is unreliable
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
271 CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
274 def Test_arg_type_wrong()
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
275 CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
276 enddef
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
277
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 def Test_try_catch()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 let l = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 try
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 add(l, '1')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 throw 'wrong'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 add(l, '2')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 catch
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 add(l, v:exception)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 add(l, '3')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 endtry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 assert_equal(['1', 'wrong', '3'], l)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291
19445
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
292 def ThrowFromDef()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
293 throw 'getout'
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
294 enddef
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
295
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
296 func CatchInFunc()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
297 try
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
298 call ThrowFromDef()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
299 catch
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
300 let g:thrown_func = v:exception
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
301 endtry
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
302 endfunc
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
303
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
304 def CatchInDef()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
305 try
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
306 ThrowFromDef()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
307 catch
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
308 g:thrown_def = v:exception
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
309 endtry
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
310 enddef
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
311
19459
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
312 def ReturnFinally(): string
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
313 try
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
314 return 'intry'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
315 finally
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
316 g:in_finally = 'finally'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
317 endtry
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
318 return 'end'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
319 enddef
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
320
19445
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
321 def Test_try_catch_nested()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
322 CatchInFunc()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
323 assert_equal('getout', g:thrown_func)
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
324
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
325 CatchInDef()
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
326 assert_equal('getout', g:thrown_def)
19459
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
327
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
328 assert_equal('intry', ReturnFinally())
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
329 assert_equal('finally', g:in_finally)
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
330 enddef
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
331
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
332 def Test_try_catch_match()
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
333 let seq = 'a'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
334 try
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
335 throw 'something'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
336 catch /nothing/
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
337 seq ..= 'x'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
338 catch /some/
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
339 seq ..= 'b'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
340 catch /asdf/
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
341 seq ..= 'x'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
342 finally
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
343 seq ..= 'c'
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
344 endtry
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
345 assert_equal('abc', seq)
19445
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
346 enddef
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
347
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 let s:export_script_lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 let name: string = 'bob'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 def Concat(arg: string): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 return name .. arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 let g:result = Concat('bie')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 let g:localname = name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 export const CONST = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 export let exported = 9876
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
359 export let exp_name = 'John'
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 export def Exported(): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 return 'Exported'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
365 def Test_vim9_import_export()
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 let import_script_lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 import {exported, Exported} from './Xexport.vim'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 g:imported = exported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
370 exported += 3
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
371 g:imported_added = exported
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 g:imported_func = Exported()
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
373
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
374 import {exp_name} from './Xexport.vim'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
375 g:imported_name = exp_name
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
376 exp_name ..= ' Doe'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
377 g:imported_name_appended = exp_name
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
378 g:imported_later = exported
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 writefile(import_script_lines, 'Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 writefile(s:export_script_lines, 'Xexport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 assert_equal('bobbie', g:result)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 assert_equal('bob', g:localname)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 assert_equal(9876, g:imported)
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
389 assert_equal(9879, g:imported_added)
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
390 assert_equal(9879, g:imported_later)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 assert_equal('Exported', g:imported_func)
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
392 assert_equal('John', g:imported_name)
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
393 assert_equal('John Doe', g:imported_name_appended)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 assert_false(exists('g:name'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 unlet g:result
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 unlet g:localname
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 unlet g:imported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
399 unlet g:imported_added
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
400 unlet g:imported_later
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 unlet g:imported_func
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
402 unlet g:imported_name g:imported_name_appended
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 delete('Ximport.vim')
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
404
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
405 let import_in_def_lines =<< trim END
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
406 vim9script
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
407 def ImportInDef()
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
408 import exported from './Xexport.vim'
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
409 g:imported = exported
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
410 exported += 7
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
411 g:imported_added = exported
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
412 enddef
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
413 ImportInDef()
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
414 END
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
415 writefile(import_in_def_lines, 'Ximport2.vim')
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
416 source Ximport2.vim
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
417 " TODO: this should be 9879
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
418 assert_equal(9876, g:imported)
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
419 assert_equal(9883, g:imported_added)
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
420 unlet g:imported
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
421 unlet g:imported_added
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
422 delete('Ximport2.vim')
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
423
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
424 let import_star_as_lines =<< trim END
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
425 vim9script
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
426 import * as Export from './Xexport.vim'
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
427 def UseExport()
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
428 g:imported = Export.exported
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
429 enddef
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
430 UseExport()
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
431 END
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
432 writefile(import_star_as_lines, 'Ximport.vim')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
433 source Ximport.vim
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
434 assert_equal(9883, g:imported)
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
435
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
436 let import_star_lines =<< trim END
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
437 vim9script
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
438 import * from './Xexport.vim'
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
439 g:imported = exported
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
440 END
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
441 writefile(import_star_lines, 'Ximport.vim')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
442 assert_fails('source Ximport.vim', 'E1045:')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
443
19511
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
444 " try to import something that exists but is not exported
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
445 let import_not_exported_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
446 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
447 import name from './Xexport.vim'
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
448 END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
449 writefile(import_not_exported_lines, 'Ximport.vim')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
450 assert_fails('source Ximport.vim', 'E1049:')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
451
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
452 " try to import something that is already defined
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
453 let import_already_defined =<< trim END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
454 vim9script
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
455 let exported = 'something'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
456 import exported from './Xexport.vim'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
457 END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
458 writefile(import_already_defined, 'Ximport.vim')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
459 assert_fails('source Ximport.vim', 'E1073:')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
460
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
461 " try to import something that is already defined
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
462 import_already_defined =<< trim END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
463 vim9script
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
464 let exported = 'something'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
465 import * as exported from './Xexport.vim'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
466 END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
467 writefile(import_already_defined, 'Ximport.vim')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
468 assert_fails('source Ximport.vim', 'E1073:')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
469
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
470 " try to import something that is already defined
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
471 import_already_defined =<< trim END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
472 vim9script
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
473 let exported = 'something'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
474 import {exported} from './Xexport.vim'
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
475 END
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
476 writefile(import_already_defined, 'Ximport.vim')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
477 assert_fails('source Ximport.vim', 'E1073:')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
478
19511
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
479 " import a very long name, requires making a copy
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
480 let import_long_name_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
481 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
482 import name012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 from './Xexport.vim'
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
483 END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
484 writefile(import_long_name_lines, 'Ximport.vim')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
485 assert_fails('source Ximport.vim', 'E1048:')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
486
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
487 let import_no_from_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
488 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
489 import name './Xexport.vim'
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
490 END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
491 writefile(import_no_from_lines, 'Ximport.vim')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
492 assert_fails('source Ximport.vim', 'E1070:')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
493
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
494 let import_invalid_string_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
495 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
496 import name from Xexport.vim
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
497 END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
498 writefile(import_invalid_string_lines, 'Ximport.vim')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
499 assert_fails('source Ximport.vim', 'E1071:')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
500
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
501 let import_wrong_name_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
502 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
503 import name from './XnoExport.vim'
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
504 END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
505 writefile(import_wrong_name_lines, 'Ximport.vim')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
506 assert_fails('source Ximport.vim', 'E1053:')
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
507
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
508 let import_missing_comma_lines =<< trim END
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
509 vim9script
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
510 import {exported name} from './Xexport.vim'
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
511 END
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
512 writefile(import_missing_comma_lines, 'Ximport3.vim')
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
513 assert_fails('source Ximport3.vim', 'E1046:')
19511
7e76d5fba19f patch 8.2.0313: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19509
diff changeset
514
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
515 delete('Ximport.vim')
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19593
diff changeset
516 delete('Ximport3.vim')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 delete('Xexport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518
19507
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
519 " Check that in a Vim9 script 'cpo' is set to the Vim default.
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
520 set cpo&vi
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
521 let cpo_before = &cpo
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
522 let lines =<< trim END
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
523 vim9script
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
524 g:cpo_in_vim9script = &cpo
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
525 END
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
526 writefile(lines, 'Xvim9_script')
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
527 source Xvim9_script
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
528 assert_equal(cpo_before, &cpo)
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
529 set cpo&vim
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
530 assert_equal(&cpo, g:cpo_in_vim9script)
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
531 delete('Xvim9_script')
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
532 enddef
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
533
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
534 def Test_vim9script_fails()
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 CheckScriptFailure(['scriptversion 2', 'vim9script'], 'E1039:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 CheckScriptFailure(['vim9script', 'scriptversion 2'], 'E1040:')
19507
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
537 CheckScriptFailure(['export let some = 123'], 'E1042:')
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19507
diff changeset
538 CheckScriptFailure(['import some from "./Xexport.vim"'], 'E1042:')
19507
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
539 CheckScriptFailure(['vim9script', 'export let g:some'], 'E1044:')
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
540 CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
541
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
542 assert_fails('vim9script', 'E1038')
65049a682574 patch 8.2.0311: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19497
diff changeset
543 assert_fails('export something', 'E1042')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 def Test_vim9script_call()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 let lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 def MyFunc(arg: string)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 var = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 MyFunc('foobar')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 assert_equal('foobar', var)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 let str = 'barfoo'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 str->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 assert_equal('barfoo', var)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 let g:value = 'value'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 g:value->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 assert_equal('value', var)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 let listvar = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 def ListFunc(arg: list<number>)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 listvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 [1, 2, 3]->ListFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 assert_equal([1, 2, 3], listvar)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 let dictvar = {}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 def DictFunc(arg: dict<number>)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 dictvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {'a': 1, 'b': 2}->DictFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 assert_equal(#{a: 1, b: 2}, dictvar)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 #{a: 3, b: 4}->DictFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 assert_equal(#{a: 3, b: 4}, dictvar)
19481
c27837cbe922 patch 8.2.0298: Vim9 script: cannot start command with a string constant
Bram Moolenaar <Bram@vim.org>
parents: 19473
diff changeset
579
c27837cbe922 patch 8.2.0298: Vim9 script: cannot start command with a string constant
Bram Moolenaar <Bram@vim.org>
parents: 19473
diff changeset
580 ('text')->MyFunc()
c27837cbe922 patch 8.2.0298: Vim9 script: cannot start command with a string constant
Bram Moolenaar <Bram@vim.org>
parents: 19473
diff changeset
581 assert_equal('text', var)
c27837cbe922 patch 8.2.0298: Vim9 script: cannot start command with a string constant
Bram Moolenaar <Bram@vim.org>
parents: 19473
diff changeset
582 ("some")->MyFunc()
c27837cbe922 patch 8.2.0298: Vim9 script: cannot start command with a string constant
Bram Moolenaar <Bram@vim.org>
parents: 19473
diff changeset
583 assert_equal('some', var)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 writefile(lines, 'Xcall.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 source Xcall.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 delete('Xcall.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 def Test_vim9script_call_fail_decl()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 let lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 def MyFunc(arg: string)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 let var = 123
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 writefile(lines, 'Xcall_decl.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 assert_fails('source Xcall_decl.vim', 'E1054:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 delete('Xcall_decl.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 def Test_vim9script_call_fail_const()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 let lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 const var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 def MyFunc(arg: string)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 var = 'asdf'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 writefile(lines, 'Xcall_const.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 assert_fails('source Xcall_const.vim', 'E46:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 delete('Xcall_const.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 def Test_vim9script_reload()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 let lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 const var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 def MyFunc(arg: string)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 let morelines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 let valtwo = 222
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 export def GetValtwo(): number
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 return valtwo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 writefile(lines + morelines, 'Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 let testlines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 def TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 import GetValtwo from './Xreload.vim'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 assert_equal(222, GetValtwo())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 writefile(testlines, 'Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 " test that when not using "morelines" valtwo is still defined
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 " need to source Xreload.vim again, import doesn't reload a script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 writefile(lines, 'Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 " cannot declare a var twice
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 let valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 writefile(lines, 'Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 assert_fails('source Xreload.vim', 'E1041:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 delete('Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 delete('Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 def Test_import_absolute()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 \ 'import exported from "' .. escape(getcwd(), '\') .. '/Xexport_abs.vim"',
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
670 \ 'def UseExported()',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
671 \ ' g:imported_abs = exported',
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
672 \ ' exported = 8888',
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
673 \ ' g:imported_after = exported',
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
674 \ 'enddef',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
675 \ 'UseExported()',
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
676 \ 'g:import_disassembled = execute("disass UseExported")',
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 \ ]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 writefile(import_lines, 'Ximport_abs.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 writefile(s:export_script_lines, 'Xexport_abs.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 source Ximport_abs.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 assert_equal(9876, g:imported_abs)
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
684 assert_equal(8888, g:imported_after)
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
685 assert_match('<SNR>\d\+_UseExported.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
686 \ .. 'g:imported_abs = exported.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
687 \ .. '0 LOADSCRIPT exported from .*Xexport_abs.vim.*'
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
688 \ .. '1 STOREG g:imported_abs.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
689 \ .. 'exported = 8888.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
690 \ .. '3 STORESCRIPT exported in .*Xexport_abs.vim.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
691 \ .. 'g:imported_after = exported.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
692 \ .. '4 LOADSCRIPT exported from .*Xexport_abs.vim.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
693 \ .. '5 STOREG g:imported_after.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
694 \, g:import_disassembled)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 unlet g:imported_abs
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
696 unlet g:import_disassembled
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 delete('Ximport_abs.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 delete('Xexport_abs.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 def Test_import_rtp()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 \ 'import exported from "Xexport_rtp.vim"',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 \ 'g:imported_rtp = exported',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 \ ]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 writefile(import_lines, 'Ximport_rtp.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 mkdir('import')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 writefile(s:export_script_lines, 'import/Xexport_rtp.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 let save_rtp = &rtp
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 &rtp = getcwd()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 source Ximport_rtp.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 &rtp = save_rtp
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 assert_equal(9876, g:imported_rtp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 unlet g:imported_rtp
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 delete('Ximport_rtp.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 delete('import/Xexport_rtp.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 delete('import', 'd')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 def Test_fixed_size_list()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 " will be allocated as one piece of memory, check that changes work
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 let l = [1, 2, 3, 4]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 l->remove(0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 l->add(5)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 l->insert(99, 1)
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
731 assert_equal([2, 99, 3, 4, 5], l)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
734 " Test that inside :function a Python function can be defined, :def is not
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
735 " recognized.
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
736 func Test_function_python()
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
737 CheckFeature python3
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
738 let py = 'python3'
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
739 execute py "<< EOF"
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
740 def do_something():
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
741 return 1
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
742 EOF
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
743 endfunc
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
744
19332
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
745 def IfElse(what: number): string
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
746 let res = ''
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
747 if what == 1
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
748 res = "one"
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
749 elseif what == 2
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
750 res = "two"
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
751 else
19332
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
752 res = "three"
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
753 endif
19332
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
754 return res
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
755 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
756
19332
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
757 def Test_if_elseif_else()
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
758 assert_equal('one', IfElse(1))
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
759 assert_equal('two', IfElse(2))
d6e8a9e80be4 patch 8.2.0224: compiling :elseif not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
760 assert_equal('three', IfElse(3))
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
761 enddef
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
762
19585
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
763 let g:bool_true = v:true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
764 let g:bool_false = v:false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
765
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
766 def Test_if_const_expr()
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
767 let res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
768 if true ? true : false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
769 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
770 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
771 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
772
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
773 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
774 if g:bool_true ? true : false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
775 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
776 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
777 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
778
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
779 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
780 if true ? g:bool_true : false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
781 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
782 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
783 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
784
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
785 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
786 if true ? true : g:bool_false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
787 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
788 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
789 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
790
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
791 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
792 if true ? false : true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
793 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
794 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
795 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
796
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
797 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
798 if false ? false : true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
799 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
800 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
801 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
802
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
803 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
804 if false ? true : false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
805 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
806 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
807 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
808
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
809 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
810 if true && true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
811 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
812 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
813 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
814
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
815 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
816 if true && false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
817 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
818 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
819 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
820
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
821 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
822 if g:bool_true && false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
823 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
824 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
825 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
826
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
827 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
828 if true && g:bool_false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
829 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
830 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
831 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
832
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
833 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
834 if false && false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
835 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
836 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
837 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
838
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
839 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
840 if true || false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
841 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
842 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
843 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
844
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
845 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
846 if g:bool_true || false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
847 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
848 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
849 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
850
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
851 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
852 if true || g:bool_false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
853 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
854 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
855 assert_equal(true, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
856
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
857 res = false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
858 if false || false
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
859 res = true
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
860 endif
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
861 assert_equal(false, res)
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
862
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
863 enddef
0303f920a7d4 patch 8.2.0349: Vim9: constant expression not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
864
19443
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
865 def Test_delfunc()
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
866 let lines =<< trim END
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
867 vim9script
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
868 def GoneSoon()
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
869 echo 'hello'
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
870 enddef
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
871
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
872 def CallGoneSoon()
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
873 GoneSoon()
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
874 enddef
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
875
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
876 delfunc GoneSoon
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
877 CallGoneSoon()
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
878 END
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
879 writefile(lines, 'XToDelFunc')
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
880 assert_fails('so XToDelFunc', 'E933')
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
881 assert_fails('so XToDelFunc', 'E933')
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
882
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
883 delete('XToDelFunc')
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
884 enddef
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
885
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
886 def Test_execute_cmd()
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
887 new
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
888 setline(1, 'default')
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
889 execute 'call setline(1, "execute-string")'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
890 assert_equal('execute-string', getline(1))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
891 let cmd1 = 'call setline(1,'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
892 let cmd2 = '"execute-var")'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
893 execute cmd1 cmd2
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
894 assert_equal('execute-var', getline(1))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
895 execute cmd1 cmd2 '|call setline(1, "execute-var-string")'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
896 assert_equal('execute-var-string', getline(1))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
897 let cmd_first = 'call '
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
898 let cmd_last = 'setline(1, "execute-var-var")'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
899 execute cmd_first .. cmd_last
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
900 assert_equal('execute-var-var', getline(1))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
901 bwipe!
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
902 enddef
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
903
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
904 def Test_echo_cmd()
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
905 echo 'something'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
906 assert_match('^something$', Screenline(&lines))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
907
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
908 let str1 = 'some'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
909 let str2 = 'more'
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
910 echo str1 str2
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
911 assert_match('^some more$', Screenline(&lines))
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
912 enddef
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
913
19568
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
914 def Test_for_outside_of_function()
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
915 let lines =<< trim END
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
916 vim9script
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
917 new
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
918 for var in range(0, 3)
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
919 append(line('$'), var)
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
920 endfor
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
921 assert_equal(['', '0', '1', '2', '3'], getline(1, '$'))
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
922 bwipe!
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
923 END
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
924 writefile(lines, 'Xvim9for.vim')
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
925 source Xvim9for.vim
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
926 delete('Xvim9for.vim')
c0749ad6c699 patch 8.2.0341: using ":for" in Vim9 script gives an error
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
927 enddef
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928
19593
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
929 def Test_while_loop()
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
930 let result = ''
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
931 let cnt = 0
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
932 while cnt < 555
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
933 if cnt == 3
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
934 break
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
935 endif
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
936 cnt += 1
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
937 if cnt == 2
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
938 continue
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
939 endif
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
940 result ..= cnt .. '_'
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
941 endwhile
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
942 assert_equal('1_3_', result)
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
943 enddef
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
944
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
945 def Test_interrupt_loop()
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
946 let x = 0
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
947 while 1
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
948 x += 1
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
949 if x == 100
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
950 feedkeys("\<C-C>", 'L')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
951 endif
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
952 endwhile
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
953 enddef
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
954
19593
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
955 def Test_substitute_cmd()
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
956 new
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
957 setline(1, 'something')
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
958 :substitute(some(other(
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
959 assert_equal('otherthing', getline(1))
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
960 bwipe!
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
961
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
962 " also when the context is Vim9 script
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
963 let lines =<< trim END
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
964 vim9script
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
965 new
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
966 setline(1, 'something')
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
967 :substitute(some(other(
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
968 assert_equal('otherthing', getline(1))
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
969 bwipe!
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
970 END
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
971 writefile(lines, 'Xvim9lines')
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
972 source Xvim9lines
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
973
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
974 delete('Xvim9lines')
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
975 enddef
043989a2f449 patch 8.2.0353: Vim9: while loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19585
diff changeset
976
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
977 def Test_redef_failure()
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
978 call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
979 so Xdef
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
980 call writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
981 so Xdef
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
982 call writefile(['def! Func0(): string', 'enddef'], 'Xdef')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
983 call assert_fails('so Xdef', 'E1027:')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
984 call writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
985 so Xdef
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
986 call delete('Xdef')
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
987
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
988 call assert_equal(0, Func0())
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
989 call assert_equal('Func1', Func1())
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
990 call assert_equal('Func2', Func2())
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
991
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
992 delfunc! Func0
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
993 delfunc! Func1
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
994 delfunc! Func2
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
995 enddef
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
996
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker