annotate src/testdir/test_vim9_script.vim @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents db97ccaaa7c8
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1 " Test various aspects of the Vim9 script language.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3 source check.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4 source term_util.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
5 import './vim9.vim' as v9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
6 source screendump.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
7 source shared.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
9 def Test_vim9script_feature()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
10 # example from the help, here the feature is always present
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
11 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
12 " old style comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
13 if !has('vim9script')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
14 " legacy commands would go here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
15 finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
16 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
17 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
18 # Vim9 script commands go here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
19 g:didit = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
20 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
21 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
22 assert_equal(true, g:didit)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
23 unlet g:didit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
24 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
25
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
26 def Test_range_only()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
27 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
28 setline(1, ['blah', 'Blah'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
29 :/Blah/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
30 assert_equal(2, getcurpos()[1])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
31 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
32
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
33 # without range commands use current line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
34 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
35 setline(1, ['one', 'two', 'three'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
36 :2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
37 print
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
38 assert_equal('two', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
39 :3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
40 list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
41 assert_equal('three$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
42
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
43 # missing command does not print the line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
44 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
45 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
46 :1|
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
47 assert_equal('three$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
48 :|
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
49 assert_equal('three$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
50 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
51 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
52
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
53 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
54
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
55 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
56 set cpo+=-
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
57 :1,999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
58 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
59 v9.CheckDefExecAndScriptFailure(lines, 'E16:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
60 set cpo&vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
61
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
62 v9.CheckDefExecAndScriptFailure([":'x"], 'E20:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
63
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
64 # won't generate anything
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
65 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
66 :123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
67 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
68 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
69
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
70 def Test_invalid_range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
71 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
72 :123 eval 1 + 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
73 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
74 v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
75
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
76 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
77 :123 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
78 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
79 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
80 v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
81
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
82 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
83 :123 echo 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
84 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
85 v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
86
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
87 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
88 :123 cd there
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
89 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
90 v9.CheckDefAndScriptFailure(lines, 'E481:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
91 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
92
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
93 let g:alist = [7]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
94 let g:astring = 'text'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
95 let g:anumber = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
96
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
97 def Test_delfunction()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
98 # Check function is defined in script namespace
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
99 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
100 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
101 'func CheckMe()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
102 ' return 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
103 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
104 'func DoTest()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
105 ' call assert_equal(123, s:CheckMe())',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
106 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
107 'DoTest()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
108 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
109
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
110 # Check function in script namespace cannot be deleted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
111 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
112 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
113 'func DeleteMe1()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
114 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
115 'delfunction DeleteMe1',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
116 ], 'E1084:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
117 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
118 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
119 'func DeleteMe2()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
120 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
121 'def DoThat()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
122 ' delfunction DeleteMe2',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
123 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
124 'DoThat()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
125 ], 'E1084:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
126 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
127 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
128 'def DeleteMe3()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
129 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
130 'delfunction DeleteMe3',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
131 ], 'E1084:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
132 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
133 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
134 'def DeleteMe4()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
135 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
136 'def DoThat()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
137 ' delfunction DeleteMe4',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
138 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
139 'DoThat()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
140 ], 'E1084:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
141
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
142 # Check that global :def function can be replaced and deleted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
143 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
144 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
145 def g:Global(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
146 return "yes"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
147 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
148 assert_equal("yes", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
149 def! g:Global(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
150 return "no"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
151 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
152 assert_equal("no", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
153 delfunc g:Global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
154 assert_false(exists('*g:Global'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
155 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
156 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
157
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
158 # Check that global function can be replaced by a :def function and deleted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
159 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
160 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
161 func g:Global()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
162 return "yes"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
163 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
164 assert_equal("yes", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
165 def! g:Global(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
166 return "no"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
167 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
168 assert_equal("no", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
169 delfunc g:Global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
170 assert_false(exists('*g:Global'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
171 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
172 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
174 # Check that global :def function can be replaced by a function and deleted
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
175 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
176 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
177 def g:Global(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
178 return "yes"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
179 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
180 assert_equal("yes", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
181 func! g:Global()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
182 return "no"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
183 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
184 assert_equal("no", g:Global())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
185 delfunc g:Global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
186 assert_false(exists('*g:Global'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
187 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
188 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
189 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
191 def Test_wrong_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
192 v9.CheckDefFailure(['var name: list<nothing>'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
193 v9.CheckDefFailure(['var name: list<list<nothing>>'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
194 v9.CheckDefFailure(['var name: dict<nothing>'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
195 v9.CheckDefFailure(['var name: dict<dict<nothing>>'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
196
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
197 v9.CheckDefFailure(['var name: dict<number'], 'E1009:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
198 v9.CheckDefFailure(['var name: dict<list<number>'], 'E1009:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
199
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
200 v9.CheckDefFailure(['var name: ally'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
201 v9.CheckDefFailure(['var name: bram'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
202 v9.CheckDefFailure(['var name: cathy'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
203 v9.CheckDefFailure(['var name: dom'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
204 v9.CheckDefFailure(['var name: freddy'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
205 v9.CheckDefFailure(['var name: john'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
206 v9.CheckDefFailure(['var name: larry'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
207 v9.CheckDefFailure(['var name: ned'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
208 v9.CheckDefFailure(['var name: pam'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
209 v9.CheckDefFailure(['var name: sam'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
210 v9.CheckDefFailure(['var name: vim'], 'E1010:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
212 v9.CheckDefFailure(['var Ref: number', 'Ref()'], 'E1085:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
213 v9.CheckDefFailure(['var Ref: string', 'var res = Ref()'], 'E1085:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
214 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
215
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
216 def Test_script_namespace()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
217 # defining a function or variable with s: is not allowed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
218 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
219 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
220 def s:Function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
221 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
222 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
223 v9.CheckScriptFailure(lines, 'E1268:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
224
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
225 for decl in ['var', 'const', 'final']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
226 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
227 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
228 var s:var = 'var'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
229 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
230 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
231 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
232 decl .. ' s:var = "var"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
233 ], 'E1268:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
234 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
235
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
236 # Calling a function or using a variable with s: is not allowed at script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
237 # level
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
238 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
239 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
240 def Function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
241 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
242 s:Function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
243 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
244 v9.CheckScriptFailure(lines, 'E1268:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
245 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
246 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
247 def Function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
248 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
249 call s:Function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
250 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
251 v9.CheckScriptFailure(lines, 'E1268:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
252 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
253 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
254 var var = 'var'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
255 echo s:var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
256 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
257 v9.CheckScriptFailure(lines, 'E1268:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
258 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
260 def Test_script_wrong_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
261 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
262 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
263 var dict: dict<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
264 dict['a'] = ['x']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
265 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
266 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got list<string>', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
267 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
268
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
269 def Test_const()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
270 v9.CheckDefFailure(['final name = 234', 'name = 99'], 'E1018:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
271 v9.CheckDefFailure(['final one = 234', 'var one = 99'], 'E1017:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
272 v9.CheckDefFailure(['final list = [1, 2]', 'var list = [3, 4]'], 'E1017:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
273 v9.CheckDefFailure(['final two'], 'E1125:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
274 v9.CheckDefFailure(['final &option'], 'E996:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
276 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
277 final list = [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
278 list[0] = 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
279 list->assert_equal([4, 2, 3])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
280 const other = [5, 6, 7]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
281 other->assert_equal([5, 6, 7])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
283 var varlist = [7, 8]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
284 const constlist = [1, varlist, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
285 varlist[0] = 77
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
286 constlist[1][1] = 88
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
287 var cl = constlist[1]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
288 cl[1] = 88
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
289 constlist->assert_equal([1, [77, 88], 3])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
290
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
291 var vardict = {five: 5, six: 6}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
292 const constdict = {one: 1, two: vardict, three: 3}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
293 vardict['five'] = 55
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
294 constdict['two']['six'] = 66
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
295 var cd = constdict['two']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
296 cd['six'] = 66
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
297 constdict->assert_equal({one: 1, two: {five: 55, six: 66}, three: 3})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
298 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
299 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
301 # "any" type with const flag is recognized as "any"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
302 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
303 const dict: dict<any> = {foo: {bar: 42}}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
304 const foo = dict.foo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
305 assert_equal(v:t_number, type(foo.bar))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
306 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
307 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
309 # also when used as a builtin function argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
310 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
311 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
313 def SorterFunc(lhs: dict<string>, rhs: dict<string>): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
314 return lhs.name <# rhs.name ? -1 : 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
315 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
317 def Run(): void
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
318 var list = [{name: "3"}, {name: "2"}]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
319 const Sorter = get({}, "unknown", SorterFunc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
320 sort(list, Sorter)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
321 assert_equal([{name: "2"}, {name: "3"}], list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
322 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
324 Run()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
325 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
326 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
327 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
329 def Test_const_bang()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
330 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
331 const var = 234
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
332 var = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
333 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
334 v9.CheckDefExecFailure(lines, 'E1018:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
335 v9.CheckScriptFailure(['vim9script'] + lines, 'E46:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
336
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
337 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
338 const ll = [2, 3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
339 ll[0] = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
340 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
341 v9.CheckDefExecFailure(lines, 'E1119:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
342 v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
344 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
345 const ll = [2, 3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
346 ll[3] = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
347 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
348 v9.CheckDefExecFailure(lines, 'E1118:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
349 v9.CheckScriptFailure(['vim9script'] + lines, 'E684:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
351 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
352 const dd = {one: 1, two: 2}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
353 dd["one"] = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
354 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
355 v9.CheckDefExecFailure(lines, 'E1121:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
356 v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
358 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
359 const dd = {one: 1, two: 2}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
360 dd["three"] = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
361 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
362 v9.CheckDefExecFailure(lines, 'E1120:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
363 v9.CheckScriptFailure(['vim9script'] + lines, 'E741:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
364 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
365
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
366 def Test_range_no_colon()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
367 v9.CheckDefFailure(['%s/a/b/'], 'E1050:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
368 v9.CheckDefFailure(['+ s/a/b/'], 'E1050:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
369 v9.CheckDefFailure(['- s/a/b/'], 'E1050:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
370 v9.CheckDefFailure(['. s/a/b/'], 'E1050:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
371 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
373
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
374 def Test_block()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
375 var outer = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
376 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
377 var inner = 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
378 assert_equal(1, outer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
379 assert_equal(2, inner)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
380 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
381 assert_equal(1, outer)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
382
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
383 {|echo 'yes'|}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
384 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
385
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
386 def Test_block_failure()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
387 v9.CheckDefFailure(['{', 'var inner = 1', '}', 'echo inner'], 'E1001:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
388 v9.CheckDefFailure(['}'], 'E1025:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
389 v9.CheckDefFailure(['{', 'echo 1'], 'E1026:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
390 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
392 def Test_block_local_vars()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
393 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
394 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
395 v:testing = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
396 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
397 var text = ['hello']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
398 def SayHello(): list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
399 return text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
400 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
401 def SetText(v: string)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
402 text = [v]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
403 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
404 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
405
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
406 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
407 var text = ['again']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
408 def SayAgain(): list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
409 return text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
410 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
411 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
413 # test that the "text" variables are not cleaned up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
414 test_garbagecollect_now()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
416 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
418 assert_equal(['hello'], SayHello())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
419 assert_equal(['again'], SayAgain())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
420
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
421 SetText('foobar')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
422 assert_equal(['foobar'], SayHello())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
423
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
424 call writefile(['ok'], 'Xdidit')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
425 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
426 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
427
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
428 # need to execute this with a separate Vim instance to avoid the current
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
429 # context gets garbage collected.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
430 writefile(lines, 'Xscript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
431 g:RunVim([], [], '-S Xscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
432 assert_equal(['ok'], readfile('Xdidit'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
433
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
434 delete('Xdidit')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
435 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
437 def Test_block_local_vars_with_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
438 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
439 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
440 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
441 var foo = 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
442 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
443 var bar = 'bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
444 def Func(): list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
445 return [foo, bar]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
446 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
447 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
448 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
449 # function is compiled here, after blocks have finished, can still access
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
450 # "foo" and "bar"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
451 assert_equal(['foo', 'bar'], Func())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
452 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
453 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
454 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
456 " legacy func for command that's defined later
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
457 func s:InvokeSomeCommand()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
458 SomeCommand
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
459 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
460
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
461 def Test_autocommand_block()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
462 com SomeCommand {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
463 g:someVar = 'some'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
464 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
465 InvokeSomeCommand()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
466 assert_equal('some', g:someVar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
468 delcommand SomeCommand
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
469 unlet g:someVar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
470 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
472 def Test_command_block()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
473 au BufNew *.xml {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
474 g:otherVar = 'other'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
475 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
476 split other.xml
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
477 assert_equal('other', g:otherVar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
478
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
479 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
480 au! BufNew *.xml
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
481 unlet g:otherVar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
482 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
484 func g:NoSuchFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
485 echo 'none'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
486 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
488 def Test_try_catch_throw()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
489 var l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
490 try # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
491 add(l, '1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
492 throw 'wrong'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
493 add(l, '2') # "unreachable code"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
494 catch # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
495 add(l, v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
496 finally # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
497 add(l, '3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
498 endtry # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
499 assert_equal(['1', 'wrong', '3'], l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
500
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
501 l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
502 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
503 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
504 add(l, '1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
505 throw 'wrong'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
506 add(l, '2') # "unreachable code"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
507 catch /right/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
508 add(l, v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
509 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
510 catch /wrong/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
511 add(l, 'caught')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
512 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
513 add(l, 'finally')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
514 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
515 assert_equal(['1', 'caught', 'finally'], l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
516
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
517 var n: number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
518 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
519 n = l[3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
520 catch /E684:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
521 n = 99
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
522 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
523 assert_equal(99, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
525 var done = 'no'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
526 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
527 try | catch | endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
528 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
529 done = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
530 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
531 assert_equal('yes', done)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
533 done = 'no'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
534 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
535 done = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
536 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
537 try | catch | endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
538 done = 'never'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
539 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
540 assert_equal('yes', done)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
541
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
542 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
543 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
544 try | catch /pat/ | endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
545 try | catch /pat/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
546 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
547 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
548 catch /pat/ | endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
549 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
550 catch /pat/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
551 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
552 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
554 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
555 # string slice returns a string, not a number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
556 n = g:astring[3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
557 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
558 n = 77
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
559 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
560 assert_equal(77, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
561
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
562 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
563 n = l[g:astring]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
564 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
565 n = 88
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
566 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
567 assert_equal(88, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
569 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
570 n = s:does_not_exist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
571 catch /E121:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
572 n = 111
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
573 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
574 assert_equal(111, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
575
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
576 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
577 n = g:does_not_exist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
578 catch /E121:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
579 n = 121
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
580 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
581 assert_equal(121, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
582
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
583 var d = {one: 1}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
584 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
585 n = d[g:astring]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
586 catch /E716:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
587 n = 222
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
588 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
589 assert_equal(222, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
590
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
591 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
592 n = -g:astring
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
593 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
594 n = 233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
595 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
596 assert_equal(233, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
597
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
598 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
599 n = +g:astring
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
600 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
601 n = 244
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
602 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
603 assert_equal(244, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
604
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
605 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
606 n = +g:alist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
607 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
608 n = 255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
609 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
610 assert_equal(255, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
611
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
612 var nd: dict<any>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
613 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
614 nd = {[g:alist]: 1}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
615 catch /E1105:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
616 n = 266
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
617 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
618 assert_equal(266, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
620 l = [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
621 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
622 [n] = l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
623 catch /E1093:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
624 n = 277
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
625 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
626 assert_equal(277, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
628 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
629 &ts = g:astring
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
630 catch /E1012:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
631 n = 288
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
632 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
633 assert_equal(288, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
635 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
636 &backspace = 'asdf'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
637 catch /E474:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
638 n = 299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
639 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
640 assert_equal(299, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
641
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
642 l = [1]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
643 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
644 l[3] = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
645 catch /E684:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
646 n = 300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
647 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
648 assert_equal(300, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
649
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
650 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
651 unlet g:does_not_exist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
652 catch /E108:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
653 n = 322
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
654 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
655 assert_equal(322, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
656
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
657 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
658 d = {text: 1, [g:astring]: 2}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
659 catch /E721:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
660 n = 333
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
661 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
662 assert_equal(333, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
664 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
665 l = g:DeletedFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
666 catch /E933:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
667 n = 344
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
668 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
669 assert_equal(344, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
670
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
671 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
672 echo range(1, 2, 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
673 catch /E726:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
674 n = 355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
675 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
676 assert_equal(355, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
677
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
678 var P = function('g:NoSuchFunc')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
679 delfunc g:NoSuchFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
680 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
681 echo P()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
682 catch /E117:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
683 n = 366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
684 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
685 assert_equal(366, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
686
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
687 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
688 echo g:NoSuchFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
689 catch /E117:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
690 n = 377
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
691 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
692 assert_equal(377, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
693
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
694 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
695 echo g:alist + 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
696 catch /E745:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
697 n = 388
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
698 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
699 assert_equal(388, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
701 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
702 echo 4 + g:alist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
703 catch /E745:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
704 n = 399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
705 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
706 assert_equal(399, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
708 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
709 echo g:alist.member
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
710 catch /E715:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
711 n = 400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
712 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
713 assert_equal(400, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
714
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
715 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
716 echo d.member
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
717 catch /E716:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
718 n = 411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
719 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
720 assert_equal(411, n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
722 var counter = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
723 for i in range(4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
724 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
725 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
726 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
727 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
728 counter += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
729 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
730 assert_equal(4, counter)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
731
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
732 # no requirement for spaces before |
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
733 try|echo 0|catch|endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
735 # return in try with finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
736 def ReturnInTry(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
737 var ret = 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
738 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
739 return ret
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
740 catch /this/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
741 return -1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
742 catch /that/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
743 return -1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
744 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
745 # changing ret has no effect
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
746 ret = 7
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
747 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
748 return -2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
749 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
750 assert_equal(4, ReturnInTry())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
751
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
752 # return in catch with finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
753 def ReturnInCatch(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
754 var ret = 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
755 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
756 throw 'getout'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
757 return -1 # "unreachable code"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
758 catch /getout/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
759 # ret is evaluated here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
760 return ret
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
761 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
762 # changing ret later has no effect
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
763 ret = -3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
764 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
765 return -2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
766 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
767 assert_equal(5, ReturnInCatch())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
768
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
769 # return in finally after empty catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
770 def ReturnInFinally(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
771 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
772 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
773 return 6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
774 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
775 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
776 assert_equal(6, ReturnInFinally())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
777
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
778 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
779 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
780 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
781 acos('0.5')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
782 ->setline(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
783 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
784 g:caught = v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
785 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
786 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
787 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
788 assert_match('E1219: Float or Number required for argument 1', g:caught)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
789 unlet g:caught
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
790
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
791 # missing catch and/or finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
792 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
793 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
794 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
795 echo 'something'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
796 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
797 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
798 v9.CheckScriptFailure(lines, 'E1032:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
799
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
800 # skipping try-finally-endtry when try-finally-endtry is used in another block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
801 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
802 if v:true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
803 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
804 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
805 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
806 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
807 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
808 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
809 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
810 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
811 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
812 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
813 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
814
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
815 def Test_unreachable_after()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
816 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
817 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
818 throw 'Error'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
819 echo 'not reached'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
820 catch /Error/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
821 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
822 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
823 v9.CheckDefFailure(lines, 'E1095: Unreachable code after :throw')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
824
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
825 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
826 def SomeFunc(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
827 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
828 return 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
829 echo 'not reached'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
830 catch /Error/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
831 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
832 return 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
833 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
834 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
835 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
836 v9.CheckScriptFailure(lines, 'E1095: Unreachable code after :return')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
837 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
838
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
839 def Test_throw_in_nested_try()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
840 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
841 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
842
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
843 def Try(F: func(): void)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
844 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
845 F()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
846 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
847 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
848 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
850 class X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
851 def F()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
852 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
853 throw 'Foobar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
854 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
855 throw v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
856 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
857 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
858 endclass
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
860 def Test_TryMethod()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
861 var x = X.new()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
862 Try(() => x.F())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
863 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
864
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
865
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
866 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
867 Test_TryMethod()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
868 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
869 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
870 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
871 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
872 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
874 def Test_try_var_decl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
875 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
876 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
877 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
878 var in_try = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
879 assert_equal(1, get(s:, 'in_try', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
880 throw "getout"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
881 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
882 var in_catch = 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
883 assert_equal(-1, get(s:, 'in_try', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
884 assert_equal(2, get(s:, 'in_catch', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
885 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
886 var in_finally = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
887 assert_equal(-1, get(s:, 'in_try', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
888 assert_equal(-1, get(s:, 'in_catch', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
889 assert_equal(3, get(s:, 'in_finally', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
890 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
891 assert_equal(-1, get(s:, 'in_try', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
892 assert_equal(-1, get(s:, 'in_catch', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
893 assert_equal(-1, get(s:, 'in_finally', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
894 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
895 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
896 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
898 def Test_try_ends_in_return()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
899 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
900 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
901 def Foo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
902 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
903 return 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
904 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
905 return 'caught'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
906 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
907 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
908 assert_equal('foo', Foo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
909 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
910 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
911
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
912 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
913 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
914 def Foo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
915 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
916 return 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
917 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
918 return 'caught'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
919 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
920 echo 'notreached'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
921 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
922 assert_equal('foo', Foo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
923 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
924 v9.CheckScriptFailure(lines, 'E1095:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
925
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
926 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
927 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
928 def Foo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
929 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
930 return 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
931 catch /x/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
932 return 'caught'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
933 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
934 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
935 assert_equal('foo', Foo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
936 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
937 v9.CheckScriptFailure(lines, 'E1027:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
938
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
939 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
940 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
941 def Foo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
942 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
943 echo 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
944 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
945 echo 'caught'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
946 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
947 return 'done'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
948 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
949 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
950 assert_equal('done', Foo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
951 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
952 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
953
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
954 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
956 def Test_try_in_catch()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
957 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
958 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
959 var seq = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
960 def DoIt()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
961 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
962 seq->add('throw 1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
963 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
964 seq->add('notreached')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
965 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
966 seq->add('catch')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
967 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
968 seq->add('throw 2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
969 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
970 seq->add('notreached')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
971 catch /nothing/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
972 seq->add('notreached')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
973 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
974 seq->add('done')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
975 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
976 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
977 DoIt()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
978 assert_equal(['throw 1', 'catch', 'throw 2', 'done'], seq)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
979 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
980 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
982 def Test_error_in_catch()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
983 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
984 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
985 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
986 catch /E684:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
987 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
988 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
989 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
990 v9.CheckDefExecFailure(lines, 'E684:', 4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
991 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
993 " :while at the very start of a function that :continue jumps to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
994 def s:TryContinueFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
995 while g:Count < 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
996 g:sequence ..= 't'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
997 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
998 echoerr 'Test'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
999 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1000 g:Count += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1001 g:sequence ..= 'c'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1002 continue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1003 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1004 g:sequence ..= 'e'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1005 g:Count += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1006 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1007 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1008
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1009 def Test_continue_in_try_in_while()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1010 g:Count = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1011 g:sequence = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1012 TryContinueFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1013 assert_equal('tctc', g:sequence)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1014 unlet g:Count
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1015 unlet g:sequence
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1016 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1018 def Test_break_in_try_in_for()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1019 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1020 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1021 def Ls(): list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1022 var ls: list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1023 for s in ['abc', 'def']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1024 for _ in [123, 456]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1025 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1026 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1027 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1028 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1029 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1030 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1031 ls += [s]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1032 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1033 return ls
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1034 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1035 assert_equal(['abc', 'def'], Ls())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1036 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1037 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1038 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1039
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1040 def Test_nocatch_return_in_try()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1041 # return in try block returns normally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1042 def ReturnInTry(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1043 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1044 return '"some message"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1045 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1046 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1047 return 'not reached'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1048 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1049 exe 'echoerr ' .. ReturnInTry()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1050 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1051
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1052 def Test_cnext_works_in_catch()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1053 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1054 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1055 au BufEnter * eval 1 + 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1056 writefile(['text'], 'Xcncfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1057 writefile(['text'], 'Xcncfile2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1058 var items = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1059 {lnum: 1, filename: 'Xcncfile1', valid: true},
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1060 {lnum: 1, filename: 'Xcncfile2', valid: true}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1061 ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1062 setqflist([], ' ', {items: items})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1063 cwindow
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1065 def CnextOrCfirst()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1066 # if cnext fails, cfirst is used
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1067 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1068 cnext
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1069 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1070 cfirst
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1071 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1072 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1073
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1074 CnextOrCfirst()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1075 CnextOrCfirst()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1076 writefile([getqflist({idx: 0}).idx], 'Xcncresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1077 qall
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1078 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1079 writefile(lines, 'XCatchCnext', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1080 g:RunVim([], [], '--clean -S XCatchCnext')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1081 assert_equal(['1'], readfile('Xcncresult'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1083 delete('Xcncfile1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1084 delete('Xcncfile2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1085 delete('Xcncresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1086 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1087
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1088 def Test_throw_skipped()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1089 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1090 throw dontgethere
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1091 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1092 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1094 def Test_nocatch_throw_silenced()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1095 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1096 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1097 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1098 throw 'error'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1099 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1100 silent! Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1101 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1102 writefile(lines, 'XthrowSilenced', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1103 source XthrowSilenced
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1104 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1106 " g:DeletedFunc() is found when compiling Test_try_catch_throw() and then
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1107 " deleted, this should give a runtime error.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1108 def DeletedFunc(): list<any>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1109 return ['delete me']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1110 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1111 defcompile DeletedFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1113 call test_override('unreachable', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1114 defcompile Test_try_catch_throw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1115 call test_override('unreachable', 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1117 delfunc DeletedFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1118
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1119 def s:ThrowFromDef()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1120 throw "getout" # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1121 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1123 func s:CatchInFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1124 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1125 call s:ThrowFromDef()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1126 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1127 let g:thrown_func = v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1128 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1129 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1130
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1131 def s:CatchInDef()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1132 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1133 ThrowFromDef()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1134 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1135 g:thrown_def = v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1136 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1137 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1139 def s:ReturnFinally(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1140 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1141 return 'intry'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1142 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1143 g:in_finally = 'finally'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1144 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1145 return 'end'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1146 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1147
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1148 def Test_try_catch_nested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1149 CatchInFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1150 assert_equal('getout', g:thrown_func)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1151
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1152 CatchInDef()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1153 assert_equal('getout', g:thrown_def)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1154
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1155 assert_equal('intry', ReturnFinally())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1156 assert_equal('finally', g:in_finally)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1157
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1158 var l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1159 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1160 l->add('1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1161 throw 'bad'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1162 l->add('x') # "unreachable code"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1163 catch /bad/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1164 l->add('2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1165 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1166 l->add('3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1167 throw 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1168 l->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1169 catch /one/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1170 l->add('4')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1171 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1172 l->add('5')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1173 throw 'more'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1174 l->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1175 catch /more/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1176 l->add('6')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1177 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1178 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1179 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1180 assert_equal(['1', '2', '3', '4', '5', '6'], l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1182 l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1183 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1184 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1185 l->add('1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1186 throw 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1187 l->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1188 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1189 l->add('2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1190 throw 'bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1191 l->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1192 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1193 l->add('3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1194 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1195 l->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1196 catch /bar/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1197 l->add('4')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1198 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1199 assert_equal(['1', '2', '3', '4'], l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1200 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1201
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1202 call test_override('unreachable', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1203 defcompile Test_try_catch_nested
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1204 call test_override('unreachable', 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1205
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1206 def s:TryOne(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1207 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1208 return 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1209 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1210 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1211 return 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1212 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1213
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1214 def s:TryTwo(n: number): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1215 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1216 var x = {}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1217 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1218 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1219 return 'text'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1220 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1221
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1222 def Test_try_catch_twice()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1223 assert_equal('text', TryOne()->TryTwo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1224 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1225
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1226 def Test_try_catch_match()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1227 var seq = 'a'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1228 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1229 throw 'something'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1230 catch /nothing/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1231 seq ..= 'x'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1232 catch /some/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1233 seq ..= 'b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1234 catch /asdf/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1235 seq ..= 'x'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1236 catch ?a\?sdf?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1237 seq ..= 'y'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1238 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1239 seq ..= 'c'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1240 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1241 assert_equal('abc', seq)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1242 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1244 def Test_try_catch_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1245 v9.CheckDefFailure(['catch'], 'E603:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1246 v9.CheckDefFailure(['try', 'echo 0', 'catch', 'catch'], 'E1033:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1247 v9.CheckDefFailure(['try', 'echo 0', 'catch /pat'], 'E1067:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1248 v9.CheckDefFailure(['finally'], 'E606:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1249 v9.CheckDefFailure(['try', 'echo 0', 'finally', 'echo 1', 'finally'], 'E607:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1250 v9.CheckDefFailure(['endtry'], 'E602:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1251 v9.CheckDefFailure(['while 1', 'endtry'], 'E170:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1252 v9.CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1253 v9.CheckDefFailure(['if 1', 'endtry'], 'E171:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1254 v9.CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1255
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1256 v9.CheckDefFailure(['throw'], 'E1143:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1257 v9.CheckDefFailure(['throw xxx'], 'E1001:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1258 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1260 def Try_catch_skipped()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1261 var l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1262 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1263 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1264 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1265
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1266 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1267 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1268 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1269 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1270 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1271 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1272
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1273 " The skipped try/endtry was updating the wrong instruction.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1274 def Test_try_catch_skipped()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1275 var instr = execute('disassemble Try_catch_skipped')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1276 assert_match("NEWLIST size 0\n", instr)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1277 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1279 def Test_throw_line_number()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1280 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1281 eval 1 + 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1282 eval 2 + 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1283 throw 'exception'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1284 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1285 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1286 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1287 catch /exception/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1288 assert_match('line 3', v:throwpoint)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1289 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1290 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1292
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1293 def Test_throw_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1294 # only checks line continuation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1295 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1296 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1297 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1298 throw 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1299 .. 'two'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1300 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1301 assert_equal('onetwo', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1302 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1303 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1304 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1306 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1307 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1308 @r = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1309 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1310 throw @r
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1311 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1312 var result = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1313 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1314 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1315 catch /E1129:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1316 result = 'caught'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1317 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1318 assert_equal('caught', result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1319 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1320 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1321 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1322
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1323 def Test_error_in_nested_function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1324 # an error in a nested :function aborts executing in the calling :def function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1325 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1326 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1327 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1328 Error()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1329 g:test_var = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1330 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1331 func Error() abort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1332 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1333 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1334 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1335 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1336 g:test_var = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1337 v9.CheckScriptFailure(lines, 'E684:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1338 assert_equal(0, g:test_var)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1339 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1340
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1341 def Test_abort_after_error()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1342 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1343 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1344 while true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1345 echo notfound
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1346 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1347 g:gotthere = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1348 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1349 g:gotthere = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1350 v9.CheckScriptFailure(lines, 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1351 assert_false(g:gotthere)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1352 unlet g:gotthere
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1353 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1354
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1355 def Test_cexpr_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1356 # only checks line continuation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1357 set errorformat=File\ %f\ line\ %l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1358 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1359 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1360 cexpr 'File'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1361 .. ' someFile' ..
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1362 ' line 19'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1363 assert_equal(19, getqflist()[0].lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1364 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1365 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1366
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1367 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1368 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1369 def CexprFail()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1370 au QuickfixCmdPre * echo g:doesnotexist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1371 cexpr 'File otherFile line 99'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1372 g:didContinue = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1373 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1374 CexprFail()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1375 g:didContinue = 'also'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1376 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1377 g:didContinue = 'no'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1378 v9.CheckScriptFailure(lines, 'E121: Undefined variable: g:doesnotexist')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1379 assert_equal('no', g:didContinue)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1380 au! QuickfixCmdPre
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1381
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1382 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1383 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1384 def CexprFail()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1385 cexpr g:aNumber
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1386 g:didContinue = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1387 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1388 CexprFail()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1389 g:didContinue = 'also'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1390 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1391 g:aNumber = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1392 g:didContinue = 'no'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1393 v9.CheckScriptFailure(lines, 'E777: String or List expected')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1394 assert_equal('no', g:didContinue)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1395 unlet g:didContinue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1397 set errorformat&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1398 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1399
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1400 def Test_statusline_syntax()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1401 # legacy syntax is used for 'statusline'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1402 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1403 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1404 func g:Status()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1405 return '%{"x" is# "x"}'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1406 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1407 set laststatus=2 statusline=%!Status()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1408 redrawstatus
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1409 set laststatus statusline=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1410 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1411 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1412 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1413
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1414 def Test_list_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1415 # checks line continuation and comments
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1416 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1417 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1418 var mylist = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1419 'one',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1420 # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1421 'two', # empty line follows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1422
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1423 'three',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1424 ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1425 assert_equal(['one', 'two', 'three'], mylist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1426 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1427 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1429 # check all lines from heredoc are kept
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1430 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1431 # comment 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1432 two
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1433 # comment 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1435 five
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1436 # comment 6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1437 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1438 assert_equal(['# comment 1', 'two', '# comment 3', '', 'five', '# comment 6'], lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1440 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1441 [{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1442 a: 0}]->string()->assert_equal("[{'a': 0}]")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1443 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1444 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1445 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1446
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1447 if has('channel')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1448 let someJob = test_null_job()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1449
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1450 def FuncWithError()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1451 echomsg g:someJob
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1452 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1453
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1454 func Test_convert_emsg_to_exception()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1455 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1456 call FuncWithError()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1457 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1458 call assert_match('Vim:E908:', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1459 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1460 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1461 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1463 def Test_vim9script_mix()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1464 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1465 if has(g:feature)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1466 " legacy script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1467 let g:legacy = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1468 finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1469 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1470 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1471 g:legacy = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1472 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1473 g:feature = 'eval'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1474 g:legacy = -1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1475 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1476 assert_equal(1, g:legacy)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1478 g:feature = 'noteval'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1479 g:legacy = -1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1480 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1481 assert_equal(0, g:legacy)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1482 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1484 def Test_vim9script_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1485 v9.CheckScriptFailure(['scriptversion 2', 'vim9script'], 'E1039:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1486 v9.CheckScriptFailure(['vim9script', 'scriptversion 2'], 'E1040:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1488 v9.CheckScriptFailure(['vim9script', 'var str: string', 'str = 1234'], 'E1012:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1489 v9.CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1491 assert_fails('vim9script', 'E1038:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1492 v9.CheckDefFailure(['vim9script'], 'E1038:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1493
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1494 # no error when skipping
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1495 if has('nothing')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1496 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1497 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1498 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1500 def Test_script_var_shadows_function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1501 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1502 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1503 def Func(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1504 return 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1505 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1506 var Func = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1507 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1508 v9.CheckScriptFailure(lines, 'E1041:', 5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1509 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1511 def Test_function_shadows_script_var()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1512 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1513 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1514 var Func = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1515 def Func(): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1516 return 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1517 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1518 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1519 v9.CheckScriptFailure(lines, 'E1041:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1520 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1521
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1522 def Test_script_var_shadows_command()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1523 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1524 var undo = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1525 undo = 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1526 assert_equal(2, undo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1527 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1528 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1529
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1530 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1531 var undo = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1532 undo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1533 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1534 v9.CheckDefAndScriptFailure(lines, 'E1207:', 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1535 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1537 def Test_vim9script_call_wrong_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1538 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1539 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1540 var Time = 'localtime'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1541 Time()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1542 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1543 v9.CheckScriptFailure(lines, 'E1085:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1544 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1545
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1546 def Test_vim9script_reload_delfunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1547 var first_lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1548 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1549 def FuncYes(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1550 return 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1551 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1552 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1553 var withno_lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1554 def FuncNo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1555 return 'no'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1556 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1557 def g:DoCheck(no_exists: bool)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1558 assert_equal('yes', FuncYes())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1559 assert_equal('no', FuncNo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1560 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1561 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1562 var nono_lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1563 def g:DoCheck(no_exists: bool)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1564 assert_equal('yes', FuncYes())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1565 assert_fails('FuncNo()', 'E117:', '', 2, 'DoCheck')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1566 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1567 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1569 # FuncNo() is defined
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1570 writefile(first_lines + withno_lines, 'Xreloaded.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1571 source Xreloaded.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1572 g:DoCheck(true)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1573
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1574 # FuncNo() is not redefined
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1575 writefile(first_lines + nono_lines, 'Xreloaded.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1576 source Xreloaded.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1577 g:DoCheck(false)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1579 # FuncNo() is back
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1580 writefile(first_lines + withno_lines, 'Xreloaded.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1581 source Xreloaded.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1582 g:DoCheck(false)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1583 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1584
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1585 def Test_vim9script_reload_delvar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1586 # write the script with a script-local variable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1587 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1588 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1589 var name = 'string'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1590 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1591 writefile(lines, 'XreloadVar.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1592 source XreloadVar.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1594 # now write the script using the same variable locally - works
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1595 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1596 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1597 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1598 var name = 'string'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1599 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1600 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1601 writefile(lines, 'XreloadVar.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1602 source XreloadVar.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1603 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1604
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1605 def Test_func_redefine_error()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1606 var lines = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1607 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1608 'def Func()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1609 ' eval [][0]',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1610 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1611 'Func()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1612 ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1613 writefile(lines, 'Xtestscript.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1614
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1615 for count in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1616 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1617 source Xtestscript.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1618 catch /E684/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1619 # function name should contain <SNR> every time
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1620 assert_match('E684: List index out of range', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1621 assert_match('function <SNR>\d\+_Func, line 1', v:throwpoint)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1622 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1623 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1624 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1625
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1626 def Test_func_redefine_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1627 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1628 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1629 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1630 echo 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1631 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1632 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1633 echo 'two'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1634 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1635 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1636 v9.CheckScriptFailure(lines, 'E1073:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1637
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1638 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1639 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1640 def Foo(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1641 return 'foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1642 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1643 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1644 var Foo = {-> 'lambda'}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1645 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1646 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1647 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1648 v9.CheckScriptFailure(lines, 'E1073:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1649 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1650
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1651 def Test_lambda_split()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1652 # this was using freed memory, because of the split expression
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1653 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1654 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1655 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1656 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1657 0->(0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1658 ->a.0(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1659 ->u
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1660 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1661 v9.CheckScriptFailure(lines, 'E1050:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1662 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1664 def Test_fixed_size_list()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1665 # will be allocated as one piece of memory, check that changes work
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1666 var l = [1, 2, 3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1667 l->remove(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1668 l->add(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1669 l->insert(99, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1670 assert_equal([2, 99, 3, 4, 5], l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1671 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1672
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1673 def Test_no_insert_xit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1674 v9.CheckDefExecFailure(['a = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1675 v9.CheckDefExecFailure(['c = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1676 v9.CheckDefExecFailure(['i = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1677 v9.CheckDefExecFailure(['t = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1678 v9.CheckDefExecFailure(['x = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1679
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1680 v9.CheckScriptFailure(['vim9script', 'a = 1'], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1681 v9.CheckScriptFailure(['vim9script', 'a'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1682 v9.CheckScriptFailure(['vim9script', 'c = 1'], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1683 v9.CheckScriptFailure(['vim9script', 'c'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1684 v9.CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1685 v9.CheckScriptFailure(['vim9script', 'i'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1686 v9.CheckScriptFailure(['vim9script', 'o = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1687 v9.CheckScriptFailure(['vim9script', 'o'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1688 v9.CheckScriptFailure(['vim9script', 't'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1689 v9.CheckScriptFailure(['vim9script', 't = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1690 v9.CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1691 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1693 def s:IfElse(what: number): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1694 var res = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1695 if what == 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1696 res = "one"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1697 elseif what == 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1698 res = "two"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1699 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1700 res = "three"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1701 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1702 return res
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1703 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1704
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1705 def Test_if_elseif_else()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1706 assert_equal('one', IfElse(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1707 assert_equal('two', IfElse(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1708 assert_equal('three', IfElse(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1709 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1711 def Test_if_elseif_else_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1712 v9.CheckDefFailure(['elseif true'], 'E582:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1713 v9.CheckDefFailure(['else'], 'E581:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1714 v9.CheckDefFailure(['endif'], 'E580:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1715 v9.CheckDefFailure(['if g:abool', 'elseif xxx'], 'E1001:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1716 v9.CheckDefFailure(['if true', 'echo 1'], 'E171:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1717
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1718 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1719 var s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1720 if s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1721 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1722 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1723 v9.CheckDefFailure(lines, 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1724
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1725 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1726 var s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1727 if s == ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1728 elseif s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1729 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1730 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1731 v9.CheckDefFailure(lines, 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1732
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1733 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1734 var cond = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1735 if cond
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1736 echo 'true'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1737 elseif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1738 echo 'false'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1739 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1740 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1741 v9.CheckDefAndScriptFailure(lines, ['E1143:', 'E15:'], 4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1742 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1744 def Test_if_else_func_using_var()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1745 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1746 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1748 const debug = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1749 if debug
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1750 var mode_chars = 'something'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1751 def Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1752 var x = mode_chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1753 g:where = 'in true'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1754 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1755 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1756 def Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1757 g:where = 'in false'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1758 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1759 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1760
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1761 Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1762 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1763 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1764 assert_equal('in true', g:where)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1765 unlet g:where
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1766
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1767 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1768 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1769
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1770 const debug = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1771 if debug
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1772 var mode_chars = 'something'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1773 def Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1774 g:where = 'in true'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1775 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1776 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1777 def Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1778 var x = mode_chars
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1779 g:where = 'in false'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1780 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1781 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1782
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1783 Bits2Ascii()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1784 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1785 v9.CheckScriptFailure(lines, 'E1001: Variable not found: mode_chars')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1786 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1788 let g:bool_true = v:true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1789 let g:bool_false = v:false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1790
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1791 def Test_if_const_expr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1792 var res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1793 if true ? true : false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1794 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1795 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1796 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1797
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1798 g:glob = 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1799 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1800 execute('g:glob = 3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1801 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1802 assert_equal(2, g:glob)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1803 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1804 execute('g:glob = 3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1805 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1806 assert_equal(3, g:glob)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1807
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1808 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1809 if g:bool_true ? true : false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1810 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1811 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1812 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1813
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1814 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1815 if true ? g:bool_true : false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1816 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1817 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1818 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1819
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1820 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1821 if true ? true : g:bool_false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1822 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1823 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1824 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1825
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1826 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1827 if true ? false : true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1828 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1829 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1830 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1831
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1832 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1833 if false ? false : true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1834 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1835 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1836 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1837
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1838 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1839 if false ? true : false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1840 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1841 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1842 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1844 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1845 if has('xyz') ? true : false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1846 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1847 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1848 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1850 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1851 if true && true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1852 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1853 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1854 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1856 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1857 if true && false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1858 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1859 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1860 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1861
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1862 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1863 if g:bool_true && false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1864 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1865 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1866 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1868 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1869 if true && g:bool_false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1870 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1871 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1872 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1874 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1875 if false && false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1876 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1877 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1878 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1879
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1880 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1881 if true || false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1882 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1883 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1884 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1885
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1886 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1887 if g:bool_true || false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1888 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1889 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1890 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1892 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1893 if true || g:bool_false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1894 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1895 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1896 assert_equal(true, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1898 res = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1899 if false || false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1900 res = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1901 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1902 assert_equal(false, res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1903
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1904 # with constant "false" expression may be invalid so long as the syntax is OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1905 if false | eval 1 + 2 | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1906 if false | eval burp + 234 | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1907 if false | echo burp 234 'asd' | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1908 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1909 burp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1910 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1911
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1912 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1913 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1914 echo nothing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1915 elseif 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1916 echo still nothing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1917 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1918 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1920 # expression with line breaks skipped
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1921 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1922 ('aaa'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1923 .. 'bbb'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1924 .. 'ccc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1925 )->setline(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1926 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1927 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1928
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1929 def Test_if_const_expr_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1930 v9.CheckDefFailure(['if "aaa" == "bbb'], 'E114:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1931 v9.CheckDefFailure(["if 'aaa' == 'bbb"], 'E115:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1932 v9.CheckDefFailure(["if has('aaa'"], 'E110:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1933 v9.CheckDefFailure(["if has('aaa') ? true false"], 'E109:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1934 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1936 def s:RunNested(i: number): number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1937 var x: number = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1938 if i % 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1939 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1940 # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1941 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1942 # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1943 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1944 x += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1945 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1946 x += 1000
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1947 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1948 return x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1949 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1950
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1951 def Test_nested_if()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1952 assert_equal(1, RunNested(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1953 assert_equal(1000, RunNested(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1954 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1956 def Test_execute_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1957 # missing argument is ignored
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1958 execute
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1959 execute # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1961 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1962 setline(1, 'default')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1963 execute 'setline(1, "execute-string")'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1964 assert_equal('execute-string', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1965
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1966 execute "setline(1, 'execute-string')"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1967 assert_equal('execute-string', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1968
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1969 var cmd1 = 'setline(1,'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1970 var cmd2 = '"execute-var")'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1971 execute cmd1 cmd2 # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1972 assert_equal('execute-var', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1974 execute cmd1 cmd2 '|setline(1, "execute-var-string")'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1975 assert_equal('execute-var-string', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1976
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1977 var cmd_first = 'call '
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1978 var cmd_last = 'setline(1, "execute-var-var")'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1979 execute cmd_first .. cmd_last
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1980 assert_equal('execute-var-var', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1981 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1982
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1983 var n = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1984 execute 'echomsg' (n ? '"true"' : '"no"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1985 assert_match('^true$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1987 echomsg [1, 2, 3] {a: 1, b: 2}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1988 assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1989
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1990 v9.CheckDefFailure(['execute xxx'], 'E1001:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1991 v9.CheckDefExecFailure(['execute "tabnext " .. 8'], 'E475:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1992 v9.CheckDefFailure(['execute "cmd"# comment'], 'E488:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1993 if has('channel')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1994 v9.CheckDefExecFailure(['execute test_null_channel()'], 'E908:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1995 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1996 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1998 def Test_execute_cmd_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
1999 # only checks line continuation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2000 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2001 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2002 execute 'g:someVar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2003 .. ' = ' ..
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2004 '28'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2005 assert_equal(28, g:someVar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2006 unlet g:someVar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2007 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2008 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2009 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2011 def Test_execute_finish()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2012 # the empty lines are relevant here
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2013 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2014 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2015
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2016 var vname = "g:hello"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2018 if exists(vname) | finish | endif | execute vname '= "world"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2019
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2020 assert_equal('world', g:hello)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2022 if exists(vname) | finish | endif | execute vname '= "world"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2023
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2024 assert_report('should not be reached')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2025 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2026 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2027 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2028
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2029 def Test_echo_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2030 echo 'some' # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2031 echon 'thing'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2032 assert_match('^something$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2034 echo "some" # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2035 echon "thing"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2036 assert_match('^something$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2037
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2038 var str1 = 'some'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2039 var str2 = 'more'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2040 echo str1 str2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2041 assert_match('^some more$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2043 echo "one\ntwo"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2044 assert_match('^one$', g:Screenline(&lines - 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2045 assert_match('^two$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2047 v9.CheckDefFailure(['echo "xxx"# comment'], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2048 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2049
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2050 def Test_echomsg_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2051 echomsg 'some' 'more' # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2052 assert_match('^some more$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2053 echo 'clear'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2054 :1messages
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2055 assert_match('^some more$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2056
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2057 v9.CheckDefFailure(['echomsg "xxx"# comment'], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2058 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2060 def Test_echomsg_cmd_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2061 # only checks line continuation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2062 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2063 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2064 echomsg 'here'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2065 .. ' is ' ..
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2066 'a message'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2067 assert_match('^here is a message$', g:Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2068 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2069 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2070 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2072 def Test_echoerr_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2073 var local = 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2074 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2075 echoerr 'something' local 'wrong' # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2076 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2077 assert_match('something local wrong', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2078 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2079 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2080
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2081 def Test_echoerr_cmd_vimscript()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2082 # only checks line continuation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2083 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2084 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2085 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2086 echoerr 'this'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2087 .. ' is ' ..
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2088 'wrong'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2089 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2090 assert_match('this is wrong', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2091 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2092 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2093 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2094 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2095
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2096 def Test_echoconsole_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2097 var local = 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2098 echoconsole 'something' local # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2099 # output goes anywhere
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2100 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2101
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2102 def Test_echowindow_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2103 var local = 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2104 echowindow 'something' local # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2106 # with modifier
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2107 unsilent echowin 'loud'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2109 # output goes in message window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2110 popup_clear()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2111 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2113 def Test_for_outside_of_function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2114 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2115 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2116 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2117 for var in range(0, 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2118 append(line('$'), var)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2119 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2120 assert_equal(['', '0', '1', '2', '3'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2121 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2123 var result = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2124 for i in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2125 var loop = ' loop ' .. i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2126 result ..= loop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2127 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2128 assert_equal(' loop 1 loop 2 loop 3', result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2129 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2130 writefile(lines, 'Xvim9for.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2131 source Xvim9for.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2132 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2133
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2134 def Test_for_skipped_block()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2135 # test skipped blocks at outside of function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2136 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2137 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2138 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2139 for n in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2140 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2141 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2142 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2143 for n in [3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2144 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2145 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2146 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2147 assert_equal([1, 2], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2148
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2149 result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2150 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2151 for n in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2152 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2153 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2154 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2155 for n in [3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2156 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2157 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2158 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2159 assert_equal([3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2160 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2161 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2162
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2163 # test skipped blocks at inside of function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2164 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2165 def DefTrue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2166 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2167 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2168 for n in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2169 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2170 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2171 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2172 for n in [3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2173 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2174 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2175 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2176 assert_equal([1, 2], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2177 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2178 DefTrue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2180 def DefFalse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2181 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2182 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2183 for n in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2184 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2185 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2186 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2187 for n in [3, 4]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2188 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2189 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2190 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2191 assert_equal([3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2192 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2193 DefFalse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2195 def BuildDiagrams()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2196 var diagrams: list<any>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2197 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2198 var max = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2199 for v in diagrams
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2200 var l = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2201 if max < l | max = l | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2202 v->add(l)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2203 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2204 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2205 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2206 BuildDiagrams()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2207 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2208 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2209 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2211 def Test_skipped_redir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2212 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2213 def Tredir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2214 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2215 redir => l[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2216 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2217 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2218 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2219 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2220 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2221 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2222 delfunc g:Tredir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2224 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2225 def Tredir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2226 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2227 redir => l[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2228 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2229 echo 'executed'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2230 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2231 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2232 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2233 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2234 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2235 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2236 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2237 delfunc g:Tredir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2239 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2240 def Tredir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2241 var l = ['']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2242 if 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2243 redir => l[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2244 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2245 echo 'executed'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2246 if 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2247 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2248 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2249 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2250 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2251 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2252 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2253 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2254 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2255 delfunc g:Tredir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2257 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2258 let doit = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2259 def Tredir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2260 var l = ['']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2261 if g:doit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2262 redir => l[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2263 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2264 echo 'executed'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2265 if g:doit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2266 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2267 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2268 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2269 defcompile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2270 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2271 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2272 delfunc g:Tredir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2273 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2274
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2275 def Test_for_loop()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2276 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2277 var result = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2278 for cnt in range(7)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2279 if cnt == 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2280 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2281 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2282 if cnt == 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2283 continue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2284 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2285 result ..= cnt .. '_'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2286 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2287 assert_equal('0_1_3_', result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2288
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2289 var concat = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2290 for str in eval('["one", "two"]')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2291 concat ..= str
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2292 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2293 assert_equal('onetwo', concat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2295 var total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2296 for nr in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2297 [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2298 total += nr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2299 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2300 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2302 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2303 for nr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2304 in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2305 total += nr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2306 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2307 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2308
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2309 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2310 for nr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2311 in
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2312 [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2313 total += nr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2314 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2315 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2317 # with type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2318 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2319 for n: number in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2320 total += n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2321 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2322 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2324 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2325 for b in 0z010203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2326 total += b
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2327 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2328 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2330 var chars = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2331 for s: string in 'foobar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2332 chars ..= s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2333 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2334 assert_equal('foobar', chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2335
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2336 chars = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2337 for x: string in {a: 'a', b: 'b'}->values()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2338 chars ..= x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2339 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2340 assert_equal('ab', chars)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2342 # unpack with type
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2343 var res = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2344 for [n: number, s: string] in [[1, 'a'], [2, 'b']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2345 res ..= n .. s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2346 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2347 assert_equal('1a2b', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2348
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2349 # unpack with one var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2350 var reslist = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2351 for [x] in [['aaa'], ['bbb']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2352 reslist->add(x)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2353 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2354 assert_equal(['aaa', 'bbb'], reslist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2356 # loop over string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2357 res = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2358 for c in 'aéc̀d'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2359 res ..= c .. '-'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2360 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2361 assert_equal('a-é-c̀-d-', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2362
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2363 res = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2364 for c in ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2365 res ..= c .. '-'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2366 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2367 assert_equal('', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2369 res = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2370 for c in test_null_string()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2371 res ..= c .. '-'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2372 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2373 assert_equal('', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2374
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2375 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2376 for c in null_list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2377 total += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2378 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2379 assert_equal(0, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2381 for c in null_blob
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2382 total += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2383 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2384 assert_equal(0, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2385
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2386 var foo: list<dict<any>> = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2387 {a: 'Cat'}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2388 ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2389 for dd in foo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2390 dd.counter = 12
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2391 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2392 assert_equal([{a: 'Cat', counter: 12}], foo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2393
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2394 reslist = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2395 for _ in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2396 reslist->add('x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2397 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2398 assert_equal(['x', 'x', 'x'], reslist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2399 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2400 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2401 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2402
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2403 def Test_for_loop_list_of_lists()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2404 # loop variable is final, not const
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2405 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2406 # Filter out all odd numbers in each sublist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2407 var list: list<list<number>> = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2408 for i in list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2409 filter(i, (_, n: number): bool => n % 2 == 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2410 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2411
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2412 assert_equal([[], [2], [2], [2, 4]], list)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2413 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2414 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2415 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2417 def Test_for_loop_with_closure()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2418 # using the loop variable in a closure results in the last used value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2419 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2420 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2421 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2422 flist[i] = () => i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2423 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2424 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2425 assert_equal(4, flist[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2426 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2427 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2428 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2430 # also works when the loop variable is used only once halfway the loops
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2431 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2432 var Clo: func
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2433 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2434 if i == 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2435 Clo = () => i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2436 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2437 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2438 assert_equal(4, Clo())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2439 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2440 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2441
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2442 # using a local variable set to the loop variable in a closure results in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2443 # value at that moment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2444 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2445 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2446 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2447 var inloop = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2448 flist[i] = () => inloop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2449 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2450 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2451 assert_equal(i, flist[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2452 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2453 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2454 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2456 # also with an extra block level
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2457 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2458 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2459 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2460 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2461 var inloop = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2462 flist[i] = () => inloop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2463 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2464 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2465 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2466 assert_equal(i, flist[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2467 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2468 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2469 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2471 # and declaration in higher block
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2472 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2473 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2474 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2475 var inloop = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2476 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2477 flist[i] = () => inloop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2478 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2479 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2480 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2481 assert_equal(i, flist[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2482 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2483 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2484 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2485
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2486 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2487 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2488 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2489 var inloop = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2490 flist[i] = () => {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2491 return inloop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2492 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2493 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2494 for i in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2495 assert_equal(i, flist[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2496 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2497 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2498 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2500 # Also works for a nested loop
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2501 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2502 var flist: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2503 var n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2504 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2505 var ii = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2506 for a in ['a', 'b', 'c']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2507 var aa = a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2508 flist[n] = () => ii .. aa
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2509 ++n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2510 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2511 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2512
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2513 n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2514 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2515 for a in ['a', 'b', 'c']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2516 assert_equal(i .. a, flist[n]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2517 ++n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2518 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2519 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2520 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2521 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2523 # using two loop variables
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2524 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2525 var lv_list: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2526 var copy_list: list<func>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2527 for [idx, c] in items('word')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2528 var lidx = idx
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2529 var lc = c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2530 lv_list[idx] = () => {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2531 return idx .. c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2532 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2533 copy_list[idx] = () => {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2534 return lidx .. lc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2535 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2536 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2537 for [i, c] in items('word')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2538 assert_equal(3 .. 'd', lv_list[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2539 assert_equal(i .. c, copy_list[i]())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2540 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2541 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2542 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2543 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2544
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2545 def Test_define_global_closure_in_loops()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2546 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2547 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2549 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2550 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2551 var ii = i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2552 for a in ['a', 'b', 'c']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2553 var aa = a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2554 if ii == 0 && aa == 'a'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2555 def g:Global_0a(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2556 return ii .. aa
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2557 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2558 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2559 if ii == 1 && aa == 'b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2560 def g:Global_1b(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2561 return ii .. aa
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2562 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2563 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2564 if ii == 2 && aa == 'c'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2565 def g:Global_2c(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2566 return ii .. aa
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2567 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2568 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2569 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2570 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2571 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2572 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2573 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2574 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2575 assert_equal("0a", g:Global_0a())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2576 assert_equal("1b", g:Global_1b())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2577 assert_equal("2c", g:Global_2c())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2579 delfunc g:Global_0a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2580 delfunc g:Global_1b
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2581 delfunc g:Global_2c
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2582 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2583
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2584 def Test_for_loop_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2585 v9.CheckDefAndScriptFailure(['for '], ['E1097:', 'E690:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2586 v9.CheckDefAndScriptFailure(['for x'], ['E1097:', 'E690:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2587 v9.CheckDefAndScriptFailure(['for x in'], ['E1097:', 'E15:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2588 v9.CheckDefAndScriptFailure(['for # in range(5)'], 'E690:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2589 v9.CheckDefAndScriptFailure(['for i In range(5)'], 'E690:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2590 v9.CheckDefAndScriptFailure(['var x = 5', 'for x in range(5)', 'endfor'], ['E1017:', 'E1041:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2591 v9.CheckScriptFailure(['vim9script', 'var x = 5', 'for x in range(5)', '# comment', 'endfor'], 'E1041:', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2592 v9.CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2593 delfunc! g:Func
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2594 v9.CheckDefFailure(['for i in xxx'], 'E1001:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2595 v9.CheckDefFailure(['endfor'], 'E588:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2596 v9.CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2597
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2598 # wrong type detected at compile time
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2599 v9.CheckDefFailure(['for i in {a: 1}', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2600
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2601 # wrong type detected at runtime
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2602 g:adict = {a: 1}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2603 v9.CheckDefExecFailure(['for i in g:adict', 'echo 3', 'endfor'], 'E1177: For loop on dict not supported')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2604 unlet g:adict
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2605
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2606 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2607 var d: list<dict<any>> = [{a: 0}]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2608 for e in d
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2609 e = {a: 0, b: ''}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2610 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2611 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2612 v9.CheckDefAndScriptFailure(lines, ['E1018:', 'E46:'], 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2614 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2615 for nr: number in ['foo']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2616 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2617 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2618 v9.CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2619
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2620 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2621 for n : number in [1, 2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2622 echo n
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2623 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2624 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2625 v9.CheckDefAndScriptFailure(lines, 'E1059:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2627 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2628 var d: dict<number> = {a: 1, b: 2}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2629 for [k: job, v: job] in d->items()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2630 echo k v
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2631 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2632 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2633 v9.CheckDefExecAndScriptFailure(lines, ['E1163: Variable 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2634
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2635 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2636 var i = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2637 for i in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2638 echo i
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2639 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2640 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2641 v9.CheckDefExecAndScriptFailure(lines, ['E1017:', 'E1041:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2643 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2644 var l = [0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2645 for l[0] in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2646 echo l[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2647 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2648 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2649 v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2650
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2651 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2652 var d = {x: 0}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2653 for d.x in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2654 echo d.x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2655 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2656 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2657 v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2658
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2659 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2660 var l: list<dict<any>> = [{a: 1, b: 'x'}]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2661 for item: dict<number> in l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2662 echo item
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2663 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2664 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2665 v9.CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<number> but got dict<any>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2666
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2667 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2668 var l: list<dict<any>> = [{n: 1}]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2669 for item: dict<number> in l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2670 var d = {s: ''}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2671 d->extend(item)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2672 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2673 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2674 v9.CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<string> but got dict<number>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2675
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2676 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2677 for a in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2678 while a > 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2679 for b in range(2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2680 while b < 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2681 for c in range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2682 while c > 6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2683 while c < 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2684 for d in range(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2685 for e in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2686 while e > 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2687 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2688 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2689 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2690 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2691 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2692 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2693 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2694 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2695 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2696 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2697 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2698 v9.CheckDefSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2700 v9.CheckDefFailure(['for x in range(3)'] + lines + ['endfor'], 'E1306:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2701 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2702
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2703 def Test_for_loop_script_var()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2704 # cannot use s:var in a :def function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2705 v9.CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1254:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2706
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2707 # can use s:var in Vim9 script, with or without s:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2708 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2709 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2710 var total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2711 for s:var in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2712 total += s:var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2713 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2714 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2715
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2716 total = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2717 for var in [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2718 total += var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2719 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2720 assert_equal(6, total)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2721 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2722 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2723
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2724 def Test_for_loop_unpack()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2725 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2726 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2727 for [v1, v2] in [[1, 2], [3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2728 result->add(v1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2729 result->add(v2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2730 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2731 assert_equal([1, 2, 3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2732
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2733 result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2734 for [v1, v2; v3] in [[1, 2], [3, 4, 5, 6]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2735 result->add(v1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2736 result->add(v2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2737 result->add(v3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2738 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2739 assert_equal([1, 2, [], 3, 4, [5, 6]], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2741 result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2742 for [&ts, &sw] in [[1, 2], [3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2743 result->add(&ts)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2744 result->add(&sw)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2745 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2746 assert_equal([1, 2, 3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2747
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2748 var slist: list<string>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2749 for [$LOOPVAR, @r, v:errmsg] in [['a', 'b', 'c'], ['d', 'e', 'f']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2750 slist->add($LOOPVAR)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2751 slist->add(@r)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2752 slist->add(v:errmsg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2753 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2754 assert_equal(['a', 'b', 'c', 'd', 'e', 'f'], slist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2755
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2756 slist = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2757 for [g:globalvar, b:bufvar, w:winvar, t:tabvar] in [['global', 'buf', 'win', 'tab'], ['1', '2', '3', '4']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2758 slist->add(g:globalvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2759 slist->add(b:bufvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2760 slist->add(w:winvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2761 slist->add(t:tabvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2762 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2763 assert_equal(['global', 'buf', 'win', 'tab', '1', '2', '3', '4'], slist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2764 unlet! g:globalvar b:bufvar w:winvar t:tabvar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2765
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2766 var res = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2767 for [_, n, _] in [[1, 2, 3], [4, 5, 6]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2768 res->add(n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2769 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2770 assert_equal([2, 5], res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2771
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2772 var text: list<string> = ["hello there", "goodbye now"]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2773 var splitted = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2774 for [first; next] in mapnew(text, (i, v) => split(v))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2775 splitted ..= string(first) .. string(next) .. '/'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2776 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2777 assert_equal("'hello'['there']/'goodbye'['now']/", splitted)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2778 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2779 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2781 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2782 for [v1, v2] in [[1, 2, 3], [3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2783 echo v1 v2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2784 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2785 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2786 v9.CheckDefExecFailure(lines, 'E710:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2787
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2788 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2789 for [v1, v2] in [[1], [3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2790 echo v1 v2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2791 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2792 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2793 v9.CheckDefExecFailure(lines, 'E711:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2794
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2795 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2796 for [v1, v1] in [[1, 2], [3, 4]]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2797 echo v1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2798 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2799 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2800 v9.CheckDefExecFailure(lines, 'E1017:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2802 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2803 for [a, b] in g:listlist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2804 echo a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2805 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2806 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2807 g:listlist = [1, 2, 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2808 v9.CheckDefExecFailure(lines, 'E1140:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2809 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2810
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2811 def Test_for_loop_with_try_continue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2812 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2813 var looped = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2814 var cleanup = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2815 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2816 looped += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2817 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2818 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2819 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2820 continue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2821 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2822 cleanup += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2823 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2824 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2825 assert_equal(3, looped)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2826 assert_equal(3, cleanup)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2827 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2828 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2829 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2830
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2831 def Test_while_skipped_block()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2832 # test skipped blocks at outside of function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2833 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2834 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2835 var n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2836 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2837 n = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2838 while n < 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2839 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2840 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2841 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2842 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2843 n = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2844 while n < 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2845 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2846 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2847 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2848 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2849 assert_equal([1, 2], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2850
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2851 result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2852 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2853 n = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2854 while n < 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2855 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2856 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2857 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2858 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2859 n = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2860 while n < 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2861 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2862 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2863 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2864 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2865 assert_equal([3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2866 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2867 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2868
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2869 # test skipped blocks at inside of function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2870 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2871 def DefTrue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2872 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2873 var n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2874 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2875 n = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2876 while n < 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2877 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2878 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2879 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2880 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2881 n = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2882 while n < 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2883 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2884 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2885 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2886 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2887 assert_equal([1, 2], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2888 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2889 DefTrue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2890
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2891 def DefFalse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2892 var result = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2893 var n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2894 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2895 n = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2896 while n < 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2897 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2898 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2899 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2900 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2901 n = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2902 while n < 5
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2903 result += [n]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2904 n += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2905 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2906 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2907 assert_equal([3, 4], result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2908 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2909 DefFalse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2910 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2911 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2912 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2913
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2914 def Test_while_loop()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2915 var result = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2916 var cnt = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2917 while cnt < 555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2918 if cnt == 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2919 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2920 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2921 cnt += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2922 if cnt == 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2923 continue
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2924 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2925 result ..= cnt .. '_'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2926 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2927 assert_equal('1_3_', result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2928
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2929 var s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2930 while s == 'x' # {comment}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2931 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2932 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2933
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2934 def Test_while_loop_in_script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2935 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2936 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2937 var result = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2938 var cnt = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2939 while cnt < 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2940 var s = 'v' .. cnt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2941 result ..= s
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2942 cnt += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2943 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2944 assert_equal('v0v1v2', result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2945 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2946 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2947 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2948
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2949 def Test_while_loop_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2950 v9.CheckDefFailure(['while xxx'], 'E1001:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2951 v9.CheckDefFailure(['endwhile'], 'E588:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2952 v9.CheckDefFailure(['continue'], 'E586:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2953 v9.CheckDefFailure(['if true', 'continue'], 'E586:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2954 v9.CheckDefFailure(['break'], 'E587:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2955 v9.CheckDefFailure(['if true', 'break'], 'E587:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2956 v9.CheckDefFailure(['while 1', 'echo 3'], 'E170:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2957
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2958 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2959 var s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2960 while s = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2961 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2962 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2963 v9.CheckDefFailure(lines, 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2964 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2965
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2966 def Test_interrupt_loop()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2967 var caught = false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2968 var x = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2969 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2970 while 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2971 x += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2972 if x == 100
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2973 feedkeys("\<C-C>", 'Lt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2974 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2975 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2976 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2977 caught = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2978 assert_equal(100, x)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2979 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2980 assert_true(caught, 'should have caught an exception')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2981 # consume the CTRL-C
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2982 getchar(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2983 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2984
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2985 def Test_automatic_line_continuation()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2986 var mylist = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2987 'one',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2988 'two',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2989 'three',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2990 ] # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2991 assert_equal(['one', 'two', 'three'], mylist)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2992
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2993 var mydict = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2994 ['one']: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2995 ['two']: 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2996 ['three']:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2997 3,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2998 } # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
2999 assert_equal({one: 1, two: 2, three: 3}, mydict)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3000 mydict = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3001 one: 1, # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3002 two: # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3003 2, # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3004 three: 3 # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3005 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3006 assert_equal({one: 1, two: 2, three: 3}, mydict)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3007 mydict = {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3008 one: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3009 two:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3010 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3011 three: 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3012 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3013 assert_equal({one: 1, two: 2, three: 3}, mydict)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3015 assert_equal(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3016 ['one', 'two', 'three'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3017 split('one two three')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3018 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3019 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3020
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3021 def Test_vim9_comment()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3022 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3023 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3024 '# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3025 '#something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3026 '#{{something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3027 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3028 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3029 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3030 '#{something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3031 ], 'E1170:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3032
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3033 split Xv9cfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3034 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3035 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3036 'edit #something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3037 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3038 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3039 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3040 'edit #{something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3041 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3042 close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3043
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3044 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3045 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3046 ':# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3047 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3048 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3049 '# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3050 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3051 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3052 ':# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3053 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3054
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3055 { # block start
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3056 } # block end
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3057 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3058 '{# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3059 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3060 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3061 '{',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3062 '}# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3063 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3065 echo "yes" # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3066 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3067 'echo "yes"# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3068 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3069 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3070 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3071 'echo "yes" # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3072 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3073 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3074 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3075 'echo "yes"# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3076 ], 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3077 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3078 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3079 'echo# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3080 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3081 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3082 'echo "yes" # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3083 ], 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3084
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3085 exe "echo" # comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3086 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3087 'exe "echo"# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3088 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3089 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3090 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3091 'exe "echo" # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3092 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3093 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3094 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3095 'exe "echo"# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3096 ], 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3097 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3098 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3099 'exe# something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3100 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3101 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3102 'exe "echo" # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3103 ], 'E121:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3105 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3106 'try# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3107 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3108 'catch',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3109 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3110 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3111 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3112 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3113 'try# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3114 'echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3115 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3116 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3117 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3118 ' throw#comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3119 'catch',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3120 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3121 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3122 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3123 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3124 ' throw "yes"#comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3125 'catch',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3126 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3127 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3128 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3129 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3130 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3131 'catch# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3132 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3133 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3134 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3135 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3136 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3137 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3138 'catch# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3139 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3140 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3141 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3142 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3143 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3144 'catch /pat/# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3145 'endtry',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3146 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3147 v9.CheckDefFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3148 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3149 'echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3150 'catch',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3151 'endtry# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3152 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3153 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3154 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3155 'try',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3156 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3157 'catch',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3158 'endtry# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3159 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3160
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3161 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3162 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3163 'hi # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3164 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3165 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3166 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3167 'hi# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3168 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3169 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3170 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3171 'hi Search # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3172 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3173 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3174 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3175 'hi Search# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3176 ], 'E416:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3177 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3178 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3179 'hi link This Search # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3180 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3181 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3182 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3183 'hi link This That# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3184 ], 'E413:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3185 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3186 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3187 'hi clear This # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3188 'hi clear # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3189 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3190 # not tested, because it doesn't give an error but a warning:
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3191 # hi clear This# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3192 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3193 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3194 'hi clear# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3195 ], 'E416:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3196
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3197 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3198 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3199 'hi Group term=bold',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3200 'match Group /todo/ # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3201 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3202 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3203 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3204 'hi Group term=bold',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3205 'match Group /todo/# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3206 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3207 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3208 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3209 'match # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3210 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3211 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3212 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3213 'match# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3214 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3215 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3216 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3217 'match none # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3218 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3219 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3220 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3221 'match none# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3222 ], 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3224 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3225 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3226 'menutrans clear # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3227 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3228 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3229 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3230 'menutrans clear# comment text',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3231 ], 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3232
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3233 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3234 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3235 'syntax clear # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3236 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3237 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3238 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3239 'syntax clear# comment text',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3240 ], 'E28:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3241 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3242 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3243 'syntax keyword Word some',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3244 'syntax clear Word # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3245 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3246 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3247 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3248 'syntax keyword Word some',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3249 'syntax clear Word# comment text',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3250 ], 'E28:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3251
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3252 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3253 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3254 'syntax list # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3255 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3256 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3257 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3258 'syntax list# comment text',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3259 ], 'E28:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3261 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3262 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3263 'syntax match Word /pat/ oneline # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3264 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3265 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3266 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3267 'syntax match Word /pat/ oneline# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3268 ], 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3270 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3271 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3272 'syntax keyword Word word # comm[ent',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3273 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3274 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3275 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3276 'syntax keyword Word word# comm[ent',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3277 ], 'E789:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3279 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3280 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3281 'syntax match Word /pat/ # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3282 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3283 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3284 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3285 'syntax match Word /pat/# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3286 ], 'E402:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3288 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3289 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3290 'syntax match Word /pat/ contains=Something # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3291 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3292 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3293 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3294 'syntax match Word /pat/ contains=Something# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3295 ], 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3296 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3297 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3298 'syntax match Word /pat/ contains= # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3299 ], 'E406:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3300 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3301 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3302 'syntax match Word /pat/ contains=# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3303 ], 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3305 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3306 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3307 'syntax region Word start=/pat/ end=/pat/ # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3308 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3309 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3310 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3311 'syntax region Word start=/pat/ end=/pat/# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3312 ], 'E402:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3313
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3314 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3315 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3316 'syntax sync # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3317 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3318 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3319 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3320 'syntax sync# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3321 ], 'E404:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3322 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3323 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3324 'syntax sync ccomment # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3325 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3326 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3327 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3328 'syntax sync ccomment# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3329 ], 'E404:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3330
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3331 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3332 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3333 'syntax cluster Some contains=Word # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3334 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3335 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3336 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3337 'syntax cluster Some contains=Word# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3338 ], 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3339
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3340 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3341 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3342 'command Echo echo # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3343 'command Echo # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3344 'delcommand Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3345 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3346 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3347 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3348 'command Echo echo# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3349 'Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3350 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3351 delcommand Echo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3352
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3353 var curdir = getcwd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3354 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3355 'command Echo cd " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3356 'Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3357 'delcommand Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3358 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3359 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3360 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3361 'command Echo cd # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3362 'Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3363 'delcommand Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3364 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3365 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3366 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3367 'command Echo cd " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3368 'Echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3369 ], 'E344:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3370 delcommand Echo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3371 chdir(curdir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3373 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3374 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3375 'command Echo# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3376 ], 'E182:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3377 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3378 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3379 'command Echo echo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3380 'command Echo# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3381 ], 'E182:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3382 delcommand Echo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3384 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3385 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3386 'function # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3387 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3388 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3389 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3390 'function " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3391 ], 'E129:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3392 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3393 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3394 'function# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3395 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3396 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3397 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3398 'import "./vim9.vim" as v9',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3399 'function v9.CheckScriptSuccess # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3400 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3401 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3402 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3403 'import "./vim9.vim" as v9',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3404 'function v9.CheckScriptSuccess# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3405 ], 'E1048: Item not found in script: CheckScriptSuccess#')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3406
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3407 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3408 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3409 'func g:DeleteMeA()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3410 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3411 'delfunction g:DeleteMeA # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3412 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3413 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3414 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3415 'func g:DeleteMeB()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3416 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3417 'delfunction g:DeleteMeB# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3418 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3419
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3420 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3421 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3422 'call execute("ls") # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3423 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3424 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3425 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3426 'call execute("ls")# comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3427 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3428
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3429 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3430 'def Test() " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3431 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3432 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3433 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3434 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3435 'def Test() " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3436 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3437 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3438
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3439 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3440 'func Test() " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3441 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3442 'delfunc Test',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3443 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3444 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3445 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3446 'func Test() " comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3447 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3448 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3449
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3450 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3451 'def Test() # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3452 'enddef',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3453 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3454 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3455 'func Test() # comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3456 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3457 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3458
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3459 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3460 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3461 syn region Text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3462 \ start='foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3463 #\ comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3464 \ end='bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3465 syn region Text start='foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3466 #\ comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3467 \ end='bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3468 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3469 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3470
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3471 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3472 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3473 syn region Text
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3474 \ start='foo'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3475 "\ comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3476 \ end='bar'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3477 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3478 v9.CheckScriptFailure(lines, 'E399:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3479 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3481 def Test_vim9_comment_gui()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3482 CheckCanRunGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3484 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3485 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3486 'gui#comment'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3487 ], 'E1144:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3488 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3489 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3490 'gui -f#comment'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3491 ], 'E194:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3492 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3493
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3494 def Test_vim9_comment_not_compiled()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3495 au TabEnter *.vim g:entered = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3496 au TabEnter *.x g:entered = 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3498 edit test.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3499 doautocmd TabEnter #comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3500 assert_equal(1, g:entered)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3501
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3502 doautocmd TabEnter f.x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3503 assert_equal(2, g:entered)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3504
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3505 g:entered = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3506 doautocmd TabEnter f.x #comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3507 assert_equal(2, g:entered)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3508
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3509 assert_fails('doautocmd Syntax#comment', 'E216:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3511 au! TabEnter
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3512 unlet g:entered
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3514 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3515 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3516 'g:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3517 'b:var = 456',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3518 'w:var = 777',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3519 't:var = 888',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3520 'unlet g:var w:var # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3521 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3522
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3523 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3524 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3525 'let var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3526 ], 'E1126: Cannot use :let in Vim9 script')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3527
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3528 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3529 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3530 'var g:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3531 ], 'E1016: Cannot declare a global variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3533 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3534 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3535 'var b:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3536 ], 'E1016: Cannot declare a buffer variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3537
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3538 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3539 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3540 'var w:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3541 ], 'E1016: Cannot declare a window variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3542
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3543 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3544 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3545 'var t:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3546 ], 'E1016: Cannot declare a tab variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3547
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3548 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3549 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3550 'var v:version = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3551 ], 'E1016: Cannot declare a v: variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3553 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3554 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3555 'var $VARIABLE = "text"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3556 ], 'E1016: Cannot declare an environment variable:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3557
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3558 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3559 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3560 'g:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3561 'unlet g:var# comment1',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3562 ], 'E108:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3563
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3564 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3565 'let g:var = 123',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3566 'unlet g:var # something',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3567 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3568
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3569 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3570 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3571 'if 1 # comment2',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3572 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3573 'elseif 2 #comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3574 ' echo "no"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3575 'endif',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3576 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3577
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3578 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3579 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3580 'if 1# comment3',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3581 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3582 'endif',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3583 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3584
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3585 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3586 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3587 'if 0 # comment4',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3588 ' echo "yes"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3589 'elseif 2#comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3590 ' echo "no"',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3591 'endif',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3592 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3593
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3594 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3595 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3596 'var v = 1 # comment5',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3597 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3598
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3599 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3600 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3601 'var v = 1# comment6',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3602 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3604 v9.CheckScriptSuccess([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3605 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3606 'new',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3607 'setline(1, ["# define pat", "last"])',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3608 ':$',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3609 'dsearch /pat/ #comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3610 'bwipe!',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3611 ])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3612
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3613 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3614 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3615 'new',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3616 'setline(1, ["# define pat", "last"])',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3617 ':$',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3618 'dsearch /pat/#comment',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3619 'bwipe!',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3620 ], 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3622 v9.CheckScriptFailure([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3623 'vim9script',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3624 'func! SomeFunc()',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3625 ], 'E477:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3626 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3627
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3628 def Test_finish()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3629 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3630 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3631 g:res = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3632 if v:false | finish | endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3633 g:res = 'two'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3634 finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3635 g:res = 'three'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3636 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3637 writefile(lines, 'Xfinished', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3638 source Xfinished
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3639 assert_equal('two', g:res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3641 unlet g:res
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3642 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3643
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3644 def Test_forward_declaration()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3645 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3646 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3647 def GetValue(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3648 return theVal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3649 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3650 var theVal = 'something'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3651 g:initVal = GetValue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3652 theVal = 'else'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3653 g:laterVal = GetValue()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3654 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3655 writefile(lines, 'Xforward', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3656 source Xforward
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3657 assert_equal('something', g:initVal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3658 assert_equal('else', g:laterVal)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3659
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3660 unlet g:initVal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3661 unlet g:laterVal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3662 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3664 def Test_declare_script_var_in_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3665 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3666 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3667 func Declare()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3668 let s:local = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3669 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3670 Declare()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3671 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3672 v9.CheckScriptFailure(lines, 'E1269:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3673 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3674
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3675 def Test_lock_script_var()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3676 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3677 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3678 var local = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3679 assert_equal(123, local)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3680
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3681 var error: string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3682 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3683 local = 'asdf'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3684 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3685 error = v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3686 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3687 assert_match('E1012: Type mismatch; expected number but got string', error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3689 lockvar local
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3690 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3691 local = 999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3692 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3693 error = v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3694 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3695 assert_match('E741: Value is locked: local', error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3696 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3697 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3698 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3700
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3701 func Test_vim9script_not_global()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3702 " check that items defined in Vim9 script are script-local, not global
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3703 let vim9lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3704 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3705 var name = 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3706 func TheFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3707 echo 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3708 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3709 def DefFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3710 echo 'local'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3711 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3712 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3713 call writefile(vim9lines, 'Xvim9script.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3714 source Xvim9script.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3715 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3716 echo g:var
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3717 assert_report('did not fail')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3718 catch /E121:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3719 " caught
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3720 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3721 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3722 call TheFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3723 assert_report('did not fail')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3724 catch /E117:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3725 " caught
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3726 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3727 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3728 call DefFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3729 assert_report('did not fail')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3730 catch /E117:/
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3731 " caught
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3732 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3733 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3734
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3735 def Test_vim9_copen()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3736 # this was giving an error for setting w:quickfix_title
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3737 copen
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3738 quit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3739 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3741 def Test_script_var_in_autocmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3742 # using a script variable from an autocommand, defined in a :def function in a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3743 # legacy Vim script, cannot check the variable type.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3744 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3745 let s:counter = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3746 def s:Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3747 au! CursorHold
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3748 au CursorHold * s:counter += 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3749 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3750 call s:Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3751 doau CursorHold
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3752 call assert_equal(2, s:counter)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3753 au! CursorHold
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3754 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3755 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3756 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3757
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3758 def Test_error_in_autoload_script()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3759 var save_rtp = &rtp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3760 var dir = getcwd() .. '/Xruntime'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3761 &rtp = dir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3762 mkdir(dir .. '/autoload', 'pR')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3763
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3764 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3765 vim9script noclear
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3766 export def Autoloaded()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3767 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3768 def Broken()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3769 var x: any = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3770 eval x != 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3771 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3772 Broken()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3773 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3774 writefile(lines, dir .. '/autoload/script.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3775
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3776 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3777 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3778 def CallAutoloaded()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3779 script#Autoloaded()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3780 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3781
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3782 function Legacy()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3783 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3784 call s:CallAutoloaded()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3785 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3786 call assert_match('E1030: Using a String as a Number', v:exception)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3787 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3788 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3789
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3790 Legacy()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3791 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3792 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3793
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3794 &rtp = save_rtp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3795 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3796
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3797 def Test_error_in_autoload_script_foldexpr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3798 var save_rtp = &rtp
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3799 mkdir('Xvim/autoload', 'pR')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3800 &runtimepath = 'Xvim'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3801
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3802 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3803 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3804 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3805 echomsg 'no error'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3806 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3807 lines->writefile('Xvim/autoload/script.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3808
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3809 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3810 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3811 import autoload 'script.vim'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3812 &foldmethod = 'expr'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3813 &foldexpr = 'script.Func()'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3814 redraw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3815 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3816 v9.CheckScriptFailure(lines, 'E684: List index out of range: 0')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3817 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3818
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3819 def Test_invalid_sid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3820 assert_fails('func <SNR>1234_func', 'E123:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3821
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3822 if g:RunVim([], ['wq! Xdidit'], '+"func <SNR>1_func"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3823 assert_equal([], readfile('Xdidit'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3824 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3825 delete('Xdidit')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3826 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3827
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3828 def Test_restoring_cpo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3829 writefile(['vim9script', 'set nocp'], 'Xsourced', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3830 writefile(['call writefile(["done"], "Xdone")', 'quit!'], 'Xclose', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3831 if g:RunVim([], [], '-u NONE +"set cpo+=a" -S Xsourced -S Xclose')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3832 assert_equal(['done'], readfile('Xdone'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3833 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3834 delete('Xdone')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3835
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3836 writefile(['vim9script', 'g:cpoval = &cpo'], 'XanotherScript', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3837 set cpo=aABceFsMny>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3838 edit XanotherScript
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3839 so %
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3840 assert_equal('aABceFsMny>', &cpo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3841 assert_equal('aABceFs', g:cpoval)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3842 :1del
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3843 setline(1, 'let g:cpoval = &cpo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3844 w
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3845 so %
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3846 assert_equal('aABceFsMny>', &cpo)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3847 assert_equal('aABceFsMny>', g:cpoval)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3848
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3849 set cpo&vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3850 unlet g:cpoval
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3851
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3852 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3853 # 'cpo' is not restored in main vimrc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3854 var save_HOME = $HOME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3855 $HOME = getcwd() .. '/Xhome'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3856 mkdir('Xhome', 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3857 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3858 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3859 writefile(['before: ' .. &cpo], 'Xrporesult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3860 set cpo+=M
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3861 writefile(['after: ' .. &cpo], 'Xrporesult', 'a')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3862 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3863 writefile(lines, 'Xhome/.vimrc')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3864
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3865 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3866 call writefile(['later: ' .. &cpo], 'Xrporesult', 'a')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3867 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3868 writefile(lines, 'Xlegacy', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3870 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3871 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3872 call writefile(['vim9: ' .. &cpo], 'Xrporesult', 'a')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3873 qa
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3874 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3875 writefile(lines, 'Xvim9', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3876
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3877 var cmd = g:GetVimCommand() .. " -S Xlegacy -S Xvim9"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3878 cmd = substitute(cmd, '-u NONE', '', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3879 exe "silent !" .. cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3881 assert_equal([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3882 'before: aABceFs',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3883 'after: aABceFsM',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3884 'later: aABceFsM',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3885 'vim9: aABceFs'], readfile('Xrporesult'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3886
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3887 $HOME = save_HOME
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3888 delete('Xrporesult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3889 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3890 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3892 " Use :function so we can use Check commands
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3893 func Test_no_redraw_when_restoring_cpo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3894 CheckScreendump
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3895 CheckFeature timers
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3896 call Run_test_no_redraw_when_restoring_cpo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3897 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3898
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3899 def Run_test_no_redraw_when_restoring_cpo()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3900 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3901 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3902 export def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3903 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3904 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3905 mkdir('Xnordir/autoload', 'pR')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3906 writefile(lines, 'Xnordir/autoload/script.vim')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3907
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3908 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3909 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3910 set cpo+=M
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3911 exe 'set rtp^=' .. getcwd() .. '/Xnordir'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3912 au CmdlineEnter : ++once timer_start(0, (_) => script#Func())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3913 setline(1, 'some text')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3914 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3915 writefile(lines, 'XTest_redraw_cpo', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3916 var buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3917 term_sendkeys(buf, "V:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3918 g:VerifyScreenDump(buf, 'Test_vim9_no_redraw', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3919
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3920 # clean up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3921 term_sendkeys(buf, "\<Esc>u")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3922 g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3923 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3924
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3925 func Test_reject_declaration()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3926 CheckScreendump
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3927 call Run_test_reject_declaration()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3928 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3930 def Run_test_reject_declaration()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3931 var buf = g:RunVimInTerminal('', {'rows': 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3932 term_sendkeys(buf, ":vim9cmd var x: number\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3933 g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration_1', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3934 term_sendkeys(buf, ":\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3935 term_sendkeys(buf, ":vim9cmd g:foo = 123 | echo g:foo\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3936 g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration_2', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3937
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3938 # clean up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3939 g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3940 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3942 def Test_minimal_command_name_length()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3943 var names = [
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3944 'cons',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3945 'brea',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3946 'cat',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3947 'catc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3948 'con',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3949 'cont',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3950 'conti',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3951 'contin',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3952 'continu',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3953 'el',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3954 'els',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3955 'elsei',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3956 'endfo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3957 'en',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3958 'end',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3959 'endi',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3960 'endw',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3961 'endt',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3962 'endtr',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3963 'exp',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3964 'expo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3965 'expor',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3966 'fina',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3967 'finall',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3968 'fini',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3969 'finis',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3970 'imp',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3971 'impo',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3972 'impor',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3973 'retu',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3974 'retur',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3975 'th',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3976 'thr',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3977 'thro',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3978 'wh',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3979 'whi',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3980 'whil',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3981 ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3982 for name in names
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3983 v9.CheckDefAndScriptFailure([name .. ' '], 'E1065:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3984 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3986 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3987 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3988 def SomeFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3989 endd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3990 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3991 v9.CheckScriptFailure(lines, 'E1065:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3992 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3993 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3994 def SomeFunc()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3995 endde
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3996 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3997 v9.CheckScriptFailure(lines, 'E1065:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3998 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
3999
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4000 def Test_unset_any_variable()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4001 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4002 var name: any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4003 assert_equal(0, name)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4004 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4005 v9.CheckDefAndScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4006 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4007
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4008 func Test_define_func_at_command_line()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4009 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4010
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4011 " call indirectly to avoid compilation error for missing functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4012 call Run_Test_define_func_at_command_line()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4013 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4014
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4015 def Run_Test_define_func_at_command_line()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4016 # run in a separate Vim instance to avoid the script context
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4017 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4018 func CheckAndQuit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4019 call assert_fails('call Afunc()', 'E117: Unknown function: Bfunc')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4020 call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4021 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4022 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4023 writefile([''], 'Xdidcmd', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4024 writefile(lines, 'XcallFunc', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4025 var buf = g:RunVimInTerminal('-S XcallFunc', {rows: 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4026 # define Afunc() on the command line
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4027 term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4028 term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4029 g:WaitForAssert(() => assert_equal(['errors: []'], readfile('Xdidcmd')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4030
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4031 call g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4032 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4034 def Test_script_var_scope()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4035 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4036 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4037 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4038 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4039 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4040 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4041 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4042 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4043 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4044 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4045 v9.CheckScriptFailure(lines, 'E121:', 7)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4047 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4048 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4049 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4050 if false
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4051 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4052 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4053 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4054 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4055 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4056 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4057 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4058 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4059 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4060 v9.CheckScriptFailure(lines, 'E121:', 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4061
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4062 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4063 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4064 while true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4065 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4066 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4067 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4068 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4069 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4070 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4071 v9.CheckScriptFailure(lines, 'E121:', 7)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4073 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4074 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4075 for i in range(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4076 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4077 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4078 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4079 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4080 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4081 v9.CheckScriptFailure(lines, 'E121:', 6)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4083 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4084 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4085 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4086 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4087 assert_equal('one', one)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4088 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4089 assert_false(exists('one'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4090 assert_false(exists('s:one'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4091 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4092 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4093
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4094 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4095 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4096 {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4097 var one = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4098 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4099 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4100 echo one
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4101 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4102 v9.CheckScriptFailure(lines, 'E121:', 6)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4103 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4105 def Test_catch_exception_in_callback()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4106 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4107 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4108 def Callback(...l: list<any>)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4109 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4110 var x: string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4111 var y: string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4112 # this error should be caught with CHECKLEN
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4113 var sl = ['']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4114 [x, y] = sl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4115 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4116 g:caught = 'yes'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4117 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4118 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4119 popup_menu('popup', {callback: Callback})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4120 feedkeys("\r", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4121 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4122 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4124 unlet g:caught
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4125 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4127 def Test_no_unknown_error_after_error()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4128 if !has('unix') || !has('job')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4129 throw 'Skipped: not unix of missing +job feature'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4130 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4131 # FIXME: this check should not be needed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4132 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4133 throw 'Skipped: does not work on MS-Windows'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4134 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4135 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4136 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4137 var source: list<number>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4138 def Out_cb(...l: list<any>)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4139 eval [][0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4140 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4141 def Exit_cb(...l: list<any>)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4142 sleep 1m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4143 g:did_call_exit_cb = true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4144 source += l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4145 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4146 var myjob = job_start('echo burp', {out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4147 while job_status(myjob) == 'run'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4148 sleep 10m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4149 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4150 # wait for Exit_cb() to be called
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4151 for x in range(100)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4152 if exists('g:did_call_exit_cb')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4153 unlet g:did_call_exit_cb
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4154 break
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4155 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4156 sleep 10m
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4157 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4158 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4159 writefile(lines, 'Xdef', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4160 # Either the exit or out callback is called first, accept them in any order
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4161 assert_fails('so Xdef', ['E684:\|E1012:', 'E1012:\|E684:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4162 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4164 def InvokeNormal()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4165 exe "norm! :m+1\r"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4166 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4167
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4168 def Test_invoke_normal_in_visual_mode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4169 xnoremap <F3> <Cmd>call <SID>InvokeNormal()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4170 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4171 setline(1, ['aaa', 'bbb'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4172 feedkeys("V\<F3>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4173 assert_equal(['bbb', 'aaa'], getline(1, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4174 xunmap <F3>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4175 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4177 def Test_white_space_after_command()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4178 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4179 exit_cb: Func})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4180 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4181 v9.CheckDefAndScriptFailure(lines, 'E1144:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4182
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4183 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4184 e#
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4185 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4186 v9.CheckDefAndScriptFailure(lines, 'E1144:', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4187 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4189 def Test_script_var_gone_when_sourced_twice()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4190 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4191 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4192 if exists('g:guard')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4193 finish
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4194 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4195 g:guard = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4196 var name = 'thename'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4197 def g:GetName(): string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4198 return name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4199 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4200 def g:SetName(arg: string)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4201 name = arg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4202 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4203 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4204 writefile(lines, 'XscriptTwice.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4205 so XscriptTwice.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4206 assert_equal('thename', g:GetName())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4207 g:SetName('newname')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4208 assert_equal('newname', g:GetName())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4209 so XscriptTwice.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4210 assert_fails('call g:GetName()', 'E1149:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4211 assert_fails('call g:SetName("x")', 'E1149:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4212
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4213 delfunc g:GetName
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4214 delfunc g:SetName
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4215 unlet g:guard
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4216 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4218 def Test_unsupported_commands()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4219 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4220 ka
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4221 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4222 v9.CheckDefAndScriptFailure(lines, ['E476:', 'E492:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4224 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4225 :1ka
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4226 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4227 v9.CheckDefAndScriptFailure(lines, ['E476:', 'E492:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4228
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4229 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4230 :k a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4231 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4232 v9.CheckDefAndScriptFailure(lines, 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4234 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4235 :1k a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4236 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4237 v9.CheckDefAndScriptFailure(lines, 'E481:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4239 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4240 t
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4241 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4242 v9.CheckDefAndScriptFailure(lines, 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4244 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4245 x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4246 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4247 v9.CheckDefAndScriptFailure(lines, 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4248
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4249 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4250 xit
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4251 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4252 v9.CheckDefAndScriptFailure(lines, 'E1100:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4253
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4254 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4255 Print
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4256 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4257 v9.CheckDefAndScriptFailure(lines, ['E476: Invalid command: Print', 'E492: Not an editor command: Print'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4258
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4259 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4260 mode 4
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4261 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4262 v9.CheckDefAndScriptFailure(lines, ['E476: Invalid command: mode 4', 'E492: Not an editor command: mode 4'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4263 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4265 def Test_mapping_line_number()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4266 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4267 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4268 def g:FuncA()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4269 # Some comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4270 FuncB(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4271 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4272 # Some comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4273 def FuncB(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4274 # Some comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4275 n: number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4276 )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4277 exe 'nno '
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4278 # Some comment
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4279 .. '<F3> a'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4280 .. 'b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4281 .. 'c'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4282 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4283 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4284 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4285 var res = execute('verbose nmap <F3>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4286 assert_match('No mapping found', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4287
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4288 g:FuncA()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4289 res = execute('verbose nmap <F3>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4290 assert_match(' <F3> .* abc.*Last set from .*XScriptSuccess\d\+ line 11', res)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4291
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4292 nunmap <F3>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4293 delfunc g:FuncA
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4294 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4296 def Test_option_set()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4297 # legacy script allows for white space
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4298 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4299 set foldlevel =11
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4300 call assert_equal(11, &foldlevel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4301 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4302 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4303
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4304 set foldlevel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4305 set foldlevel=12
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4306 assert_equal(12, &foldlevel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4307 set foldlevel+=2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4308 assert_equal(14, &foldlevel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4309 set foldlevel-=3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4310 assert_equal(11, &foldlevel)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4311
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4312 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4313 set foldlevel =1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4314 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4315 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: =1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4316
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4317 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4318 set foldlevel +=1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4319 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4320 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: +=1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4321
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4322 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4323 set foldlevel ^=1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4324 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4325 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: ^=1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4326
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4327 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4328 set foldlevel -=1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4329 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4330 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: -=1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4331
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4332 set foldlevel&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4333 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4334
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4335 def Test_option_modifier()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4336 # legacy script allows for white space
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4337 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4338 set hlsearch & hlsearch !
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4339 call assert_equal(1, &hlsearch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4340 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4341 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4342
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4343 set hlsearch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4344 set hlsearch!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4345 assert_equal(false, &hlsearch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4347 set hlsearch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4348 set hlsearch&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4349 assert_equal(false, &hlsearch)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4351 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4352 set hlsearch &
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4353 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4354 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: &')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4356 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4357 set hlsearch !
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4358 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4359 v9.CheckDefExecAndScriptFailure(lines, 'E1205: No white space allowed between option and: !')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4360
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4361 set hlsearch&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4362 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4364 " This must be called last, it may cause following :def functions to fail
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4365 def Test_xxx_echoerr_line_number()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4366 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4367 echoerr 'some'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4368 .. ' error'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4369 .. ' continued'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4370 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4371 v9.CheckDefExecAndScriptFailure(lines, 'some error continued', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4372 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4373
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4374 func Test_debug_with_lambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4375 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4377 " call indirectly to avoid compilation error for missing functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4378 call Run_Test_debug_with_lambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4379 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4381 def Run_Test_debug_with_lambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4382 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4383 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4384 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4385 var n = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4386 echo [0]->filter((_, v) => v == n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4387 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4388 breakadd func Func
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4389 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4390 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4391 writefile(lines, 'XdebugFunc', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4392 var buf = g:RunVimInTerminal('-S XdebugFunc', {rows: 6, wait_for_ruler: 0})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4393 g:WaitForAssert(() => assert_match('^>', term_getline(buf, 6)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4394
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4395 term_sendkeys(buf, "cont\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4396 g:WaitForAssert(() => assert_match('\[0\]', term_getline(buf, 5)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4397
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4398 g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4399 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4400
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4401 func Test_debug_running_out_of_lines()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4402 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4404 " call indirectly to avoid compilation error for missing functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4405 call Run_Test_debug_running_out_of_lines()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4406 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4407
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4408 def Run_Test_debug_running_out_of_lines()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4409 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4410 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4411 def Crash()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4412 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4413 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4414 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4415 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4416 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4417 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4418 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4419 if true
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4420 #
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4421 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4422 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4423 breakadd func Crash
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4424 Crash()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4425 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4426 writefile(lines, 'XdebugFunc', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4427 var buf = g:RunVimInTerminal('-S XdebugFunc', {rows: 6, wait_for_ruler: 0})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4428 g:WaitForAssert(() => assert_match('^>', term_getline(buf, 6)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4429
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4430 term_sendkeys(buf, "next\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4431 g:TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4432 g:WaitForAssert(() => assert_match('^>', term_getline(buf, 6)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4433
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4434 term_sendkeys(buf, "cont\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4435 g:TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4436
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4437 g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4438 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4439
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4440 def Test_ambiguous_command_error()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4441 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4442 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4443 command CmdA echomsg 'CmdA'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4444 command CmdB echomsg 'CmdB'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4445 Cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4446 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4447 v9.CheckScriptFailure(lines, 'E464: Ambiguous use of user-defined command: Cmd', 4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4448
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4449 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4450 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4451 def Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4452 Cmd
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4453 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4454 Func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4455 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4456 v9.CheckScriptFailure(lines, 'E464: Ambiguous use of user-defined command: Cmd', 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4457
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4458 lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4459 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4460 nnoremap <F3> <ScriptCmd>Cmd<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4461 feedkeys("\<F3>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4462 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4463 v9.CheckScriptFailure(lines, 'E464: Ambiguous use of user-defined command: Cmd', 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4464
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4465 delcommand CmdA
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4466 delcommand CmdB
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4467 nunmap <F3>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4468 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4469
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4470 " Execute this near the end, profiling doesn't stop until Vim exits.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4471 " This only tests that it works, not the profiling output.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4472 def Test_profile_with_lambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4473 CheckFeature profile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4474
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4475 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4476 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4477
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4478 def ProfiledWithLambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4479 var n = 3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4480 echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4481 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4482
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4483 def ProfiledNested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4484 var x = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4485 def Nested(): any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4486 return x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4487 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4488 Nested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4489 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4490
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4491 def g:ProfiledNestedProfiled()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4492 var x = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4493 def Nested(): any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4494 return x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4495 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4496 Nested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4497 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4499 def Profile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4500 ProfiledWithLambda()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4501 ProfiledNested()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4503 # Also profile the nested function. Use a different function, although
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4504 # the contents is the same, to make sure it was not already compiled.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4505 profile func *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4506 g:ProfiledNestedProfiled()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4507
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4508 profdel func *
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4509 profile pause
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4510 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4511
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4512 var result = 'done'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4513 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4514 # mark functions for profiling now to avoid E1271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4515 profile start Xprofile.log
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4516 profile func ProfiledWithLambda
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4517 profile func ProfiledNested
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4518
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4519 Profile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4520 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4521 result = 'failed: ' .. v:exception
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4522 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4523 writefile([result], 'Xdidprofile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4524 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4525 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4526 writefile(lines, 'Xprofile.vim', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4527 call system(g:GetVimCommand()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4528 .. ' --clean'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4529 .. ' -c "so Xprofile.vim"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4530 .. ' -c "qall!"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4531 call assert_equal(0, v:shell_error)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4533 assert_equal(['done'], readfile('Xdidprofile'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4534 assert_true(filereadable('Xprofile.log'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4535 delete('Xdidprofile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4536 delete('Xprofile.log')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4537 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4539 func Test_misplaced_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4540 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4541 call Run_Test_misplaced_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4542 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4543
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4544 def Run_Test_misplaced_type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4545 writefile(['let g:somevar = "asdf"'], 'XTest_misplaced_type', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4546 var buf = g:RunVimInTerminal('-S XTest_misplaced_type', {'rows': 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4547 term_sendkeys(buf, ":vim9cmd echo islocked('somevar: string')\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4548 g:VerifyScreenDump(buf, 'Test_misplaced_type', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4550 g:StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4551 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4552
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4553 " Ensure echo doesn't crash when stringifying empty variables.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4554 def Test_echo_uninit_variables()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4555 var res: string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4556
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4557 var var_bool: bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4558 var var_num: number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4559 var var_float: float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4560 var Var_func: func
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4561 var var_string: string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4562 var var_blob: blob
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4563 var var_list: list<any>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4564 var var_dict: dict<any>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4565
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4566 redir => res
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4567 echo var_bool
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4568 echo var_num
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4569 echo var_float
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4570 echo Var_func
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4571 echo var_string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4572 echo var_blob
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4573 echo var_list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4574 echo var_dict
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4575 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4577 assert_equal(['false', '0', '0.0', 'function()', '', '0z', '[]', '{}'], res->split('\n'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4578
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4579 if has('job')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4580 var var_job: job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4581 var var_channel: channel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4582
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4583 redir => res
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4584 echo var_job
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4585 echo var_channel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4586 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4587
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4588 assert_equal(['no process', 'channel fail'], res->split('\n'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4589 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4590 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4592 def Test_free_type_before_use()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4593 # this rather complicated script was freeing a type before using it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4594 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4595 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4596
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4597 def Scan(rel: list<dict<any>>): func(func(dict<any>))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4598 return (Emit: func(dict<any>)) => {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4599 for t in rel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4600 Emit(t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4601 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4602 }
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4603 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4604
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4605 def Build(Cont: func(func(dict<any>))): list<dict<any>>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4606 var rel: list<dict<any>> = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4607 Cont((t) => {
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4608 add(rel, t)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4609 })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4610 return rel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4611 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4612
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4613 var R = [{A: 0}]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4614 var result = Scan(R)->Build()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4615 result = Scan(R)->Build()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4617 assert_equal(R, result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4618 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4619 v9.CheckScriptSuccess(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4620 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4622 " Keep this last, it messes up highlighting.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4623 def Test_substitute_cmd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4624 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4625 setline(1, 'something')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4626 :substitute(some(other(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4627 assert_equal('otherthing', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4628 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4629
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4630 # also when the context is Vim9 script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4631 var lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4632 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4633 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4634 setline(1, 'something')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4635 :substitute(some(other(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4636 assert_equal('otherthing', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4637 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4638 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4639 writefile(lines, 'Xvim9lines', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4640 source Xvim9lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4641 enddef
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32454
diff changeset
4643 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker