comparison src/testdir/test_vim9_script.vim @ 19894:ea4f8e789627 v8.2.0503

patch 8.2.0503: Vim9: some code is not tested Commit: https://github.com/vim/vim/commit/585fea7b98b79f2c6d92fa8a2340e461aff805c8 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 2 22:33:21 2020 +0200 patch 8.2.0503: Vim9: some code is not tested Problem: Vim9: some code is not tested. Solution: Add tests. Fix uncovered problems.
author Bram Moolenaar <Bram@vim.org>
date Thu, 02 Apr 2020 22:45:04 +0200
parents 5feb426d2ea1
children bd4f91762d0f
comparison
equal deleted inserted replaced
19893:4966949f841a 19894:ea4f8e789627
110 &ts %= 4 110 &ts %= 4
111 assert_equal(2, &ts) 111 assert_equal(2, &ts)
112 call CheckDefFailure(['&notex += 3'], 'E113:') 112 call CheckDefFailure(['&notex += 3'], 'E113:')
113 call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:') 113 call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
114 call CheckDefFailure(['&path += 3'], 'E1013:') 114 call CheckDefFailure(['&path += 3'], 'E1013:')
115 " test freeing ISN_STOREOPT
116 call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
115 &ts = 8 117 &ts = 8
116 118
117 g:inc_counter += 1 119 g:inc_counter += 1
118 assert_equal(2, g:inc_counter) 120 assert_equal(2, g:inc_counter)
119 121
169 assert_equal(test_null_job(), thejob) 171 assert_equal(test_null_job(), thejob)
170 172
171 let thechannel: channel 173 let thechannel: channel
172 assert_equal(test_null_channel(), thechannel) 174 assert_equal(test_null_channel(), thechannel)
173 endif 175 endif
176
177 let nr = 1234 | nr = 5678
178 assert_equal(5678, nr)
174 enddef 179 enddef
175 180
176 func Test_assignment_failure() 181 func Test_assignment_failure()
177 call CheckDefFailure(['let var=234'], 'E1004:') 182 call CheckDefFailure(['let var=234'], 'E1004:')
178 call CheckDefFailure(['let var =234'], 'E1004:') 183 call CheckDefFailure(['let var =234'], 'E1004:')
251 assert_equal(1, outer) 256 assert_equal(1, outer)
252 enddef 257 enddef
253 258
254 func Test_block_failure() 259 func Test_block_failure()
255 call CheckDefFailure(['{', 'let inner = 1', '}', 'echo inner'], 'E1001:') 260 call CheckDefFailure(['{', 'let inner = 1', '}', 'echo inner'], 'E1001:')
256 endfunc 261 call CheckDefFailure(['}'], 'E1025:')
262 call CheckDefFailure(['{', 'echo 1'], 'E1026:')
263 endfunc
264
265 def Test_cmd_modifier()
266 tab echo '0'
267 call CheckDefFailure(['5tab echo 3'], 'E16:')
268 enddef
269
257 270
258 def ReturnString(): string 271 def ReturnString(): string
259 return 'string' 272 return 'string'
260 enddef 273 enddef
261 274
324 337
325 def Test_call_default_args() 338 def Test_call_default_args()
326 assert_equal('string', MyDefaultArgs()) 339 assert_equal('string', MyDefaultArgs())
327 assert_equal('one', MyDefaultArgs('one')) 340 assert_equal('one', MyDefaultArgs('one'))
328 assert_fails('call MyDefaultArgs("one", "two")', 'E118:') 341 assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
342
343 call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:')
329 enddef 344 enddef
330 345
331 func Test_call_default_args_from_func() 346 func Test_call_default_args_from_func()
332 call assert_equal('string', MyDefaultArgs()) 347 call assert_equal('string', MyDefaultArgs())
333 call assert_equal('one', MyDefaultArgs('one')) 348 call assert_equal('one', MyDefaultArgs('one'))
478 493
479 def Test_try_catch_fails() 494 def Test_try_catch_fails()
480 call CheckDefFailure(['catch'], 'E603:') 495 call CheckDefFailure(['catch'], 'E603:')
481 call CheckDefFailure(['try', 'echo 0', 'catch','catch'], 'E1033:') 496 call CheckDefFailure(['try', 'echo 0', 'catch','catch'], 'E1033:')
482 call CheckDefFailure(['try', 'echo 0', 'catch /pat'], 'E1067:') 497 call CheckDefFailure(['try', 'echo 0', 'catch /pat'], 'E1067:')
498 call CheckDefFailure(['finally'], 'E606:')
499 call CheckDefFailure(['try', 'echo 0', 'finally', 'echo 1', 'finally'], 'E607:')
500 call CheckDefFailure(['endtry'], 'E602:')
501 call CheckDefFailure(['while 1', 'endtry'], 'E170:')
502 call CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:')
503 call CheckDefFailure(['if 2', 'endtry'], 'E171:')
504 call CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
505
506 call CheckDefFailure(['throw'], 'E471:')
507 call CheckDefFailure(['throw xxx'], 'E1001:')
483 enddef 508 enddef
484 509
485 let s:export_script_lines =<< trim END 510 let s:export_script_lines =<< trim END
486 vim9script 511 vim9script
487 let name: string = 'bob' 512 let name: string = 'bob'
937 def Test_if_elseif_else_fails() 962 def Test_if_elseif_else_fails()
938 call CheckDefFailure(['elseif true'], 'E582:') 963 call CheckDefFailure(['elseif true'], 'E582:')
939 call CheckDefFailure(['else'], 'E581:') 964 call CheckDefFailure(['else'], 'E581:')
940 call CheckDefFailure(['endif'], 'E580:') 965 call CheckDefFailure(['endif'], 'E580:')
941 call CheckDefFailure(['if true', 'elseif xxx'], 'E1001:') 966 call CheckDefFailure(['if true', 'elseif xxx'], 'E1001:')
967 call CheckDefFailure(['if true', 'echo 1'], 'E171:')
942 enddef 968 enddef
943 969
944 let g:bool_true = v:true 970 let g:bool_true = v:true
945 let g:bool_false = v:false 971 let g:bool_false = v:false
946 972
948 let res = false 974 let res = false
949 if true ? true : false 975 if true ? true : false
950 res = true 976 res = true
951 endif 977 endif
952 assert_equal(true, res) 978 assert_equal(true, res)
979
980 g:glob = 2
981 if false
982 execute('let g:glob = 3')
983 endif
984 assert_equal(2, g:glob)
985 if true
986 execute('let g:glob = 3')
987 endif
988 assert_equal(3, g:glob)
953 989
954 res = false 990 res = false
955 if g:bool_true ? true : false 991 if g:bool_true ? true : false
956 res = true 992 res = true
957 endif 993 endif
1090 let cmd_first = 'call ' 1126 let cmd_first = 'call '
1091 let cmd_last = 'setline(1, "execute-var-var")' 1127 let cmd_last = 'setline(1, "execute-var-var")'
1092 execute cmd_first .. cmd_last 1128 execute cmd_first .. cmd_last
1093 assert_equal('execute-var-var', getline(1)) 1129 assert_equal('execute-var-var', getline(1))
1094 bwipe! 1130 bwipe!
1131
1132 call CheckDefFailure(['execute xxx'], 'E1001:')
1095 enddef 1133 enddef
1096 1134
1097 def Test_echo_cmd() 1135 def Test_echo_cmd()
1098 echo 'something' 1136 echo 'some'
1137 echon 'thing'
1099 assert_match('^something$', Screenline(&lines)) 1138 assert_match('^something$', Screenline(&lines))
1100 1139
1101 let str1 = 'some' 1140 let str1 = 'some'
1102 let str2 = 'more' 1141 let str2 = 'more'
1103 echo str1 str2 1142 echo str1 str2
1139 call CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:') 1178 call CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:')
1140 call CheckScriptFailure(['def Func(arg)', 'for arg in range(5)', 'enddef'], 'E1006:') 1179 call CheckScriptFailure(['def Func(arg)', 'for arg in range(5)', 'enddef'], 'E1006:')
1141 call CheckDefFailure(['for i in "text"'], 'E1024:') 1180 call CheckDefFailure(['for i in "text"'], 'E1024:')
1142 call CheckDefFailure(['for i in xxx'], 'E1001:') 1181 call CheckDefFailure(['for i in xxx'], 'E1001:')
1143 call CheckDefFailure(['endfor'], 'E588:') 1182 call CheckDefFailure(['endfor'], 'E588:')
1183 call CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
1144 enddef 1184 enddef
1145 1185
1146 def Test_while_loop() 1186 def Test_while_loop()
1147 let result = '' 1187 let result = ''
1148 let cnt = 0 1188 let cnt = 0
1164 call CheckDefFailure(['endwhile'], 'E588:') 1204 call CheckDefFailure(['endwhile'], 'E588:')
1165 call CheckDefFailure(['continue'], 'E586:') 1205 call CheckDefFailure(['continue'], 'E586:')
1166 call CheckDefFailure(['if true', 'continue'], 'E586:') 1206 call CheckDefFailure(['if true', 'continue'], 'E586:')
1167 call CheckDefFailure(['break'], 'E587:') 1207 call CheckDefFailure(['break'], 'E587:')
1168 call CheckDefFailure(['if true', 'break'], 'E587:') 1208 call CheckDefFailure(['if true', 'break'], 'E587:')
1209 call CheckDefFailure(['while 1', 'echo 3'], 'E170:')
1169 enddef 1210 enddef
1170 1211
1171 def Test_interrupt_loop() 1212 def Test_interrupt_loop()
1172 let caught = false 1213 let caught = false
1173 let x = 0 1214 let x = 0
1183 assert_equal(100, x) 1224 assert_equal(100, x)
1184 endtry 1225 endtry
1185 assert_true(caught, 'should have caught an exception') 1226 assert_true(caught, 'should have caught an exception')
1186 enddef 1227 enddef
1187 1228
1188 def Test_substitute_cmd()
1189 new
1190 setline(1, 'something')
1191 :substitute(some(other(
1192 assert_equal('otherthing', getline(1))
1193 bwipe!
1194
1195 " also when the context is Vim9 script
1196 let lines =<< trim END
1197 vim9script
1198 new
1199 setline(1, 'something')
1200 :substitute(some(other(
1201 assert_equal('otherthing', getline(1))
1202 bwipe!
1203 END
1204 writefile(lines, 'Xvim9lines')
1205 source Xvim9lines
1206
1207 delete('Xvim9lines')
1208 enddef
1209
1210 def Test_redef_failure() 1229 def Test_redef_failure()
1211 call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef') 1230 call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef')
1212 so Xdef 1231 so Xdef
1213 call writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef') 1232 call writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef')
1214 so Xdef 1233 so Xdef
1283 call writefile(l, 'Xinvalidarg') 1302 call writefile(l, 'Xinvalidarg')
1284 call assert_fails('so Xinvalidarg', 'E119:') 1303 call assert_fails('so Xinvalidarg', 'E119:')
1285 call delete('Xinvalidarg') 1304 call delete('Xinvalidarg')
1286 endfunc 1305 endfunc
1287 1306
1307 " Keep this last, it messes up highlighting.
1308 def Test_substitute_cmd()
1309 new
1310 setline(1, 'something')
1311 :substitute(some(other(
1312 assert_equal('otherthing', getline(1))
1313 bwipe!
1314
1315 " also when the context is Vim9 script
1316 let lines =<< trim END
1317 vim9script
1318 new
1319 setline(1, 'something')
1320 :substitute(some(other(
1321 assert_equal('otherthing', getline(1))
1322 bwipe!
1323 END
1324 writefile(lines, 'Xvim9lines')
1325 source Xvim9lines
1326
1327 delete('Xvim9lines')
1328 enddef
1329
1288 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 1330 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker