" Test commands that are not compiled in a :def function
source check.vim
source vim9.vim
source term_util.vim
source view_util.vim
def Test_vim9cmd()
var lines =<< trim END
vim9cmd var x = 123
let s:y = 'yes'
vim9c assert_equal(123, x)
vim9cm assert_equal('yes', y)
END
CheckScriptSuccess(lines)
enddef
def Test_edit_wildcards()
var filename = 'Xtest'
edit `=filename`
assert_equal('Xtest', bufname())
var filenr = 123
edit Xtest`=filenr`
assert_equal('Xtest123', bufname())
filenr = 77
edit `=filename``=filenr`
assert_equal('Xtest77', bufname())
edit X`=filename`xx`=filenr`yy
assert_equal('XXtestxx77yy', bufname())
CheckDefFailure(['edit `=xxx`'], 'E1001:')
CheckDefFailure(['edit `="foo"'], 'E1083:')
enddef
def Test_expand_alternate_file()
var lines =<< trim END
edit Xfileone
var bone = bufnr()
edit Xfiletwo
var btwo = bufnr()
edit Xfilethree
var bthree = bufnr()
edit #
assert_equal(bthree, bufnr())
edit %%
assert_equal(btwo, bufnr())
edit %% # comment
assert_equal(bthree, bufnr())
edit %%yy
assert_equal('Xfiletwoyy', bufname())
exe "edit %%" .. bone
assert_equal(bone, bufnr())
exe "edit %%" .. btwo .. "xx"
assert_equal('Xfiletwoxx', bufname())
next Xfileone Xfiletwo Xfilethree
assert_equal('Xfileone', argv(0))
assert_equal('Xfiletwo', argv(1))
assert_equal('Xfilethree', argv(2))
next %%%zz
assert_equal('Xfileone', argv(0))
assert_equal('Xfiletwo', argv(1))
assert_equal('Xfilethreezz', argv(2))
v:oldfiles = ['Xonefile', 'Xtwofile']
edit %%<1
assert_equal('Xonefile', bufname())
edit %%<2
assert_equal('Xtwofile', bufname())
assert_fails('edit %%<3', 'E684:')
edit Xfileone.vim
edit Xfiletwo
edit %%:r
assert_equal('Xfileone', bufname())
assert_false(bufexists('altfoo'))
edit altfoo
edit bar
assert_true(bufexists('altfoo'))
assert_true(buflisted('altfoo'))
bdel %%
assert_true(bufexists('altfoo'))
assert_false(buflisted('altfoo'))
bwipe! altfoo
bwipe! bar
END
CheckDefAndScriptSuccess(lines)
enddef
def Test_global_backtick_expansion()
new
setline(1, 'xx')
var name = 'foobar'
g/^xx/s/.*/`=name`
assert_equal('foobar', getline(1))
bwipe!
enddef
def Test_folddo_backtick_expansion()
new
var name = 'xxx'
folddoopen edit `=name`
assert_equal('xxx', bufname())
bwipe!
new
setline(1, ['one', 'two'])
set nomodified
:1,2fold
foldclose
folddoclose edit `=name`
assert_equal('xxx', bufname())
bwipe!
enddef
def Test_hardcopy_wildcards()
CheckUnix
CheckFeature postscript
var outfile = 'print'
hardcopy > X`=outfile`.ps
assert_true(filereadable('Xprint.ps'))
delete('Xprint.ps')
enddef
def Test_syn_include_wildcards()
writefile(['syn keyword Found found'], 'Xthemine.vim')
var save_rtp = &rtp
&rtp = '.'
var fname = 'mine'
syn include @Group Xthe`=fname`.vim
assert_match('Found.* contained found', execute('syn list Found'))
&rtp = save_rtp
delete('Xthemine.vim')
enddef
def Test_echo_linebreak()
var lines =<< trim END
vim9script
redir @a
echo 'one'
.. 'two'
redir END
assert_equal("\nonetwo", @a)
END
CheckScriptSuccess(lines)
lines =<< trim END
vim9script
redir @a
echo 11 +
77
- 22
redir END
assert_equal("\n66", @a)
END
CheckScriptSuccess(lines)
enddef
def Test_condition_types()
var lines =<< trim END
if 'text'
endif
END
CheckDefAndScriptFailure(lines, 'E1135:', 1)
lines =<< trim END
if [1]
endif
END
CheckDefFailure(lines, 'E1012:', 1)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 2)
lines =<< trim END
g:cond = 'text'
if g:cond
endif
END
CheckDefExecAndScriptFailure(lines, 'E1135:', 2)
lines =<< trim END
g:cond = 0
if g:cond
elseif 'text'
endif
END
CheckDefFailure(lines, 'E1012:', 3)
CheckScriptFailure(['vim9script'] + lines, 'E1135:', 4)
lines =<< trim END
if g:cond
elseif [1]
endif
END
CheckDefFailure(lines, 'E1012:', 2)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 3)
lines =<< trim END
g:cond = 'text'
if 0
elseif g:cond
endif
END
CheckDefExecAndScriptFailure(lines, 'E1135:', 3)
lines =<< trim END
while 'text'
endwhile
END
CheckDefFailure(lines, 'E1012:', 1)
CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2)
lines =<< trim END
while [1]
endwhile
END
CheckDefFailure(lines, 'E1012:',