annotate src/testdir/test_vim9_script.vim @ 19326:d1810b726592 v8.2.0221

patch 8.2.0221: no test for Vim9 += and ..= Commit: https://github.com/vim/vim/commit/6e587dcbf319ea898ef50f7e367c46586a6f408a Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 6 13:15:52 2020 +0100 patch 8.2.0221: no test for Vim9 += and ..= Problem: No test for Vim9 += and ..=. Solution: Add tests.
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Feb 2020 13:30:03 +0100
parents 6e199d1d11d0
children e99e6d794597
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
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
4
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " 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
6 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
7 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
8 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
9 call delete('Xdef')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 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
13 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
14 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
15 call delete('Xdef')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 def Test_syntax()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let var = 234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 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
21 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 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
24 def SomeFunc(): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 return 'yes'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 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
28 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
30 let s:appendToMe = 'xxx'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
31 let s:addToMe = 111
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
32
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 def Test_assignment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 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
35 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
36 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
37 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
38
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 let list1: list<string> = ['sdf', 'asdf']
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 let list2: list<number> = [1, 2, 3]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 " TODO: does not work yet
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 " let listS: list<string> = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 " let listN: list<number> = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 let dict1: dict<string> = #{key: 'value'}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 let dict2: dict<number> = #{one: 1, two: 2}
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
48
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
49 v:char = 'abc'
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
50 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
51
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
52 $ENVVAR = 'foobar'
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
53 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
54 $ENVVAR = ''
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
55
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
56 appendToMe ..= 'yyy'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
57 assert_equal('xxxyyy', appendToMe)
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
58 addToMe += 222
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
59 assert_equal(333, addToMe)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 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
63 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
64 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
65 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
66
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 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
68 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
69
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 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
71 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
72
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 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
74 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
75
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 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
77 call CheckDefFailure(['let var: number = feedkeys("0")'], 'expected number but got void')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 func Test_const()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 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
82 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
83 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
84 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 def Test_block()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 let outer = 1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 let inner = 2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 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
91 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
92 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 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
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_block_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 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
98 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 def ReturnString(): string
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 return 'string'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 enddef
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 def ReturnNumber(): number
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 return 123
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 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
109 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
110 assert_equal(123, ReturnNumber())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 func Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 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
115 endfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 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
118 g:counter = 1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 Increment()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 " 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
123 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
124 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
125 unlet g:counter
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 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
129 let res = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 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
131 res ..= ',' .. s
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 endfor
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return res
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 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
137 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
138 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
139 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
140 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141
19295
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
142 "def Test_call_func_defined_later()
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
143 " call assert_equal('one', DefineLater('one'))
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
144 " call assert_fails('call NotDefined("one")', 'E99:')
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
145 "enddef
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
146
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
147 func DefineLater(arg)
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
148 return a:arg
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
149 endfunc
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
150
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
151 def MyDefaultArgs(name = 'string'): string
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
152 return name
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
153 enddef
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
154
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
155 func Test_call_default_args_from_func()
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
156 " TODO: implement using default value for optional argument
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
157 "call assert_equal('string', MyDefaultArgs())
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
158 call assert_fails('call MyDefaultArgs()', 'optional arguments not implemented yet')
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
159 call assert_equal('one', MyDefaultArgs('one'))
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
160 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
161 endfunc
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
162
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
163 def Test_call_default_args()
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
164 " TODO: implement using default value for optional argument
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
165 "assert_equal('string', MyDefaultArgs())
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
166 assert_equal('one', MyDefaultArgs('one'))
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
167 assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
168 enddef
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
169
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 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
171 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
172 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
173 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
174 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
175 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
177 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
178 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
179 enddef
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
180
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 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
182 let l = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 try
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 add(l, '1')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 throw 'wrong'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 add(l, '2')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 catch
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 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
189 finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 add(l, '3')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 endtry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 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
193 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 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
196 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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
198 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
199 return name .. arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 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
202 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
203
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 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
205 export let exported = 9876
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
206 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
207 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
208 return 'Exported'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 def Test_vim9script()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 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
214 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216 g:imported = exported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
217 exported += 3
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
218 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
219 g:imported_func = Exported()
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
220
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
221 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
222 g:imported_name = exp_name
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
223 exp_name ..= ' Doe'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
224 g:imported_name_appended = exp_name
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 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
228 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
229
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 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
233 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
234 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
235 assert_equal(9879, g:imported_added)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 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
237 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
238 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
239 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
240
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 unlet g:result
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 unlet g:localname
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 unlet g:imported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
244 unlet g:imported_added
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 unlet g:imported_func
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
246 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
247 delete('Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 delete('Xexport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 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
251 CheckScriptFailure(['vim9script', 'scriptversion 2'], 'E1040:')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 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
255 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
256 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 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
259 var = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 MyFunc('foobar')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 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
263
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 let str = 'barfoo'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 str->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 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
267
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 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
269 g:value->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 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
271
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 let listvar = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 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
274 listvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 [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
277 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
278
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 let dictvar = {}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 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
281 dictvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 {'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
284 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
285 #{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
286 assert_equal(#{a: 3, b: 4}, dictvar)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 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
289 source Xcall.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 delete('Xcall.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 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
294 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
295 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 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
298 let var = 123
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 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
302 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
303 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
304 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 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
307 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
308 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 const var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 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
311 var = 'asdf'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 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
315 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
316 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
317 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 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
320 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
321 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 const var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 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
325 valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 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
329 let valtwo = 222
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 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
331 return valtwo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 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
335 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 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
340 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 def TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 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
343 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
344 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 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
348 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 " 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
351 " 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
352 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
353 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 " 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
357 lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 let valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 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
363 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
364
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 delete('Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 delete('Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 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
370 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 \ '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
373 \ 'def UseExported()',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
374 \ ' 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
375 \ ' exported = 8888',
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
376 \ ' 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
377 \ 'enddef',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
378 \ 'UseExported()',
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
379 \ '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
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_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
382 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
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_abs.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(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
387 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
388 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
389 \ .. 'g:imported_abs = exported.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
390 \ .. '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
391 \ .. '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
392 \ .. 'exported = 8888.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
393 \ .. '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
394 \ .. 'g:imported_after = exported.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
395 \ .. '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
396 \ .. '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
397 \, 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
398 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
399 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
400
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 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
402 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
403 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 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
406 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 \ '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
409 \ '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
410 \ ]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 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
412 mkdir('import')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 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
414
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 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
416 &rtp = getcwd()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 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
418 &rtp = save_rtp
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 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
421 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
422
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 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
424 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
425 delete('import', 'd')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 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
429 " 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
430 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
431 l->remove(0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 l->add(5)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 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
434 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
435 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
437 " 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
438 " recognized.
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
439 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
440 CheckFeature python3
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
441 let py = 'python3'
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
442 execute py "<< EOF"
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
443 def do_something():
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
444 return 1
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
445 EOF
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
446 endfunc
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
447
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
448 def HasEval()
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
449 if has('eval')
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
450 echo 'yes'
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
451 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
452 echo 'no'
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
453 endif
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
454 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
455
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
456 def HasNothing()
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
457 if has('nothing')
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
458 echo 'yes'
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
459 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
460 echo 'no'
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
461 endif
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
462 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
463
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
464 def Test_compile_const_expr()
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
465 assert_equal("\nyes", execute('call HasEval()'))
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
466 let instr = execute('disassemble HasEval')
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
467 assert_match('PUSHS "yes"', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
468 assert_notmatch('PUSHS "no"', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
469 assert_notmatch('JUMP', instr)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
470
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
471 assert_equal("\nno", execute('call HasNothing()'))
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
472 instr = execute('disassemble HasNothing')
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
473 assert_notmatch('PUSHS "yes"', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
474 assert_match('PUSHS "no"', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
475 assert_notmatch('JUMP', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
476 enddef
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
477
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
478 func NotCompiled()
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
479 echo "not"
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
480 endfunc
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
481
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
482 let s:scriptvar = 4
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
483 let g:globalvar = 'g'
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
484
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
485 def s:ScriptFuncLoad(arg: string)
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
486 let local = 1
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
487 buffers
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
488 echo arg
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
489 echo local
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
490 echo v:version
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
491 echo s:scriptvar
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
492 echo g:globalvar
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
493 echo &tabstop
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
494 echo $ENVVAR
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
495 echo @z
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
496 enddef
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
497
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
498 def Test_disassembleLoad()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
499 assert_fails('disass NoFunc', 'E1061:')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
500 assert_fails('disass NotCompiled', 'E1062:')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
501
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
502 let res = execute('disass s:ScriptFuncLoad')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
503 assert_match('<SNR>\d*_ScriptFuncLoad.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
504 \ .. 'buffers.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
505 \ .. ' EXEC \+buffers.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
506 \ .. ' LOAD arg\[-1\].*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
507 \ .. ' LOAD $0.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
508 \ .. ' LOADV v:version.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
509 \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
510 \ .. ' LOADG g:globalvar.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
511 \ .. ' LOADENV $ENVVAR.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
512 \ .. ' LOADREG @z.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
513 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
514 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
515
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
516 def s:ScriptFuncPush()
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
517 let localbool = true
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
518 let localspec = v:none
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
519 let localblob = 0z1234
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
520 if has('float')
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
521 let localfloat = 1.234
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
522 endif
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
523 enddef
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
524
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
525 def Test_disassemblePush()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
526 let res = execute('disass s:ScriptFuncPush')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
527 assert_match('<SNR>\d*_ScriptFuncPush.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
528 \ .. 'localbool = true.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
529 \ .. ' PUSH v:true.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
530 \ .. 'localspec = v:none.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
531 \ .. ' PUSH v:none.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
532 \ .. 'localblob = 0z1234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
533 \ .. ' PUSHBLOB 0z1234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
534 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
535 if has('float')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
536 assert_match('<SNR>\d*_ScriptFuncPush.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
537 \ .. 'localfloat = 1.234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
538 \ .. ' PUSHF 1.234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
539 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
540 endif
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
541 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
542
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
543 def s:ScriptFuncStore()
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
544 let localnr = 1
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
545 localnr = 2
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
546 let localstr = 'abc'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
547 localstr = 'xyz'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
548 v:char = 'abc'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
549 s:scriptvar = 'sv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
550 g:globalvar = 'gv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
551 &tabstop = 8
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
552 $ENVVAR = 'ev'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
553 @z = 'rv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
554 enddef
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
555
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
556 def Test_disassembleStore()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
557 let res = execute('disass s:ScriptFuncStore')
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
558 assert_match('<SNR>\d*_ScriptFuncStore.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
559 \ .. 'localnr = 2.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
560 \ .. ' STORE 2 in $0.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
561 \ .. 'localstr = ''xyz''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
562 \ .. ' STORE $1.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
563 \ .. 'v:char = ''abc''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
564 \ .. 'STOREV v:char.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
565 \ .. 's:scriptvar = ''sv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
566 \ .. ' STORES s:scriptvar in .*test_vim9_script.vim.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
567 \ .. 'g:globalvar = ''gv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
568 \ .. ' STOREG g:globalvar.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
569 \ .. '&tabstop = 8.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
570 \ .. ' STOREOPT &tabstop.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
571 \ .. '$ENVVAR = ''ev''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
572 \ .. ' STOREENV $ENVVAR.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
573 \ .. '@z = ''rv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
574 \ .. ' STOREREG @z.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
575 \, res)
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
576 enddef
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
577
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
578 def s:ScriptFuncTry()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
579 try
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
580 echo 'yes'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
581 catch /fail/
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
582 echo 'no'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
583 finally
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
584 echo 'end'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
585 endtry
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
586 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
587
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
588 def Test_disassembleTry()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
589 let res = execute('disass s:ScriptFuncTry')
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
590 assert_match('<SNR>\d*_ScriptFuncTry.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
591 \ .. 'try.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
592 \ .. 'TRY catch -> \d\+, finally -> \d\+.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
593 \ .. 'catch /fail/.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
594 \ .. ' JUMP -> \d\+.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
595 \ .. ' PUSH v:exception.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
596 \ .. ' PUSHS "fail".*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
597 \ .. ' COMPARESTRING =\~.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
598 \ .. ' JUMP_IF_FALSE -> \d\+.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
599 \ .. ' CATCH.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
600 \ .. 'finally.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
601 \ .. ' PUSHS "end".*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
602 \ .. 'endtry.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
603 \ .. ' ENDTRY.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
604 \, 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
605 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
606
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
607 def s:ScriptFuncNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
608 let ll = [1, "two", 333]
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
609 let dd = #{one: 1, two: "val"}
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
610 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
611
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
612 def Test_disassembleNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
613 let res = execute('disass s:ScriptFuncNew')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
614 assert_match('<SNR>\d*_ScriptFuncNew.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
615 \ .. 'let ll = \[1, "two", 333].*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
616 \ .. 'PUSHNR 1.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
617 \ .. 'PUSHS "two".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
618 \ .. 'PUSHNR 333.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
619 \ .. 'NEWLIST size 3.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
620 \ .. 'let dd = #{one: 1, two: "val"}.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
621 \ .. 'PUSHS "one".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
622 \ .. 'PUSHNR 1.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
623 \ .. 'PUSHS "two".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
624 \ .. 'PUSHS "val".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
625 \ .. 'NEWDICT size 2.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
626 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
627 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
628
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
629 def FuncWithArg(arg)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
630 echo arg
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
631 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
632
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
633 func UserFunc()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
634 echo 'nothing'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
635 endfunc
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
636
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
637 func UserFuncWithArg(arg)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
638 echo a:arg
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
639 endfunc
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
640
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
641 def s:ScriptFuncCall(): string
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
642 changenr()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
643 char2nr("abc")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
644 Test_disassembleNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
645 FuncWithArg(343)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
646 UserFunc()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
647 UserFuncWithArg("foo")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
648 let FuncRef = function("UserFunc")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
649 FuncRef()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
650 let FuncRefWithArg = function("UserFuncWithArg")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
651 FuncRefWithArg("bar")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
652 return "yes"
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
653 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
654
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
655 def Test_disassembleCall()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
656 let res = execute('disass s:ScriptFuncCall')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
657 assert_match('<SNR>\d*_ScriptFuncCall.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
658 \ .. 'changenr().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
659 \ .. ' BCALL changenr(argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
660 \ .. 'char2nr("abc").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
661 \ .. ' PUSHS "abc".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
662 \ .. ' BCALL char2nr(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
663 \ .. 'Test_disassembleNew().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
664 \ .. ' DCALL Test_disassembleNew(argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
665 \ .. 'FuncWithArg(343).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
666 \ .. ' PUSHNR 343.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
667 \ .. ' DCALL FuncWithArg(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
668 \ .. 'UserFunc().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
669 \ .. ' UCALL UserFunc(argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
670 \ .. 'UserFuncWithArg("foo").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
671 \ .. ' PUSHS "foo".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
672 \ .. ' UCALL UserFuncWithArg(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
673 \ .. 'let FuncRef = function("UserFunc").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
674 \ .. 'FuncRef().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
675 \ .. ' LOAD $\d.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
676 \ .. ' PCALL (argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
677 \ .. 'let FuncRefWithArg = function("UserFuncWithArg").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
678 \ .. 'FuncRefWithArg("bar").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
679 \ .. ' PUSHS "bar".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
680 \ .. ' LOAD $\d.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
681 \ .. ' PCALL (argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
682 \ .. 'return "yes".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
683 \ .. ' PUSHS "yes".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
684 \ .. ' RETURN.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
685 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
686 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
687
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker