Skip to content

Commit 585fea7

Browse files
committed
patch 8.2.0503: Vim9: some code is not tested
Problem: Vim9: some code is not tested. Solution: Add tests. Fix uncovered problems.
1 parent e8c4abb commit 585fea7

3 files changed

Lines changed: 70 additions & 31 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def Test_assignment()
112112
call CheckDefFailure(['&notex += 3'], 'E113:')
113113
call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
114114
call CheckDefFailure(['&path += 3'], 'E1013:')
115+
" test freeing ISN_STOREOPT
116+
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
115117
&ts = 8
116118

117119
g:inc_counter += 1
@@ -171,6 +173,9 @@ def Test_assignment()
171173
let thechannel: channel
172174
assert_equal(test_null_channel(), thechannel)
173175
endif
176+
177+
let nr = 1234 | nr = 5678
178+
assert_equal(5678, nr)
174179
enddef
175180

176181
func Test_assignment_failure()
@@ -253,8 +258,16 @@ enddef
253258

254259
func Test_block_failure()
255260
call CheckDefFailure(['{', 'let inner = 1', '}', 'echo inner'], 'E1001:')
261+
call CheckDefFailure(['}'], 'E1025:')
262+
call CheckDefFailure(['{', 'echo 1'], 'E1026:')
256263
endfunc
257264

265+
def Test_cmd_modifier()
266+
tab echo '0'
267+
call CheckDefFailure(['5tab echo 3'], 'E16:')
268+
enddef
269+
270+
258271
def ReturnString(): string
259272
return 'string'
260273
enddef
@@ -326,6 +339,8 @@ def Test_call_default_args()
326339
assert_equal('string', MyDefaultArgs())
327340
assert_equal('one', MyDefaultArgs('one'))
328341
assert_fails('call MyDefaultArgs("one", "two")', 'E118:')
342+
343+
call CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef'], 'E1001:')
329344
enddef
330345

331346
func Test_call_default_args_from_func()
@@ -480,6 +495,16 @@ def Test_try_catch_fails()
480495
call CheckDefFailure(['catch'], 'E603:')
481496
call CheckDefFailure(['try', 'echo 0', 'catch','catch'], 'E1033:')
482497
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:')
483508
enddef
484509

485510
let s:export_script_lines =<< trim END
@@ -939,6 +964,7 @@ def Test_if_elseif_else_fails()
939964
call CheckDefFailure(['else'], 'E581:')
940965
call CheckDefFailure(['endif'], 'E580:')
941966
call CheckDefFailure(['if true', 'elseif xxx'], 'E1001:')
967+
call CheckDefFailure(['if true', 'echo 1'], 'E171:')
942968
enddef
943969

944970
let g:bool_true = v:true
@@ -951,6 +977,16 @@ def Test_if_const_expr()
951977
endif
952978
assert_equal(true, res)
953979

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)
989+
954990
res = false
955991
if g:bool_true ? true : false
956992
res = true
@@ -1092,10 +1128,13 @@ def Test_execute_cmd()
10921128
execute cmd_first .. cmd_last
10931129
assert_equal('execute-var-var', getline(1))
10941130
bwipe!
1131+
1132+
call CheckDefFailure(['execute xxx'], 'E1001:')
10951133
enddef
10961134

10971135
def Test_echo_cmd()
1098-
echo 'something'
1136+
echo 'some'
1137+
echon 'thing'
10991138
assert_match('^something$', Screenline(&lines))
11001139

11011140
let str1 = 'some'
@@ -1141,6 +1180,7 @@ def Test_for_loop_fails()
11411180
call CheckDefFailure(['for i in "text"'], 'E1024:')
11421181
call CheckDefFailure(['for i in xxx'], 'E1001:')
11431182
call CheckDefFailure(['endfor'], 'E588:')
1183+
call CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
11441184
enddef
11451185

11461186
def Test_while_loop()
@@ -1166,6 +1206,7 @@ def Test_while_loop_fails()
11661206
call CheckDefFailure(['if true', 'continue'], 'E586:')
11671207
call CheckDefFailure(['break'], 'E587:')
11681208
call CheckDefFailure(['if true', 'break'], 'E587:')
1209+
call CheckDefFailure(['while 1', 'echo 3'], 'E170:')
11691210
enddef
11701211

11711212
def Test_interrupt_loop()
@@ -1185,28 +1226,6 @@ def Test_interrupt_loop()
11851226
assert_true(caught, 'should have caught an exception')
11861227
enddef
11871228

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-
12101229
def Test_redef_failure()
12111230
call writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef')
12121231
so Xdef
@@ -1285,4 +1304,27 @@ func Test_internalfunc_arg_error()
12851304
call delete('Xinvalidarg')
12861305
endfunc
12871306

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+
12881330
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
503,
741743
/**/
742744
502,
743745
/**/

src/vim9compile.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4972,14 +4972,14 @@ compile_finally(char_u *arg, cctx_T *cctx)
49724972
// Fill in the "end" label in jumps at the end of the blocks.
49734973
compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label, cctx);
49744974

4975+
isn->isn_arg.try.try_finally = instr->ga_len;
49754976
if (scope->se_u.se_try.ts_catch_label != 0)
49764977
{
49774978
// Previous catch without match jumps here
49784979
isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
49794980
isn->isn_arg.jump.jump_where = instr->ga_len;
49804981
}
49814982

4982-
isn->isn_arg.try.try_finally = instr->ga_len;
49834983
// TODO: set index in ts_finally_label jumps
49844984

49854985
return arg;
@@ -5350,13 +5350,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
53505350
line = p;
53515351
continue;
53525352
}
5353-
if (ea.cmdidx == CMD_let)
5354-
{
5355-
line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
5356-
if (line == NULL)
5357-
goto erret;
5358-
continue;
5359-
}
5353+
// CMD_let cannot happen, compile_assignment() above is used
53605354
iemsg("Command from find_ex_command() not handled");
53615355
goto erret;
53625356
}
@@ -5464,6 +5458,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
54645458
}
54655459
if (line == NULL)
54665460
goto erret;
5461+
line = skipwhite(line);
54675462

54685463
if (cctx.ctx_type_stack.ga_len < 0)
54695464
{

0 commit comments

Comments
 (0)