annotate src/testdir/test_vim9_script.vim @ 19328:e99e6d794597 v8.2.0222

patch 8.2.0222: Vim9: optional function arguments don't work yet Commit: https://github.com/vim/vim/commit/170fcfcf250954d76fca86e3fed088ddfdb49383 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 6 17:51:35 2020 +0100 patch 8.2.0222: Vim9: optional function arguments don't work yet Problem: Vim9: optional function arguments don't work yet. Solution: Implement optional function arguments.
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Feb 2020 18:00:04 +0100
parents d1810b726592
children 9c8b803fe598
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
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
142 def MyDefaultArgs(name = 'string'): string
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
143 return name
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
144 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
145
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
146 def Test_call_default_args()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
147 assert_equal('string', MyDefaultArgs())
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
148 assert_equal('one', MyDefaultArgs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
149 assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
150 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
151
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
152 func Test_call_default_args_from_func()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
153 call assert_equal('string', MyDefaultArgs())
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
154 call assert_equal('one', MyDefaultArgs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
155 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
156 endfunc
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
157
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
158 " Default arg and varargs
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
159 def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
160 let res = one .. ',' .. two
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
161 for s in rest
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
162 res ..= ',' .. s
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
163 endfor
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
164 return res
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
165 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
166
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
167 def Test_call_def_varargs()
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
168 call assert_fails('call MyDefVarargs()', 'E119:')
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
169 assert_equal('one,foo', MyDefVarargs('one'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
170 assert_equal('one,two', MyDefVarargs('one', 'two'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
171 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
172 enddef
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
173
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19326
diff changeset
174
19295
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
175 "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
176 " 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
177 " 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
178 "enddef
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
179
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
180 func DefineLater(arg)
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
181 return a:arg
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
182 endfunc
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
183
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 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
185 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
186 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
187 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
188 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
189 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
191 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
192 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
193 enddef
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19295
diff changeset
194
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 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
196 let l = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 try
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 add(l, '1')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 throw 'wrong'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 add(l, '2')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 catch
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 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
203 finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 add(l, '3')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 endtry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 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
207 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 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
210 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 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
213 return name .. arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216 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
217
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 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
219 export let exported = 9876
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
220 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
221 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
222 return 'Exported'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 def Test_vim9script()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 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
228 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 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
230 g:imported = exported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
231 exported += 3
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
232 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
233 g:imported_func = Exported()
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
234
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
235 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
236 g:imported_name = exp_name
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
237 exp_name ..= ' Doe'
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
238 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
239 END
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 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
242 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
243
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 unlet g:result
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 unlet g:localname
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 unlet g:imported
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
258 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
259 unlet g:imported_func
19326
d1810b726592 patch 8.2.0221: no test for Vim9 += and ..=
Bram Moolenaar <Bram@vim.org>
parents: 19320
diff changeset
260 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
261 delete('Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 delete('Xexport.vim')
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 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
265 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
266 enddef
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 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
269 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
270 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 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
273 var = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 MyFunc('foobar')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 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
277
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 let str = 'barfoo'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 str->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 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
281
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 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
283 g:value->MyFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 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
285
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 let listvar = []
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 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
288 listvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 [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
291 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
292
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 let dictvar = {}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 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
295 dictvar = arg
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 {'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
298 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
299 #{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
300 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
301 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 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
303 source Xcall.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 delete('Xcall.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 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
308 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
309 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 let var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 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
312 let var = 123
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 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
316 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
317 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
318 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 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
321 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
322 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 const var = ''
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 var = 'asdf'
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 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
329 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
330 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
331 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 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
334 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
335 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 const var = ''
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 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
339 valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 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
343 let valtwo = 222
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 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
345 return valtwo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 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
349 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 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
354 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 def TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 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
357 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
358 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 TheFunc()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 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
362 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 " 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
365 " 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
366 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
367 source Xreload.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 source Ximport.vim
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 " 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
371 lines =<< trim END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 vim9script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 let valone = 1234
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 let valone = 5678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 END
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 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
377 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
378
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 delete('Xreload.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 delete('Ximport.vim')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 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
384 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 \ '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
387 \ 'def UseExported()',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
388 \ ' 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
389 \ ' exported = 8888',
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
390 \ ' 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
391 \ 'enddef',
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
392 \ 'UseExported()',
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
393 \ '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
394 \ ]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 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
396 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
397
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 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
399
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 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
401 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
402 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
403 \ .. 'g:imported_abs = exported.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
404 \ .. '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
405 \ .. '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
406 \ .. 'exported = 8888.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
407 \ .. '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
408 \ .. 'g:imported_after = exported.*'
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
409 \ .. '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
410 \ .. '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
411 \, 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
412 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
413 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
414
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 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
416 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
417 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 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
420 let import_lines = [
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 \ 'vim9script',
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 \ '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
423 \ '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
424 \ ]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 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
426 mkdir('import')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 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
428
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 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
430 &rtp = getcwd()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 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
432 &rtp = save_rtp
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 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
435 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
436
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 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
438 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
439 delete('import', 'd')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 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
443 " 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
444 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
445 l->remove(0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 l->add(5)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 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
448 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
449 enddef
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
451 " 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
452 " recognized.
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
453 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
454 CheckFeature python3
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
455 let py = 'python3'
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
456 execute py "<< EOF"
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
457 def do_something():
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
458 return 1
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
459 EOF
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
460 endfunc
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
461
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
462 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
463 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
464 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
465 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
466 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
467 endif
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
468 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
469
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
470 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
471 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
472 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
473 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
474 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
475 endif
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
476 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
477
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
478 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
479 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
480 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
481 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
482 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
483 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
484
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
485 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
486 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
487 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
488 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
489 assert_notmatch('JUMP', instr)
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
490 enddef
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
491
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
492 func NotCompiled()
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
493 echo "not"
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
494 endfunc
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
495
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
496 let s:scriptvar = 4
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
497 let g:globalvar = 'g'
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
498
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
499 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
500 let local = 1
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
501 buffers
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
502 echo arg
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
503 echo local
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
504 echo v:version
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
505 echo s:scriptvar
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
506 echo g:globalvar
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
507 echo &tabstop
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
508 echo $ENVVAR
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
509 echo @z
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
510 enddef
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
511
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
512 def Test_disassembleLoad()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
513 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
514 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
515
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
516 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
517 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
518 \ .. 'buffers.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
519 \ .. ' EXEC \+buffers.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
520 \ .. ' LOAD arg\[-1\].*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
521 \ .. ' LOAD $0.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
522 \ .. ' LOADV v:version.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
523 \ .. ' 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
524 \ .. ' LOADG g:globalvar.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
525 \ .. ' LOADENV $ENVVAR.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
526 \ .. ' LOADREG @z.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
527 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
528 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
529
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
530 def s:ScriptFuncPush()
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
531 let localbool = true
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
532 let localspec = v:none
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
533 let localblob = 0z1234
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
534 if has('float')
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
535 let localfloat = 1.234
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
536 endif
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
537 enddef
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
538
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
539 def Test_disassemblePush()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
540 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
541 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
542 \ .. 'localbool = true.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
543 \ .. ' PUSH v:true.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
544 \ .. 'localspec = v:none.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
545 \ .. ' PUSH v:none.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
546 \ .. 'localblob = 0z1234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
547 \ .. ' PUSHBLOB 0z1234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
548 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
549 if has('float')
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
550 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
551 \ .. 'localfloat = 1.234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
552 \ .. ' PUSHF 1.234.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
553 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
554 endif
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
555 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
556
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
557 def s:ScriptFuncStore()
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
558 let localnr = 1
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 let localstr = 'abc'
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 v:char = 'abc'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
563 s:scriptvar = 'sv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
564 g:globalvar = 'gv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
565 &tabstop = 8
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
566 $ENVVAR = 'ev'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
567 @z = 'rv'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
568 enddef
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
569
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
570 def Test_disassembleStore()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
571 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
572 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
573 \ .. 'localnr = 2.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
574 \ .. ' STORE 2 in $0.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
575 \ .. 'localstr = ''xyz''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
576 \ .. ' STORE $1.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
577 \ .. 'v:char = ''abc''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
578 \ .. 'STOREV v:char.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
579 \ .. 's:scriptvar = ''sv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
580 \ .. ' 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
581 \ .. 'g:globalvar = ''gv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
582 \ .. ' STOREG g:globalvar.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
583 \ .. '&tabstop = 8.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
584 \ .. ' STOREOPT &tabstop.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
585 \ .. '$ENVVAR = ''ev''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
586 \ .. ' STOREENV $ENVVAR.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
587 \ .. '@z = ''rv''.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
588 \ .. ' STOREREG @z.*'
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
589 \, res)
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
590 enddef
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
591
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
592 def s:ScriptFuncTry()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
593 try
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
594 echo 'yes'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
595 catch /fail/
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
596 echo 'no'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
597 finally
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
598 echo 'end'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
599 endtry
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
600 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
601
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
602 def Test_disassembleTry()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
603 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
604 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
605 \ .. 'try.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
606 \ .. '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
607 \ .. 'catch /fail/.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
608 \ .. ' JUMP -> \d\+.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
609 \ .. ' PUSH v:exception.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
610 \ .. ' PUSHS "fail".*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
611 \ .. ' COMPARESTRING =\~.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
612 \ .. ' JUMP_IF_FALSE -> \d\+.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
613 \ .. ' CATCH.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
614 \ .. 'finally.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
615 \ .. ' PUSHS "end".*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
616 \ .. 'endtry.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
617 \ .. ' ENDTRY.*'
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
618 \, 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
619 enddef
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19185
diff changeset
620
19320
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
621 def s:ScriptFuncNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
622 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
623 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
624 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
625
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
626 def Test_disassembleNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
627 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
628 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
629 \ .. '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
630 \ .. 'PUSHNR 1.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
631 \ .. 'PUSHS "two".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
632 \ .. 'PUSHNR 333.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
633 \ .. 'NEWLIST size 3.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
634 \ .. '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
635 \ .. 'PUSHS "one".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
636 \ .. 'PUSHNR 1.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
637 \ .. 'PUSHS "two".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
638 \ .. 'PUSHS "val".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
639 \ .. 'NEWDICT size 2.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
640 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
641 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
642
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
643 def FuncWithArg(arg)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
644 echo arg
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
645 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
646
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
647 func UserFunc()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
648 echo 'nothing'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
649 endfunc
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
650
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
651 func UserFuncWithArg(arg)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
652 echo a:arg
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
653 endfunc
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 s:ScriptFuncCall(): string
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
656 changenr()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
657 char2nr("abc")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
658 Test_disassembleNew()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
659 FuncWithArg(343)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
660 UserFunc()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
661 UserFuncWithArg("foo")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
662 let FuncRef = function("UserFunc")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
663 FuncRef()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
664 let FuncRefWithArg = function("UserFuncWithArg")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
665 FuncRefWithArg("bar")
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
666 return "yes"
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
667 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
668
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
669 def Test_disassembleCall()
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
670 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
671 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
672 \ .. 'changenr().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
673 \ .. ' BCALL changenr(argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
674 \ .. 'char2nr("abc").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
675 \ .. ' PUSHS "abc".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
676 \ .. ' BCALL char2nr(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
677 \ .. 'Test_disassembleNew().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
678 \ .. ' 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
679 \ .. 'FuncWithArg(343).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
680 \ .. ' PUSHNR 343.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
681 \ .. ' DCALL FuncWithArg(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
682 \ .. 'UserFunc().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
683 \ .. ' UCALL UserFunc(argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
684 \ .. 'UserFuncWithArg("foo").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
685 \ .. ' PUSHS "foo".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
686 \ .. ' UCALL UserFuncWithArg(argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
687 \ .. 'let FuncRef = function("UserFunc").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
688 \ .. 'FuncRef().*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
689 \ .. ' LOAD $\d.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
690 \ .. ' PCALL (argc 0).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
691 \ .. 'let FuncRefWithArg = function("UserFuncWithArg").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
692 \ .. 'FuncRefWithArg("bar").*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
693 \ .. ' PUSHS "bar".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
694 \ .. ' LOAD $\d.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
695 \ .. ' PCALL (argc 1).*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
696 \ .. 'return "yes".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
697 \ .. ' PUSHS "yes".*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
698 \ .. ' RETURN.*'
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
699 \, res)
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
700 enddef
6e199d1d11d0 patch 8.2.0218: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
701
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker