2020-04-25 20:02:55 +02:00
|
|
|
" Test commands that are not compiled in a :def function
|
|
|
|
|
2020-04-26 13:50:41 +02:00
|
|
|
source check.vim
|
2020-04-25 20:02:55 +02:00
|
|
|
source vim9.vim
|
2020-07-05 14:57:51 +02:00
|
|
|
source view_util.vim
|
2020-04-25 20:02:55 +02:00
|
|
|
|
|
|
|
def Test_edit_wildcards()
|
2020-09-27 19:05:33 +02:00
|
|
|
var filename = 'Xtest'
|
2020-04-25 20:02:55 +02:00
|
|
|
edit `=filename`
|
|
|
|
assert_equal('Xtest', bufname())
|
|
|
|
|
2020-09-27 19:05:33 +02:00
|
|
|
var filenr = 123
|
2020-04-25 20:02:55 +02:00
|
|
|
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())
|
|
|
|
enddef
|
|
|
|
|
2020-04-26 13:50:41 +02:00
|
|
|
def Test_hardcopy_wildcards()
|
|
|
|
CheckUnix
|
|
|
|
CheckFeature postscript
|
|
|
|
|
2020-09-27 19:05:33 +02:00
|
|
|
var outfile = 'print'
|
2020-04-26 13:50:41 +02:00
|
|
|
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')
|
2020-09-27 19:05:33 +02:00
|
|
|
var save_rtp = &rtp
|
2020-04-26 13:50:41 +02:00
|
|
|
&rtp = '.'
|
|
|
|
|
2020-09-27 19:05:33 +02:00
|
|
|
var fname = 'mine'
|
2020-04-26 13:50:41 +02:00
|
|
|
syn include @Group Xthe`=fname`.vim
|
|
|
|
assert_match('Found.* contained found', execute('syn list Found'))
|
|
|
|
|
|
|
|
&rtp = save_rtp
|
|
|
|
delete('Xthemine.vim')
|
|
|
|
enddef
|
|
|
|
|
2020-06-27 21:56:17 +02:00
|
|
|
def Test_echo_linebreak()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-06-27 21:56:17 +02:00
|
|
|
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
|
|
|
|
|
2020-06-27 23:07:36 +02:00
|
|
|
def Test_if_linebreak()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-06-27 23:07:36 +02:00
|
|
|
vim9script
|
|
|
|
if 1 &&
|
2020-10-03 22:52:39 +02:00
|
|
|
true
|
|
|
|
|| 1
|
2020-06-27 23:07:36 +02:00
|
|
|
g:res = 42
|
|
|
|
endif
|
|
|
|
assert_equal(42, g:res)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
unlet g:res
|
|
|
|
|
|
|
|
lines =<< trim END
|
|
|
|
vim9script
|
|
|
|
if 1 &&
|
|
|
|
0
|
|
|
|
g:res = 0
|
|
|
|
elseif 0 ||
|
|
|
|
0
|
|
|
|
|| 1
|
|
|
|
g:res = 12
|
|
|
|
endif
|
|
|
|
assert_equal(12, g:res)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
unlet g:res
|
|
|
|
enddef
|
|
|
|
|
|
|
|
def Test_while_linebreak()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-06-27 23:07:36 +02:00
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var nr = 0
|
2020-06-28 15:51:16 +02:00
|
|
|
while nr <
|
|
|
|
10 + 3
|
|
|
|
nr = nr
|
|
|
|
+ 4
|
|
|
|
endwhile
|
|
|
|
assert_equal(16, nr)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
|
|
|
|
lines =<< trim END
|
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var nr = 0
|
2020-06-28 15:51:16 +02:00
|
|
|
while nr
|
|
|
|
<
|
|
|
|
10
|
|
|
|
+
|
|
|
|
3
|
|
|
|
nr = nr
|
|
|
|
+
|
|
|
|
4
|
2020-06-27 23:07:36 +02:00
|
|
|
endwhile
|
|
|
|
assert_equal(16, nr)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
enddef
|
2020-04-25 20:02:55 +02:00
|
|
|
|
2020-06-28 18:43:40 +02:00
|
|
|
def Test_for_linebreak()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-06-28 18:43:40 +02:00
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var nr = 0
|
2020-06-28 18:43:40 +02:00
|
|
|
for x
|
|
|
|
in
|
|
|
|
[1, 2, 3, 4]
|
|
|
|
nr = nr + x
|
|
|
|
endfor
|
|
|
|
assert_equal(10, nr)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
|
|
|
|
lines =<< trim END
|
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var nr = 0
|
2020-06-28 18:43:40 +02:00
|
|
|
for x
|
|
|
|
in
|
|
|
|
[1, 2,
|
|
|
|
3, 4
|
|
|
|
]
|
|
|
|
nr = nr
|
|
|
|
+
|
|
|
|
x
|
|
|
|
endfor
|
|
|
|
assert_equal(10, nr)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
enddef
|
|
|
|
|
2020-07-02 21:11:34 +02:00
|
|
|
def Test_method_call_linebreak()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-07-01 20:07:14 +02:00
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var res = []
|
2020-07-01 20:07:14 +02:00
|
|
|
func RetArg(
|
|
|
|
arg
|
|
|
|
)
|
|
|
|
let s:res = a:arg
|
|
|
|
endfunc
|
|
|
|
[1,
|
|
|
|
2,
|
|
|
|
3]->RetArg()
|
|
|
|
assert_equal([1, 2, 3], res)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
enddef
|
|
|
|
|
2020-07-08 18:30:06 +02:00
|
|
|
def Test_dict_member()
|
2020-09-27 19:05:33 +02:00
|
|
|
var test: dict<list<number>> = {'data': [3, 1, 2]}
|
2020-07-08 18:30:06 +02:00
|
|
|
test.data->sort()
|
|
|
|
assert_equal(#{data: [1, 2, 3]}, test)
|
|
|
|
test.data
|
|
|
|
->reverse()
|
|
|
|
assert_equal(#{data: [3, 2, 1]}, test)
|
|
|
|
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-07-08 18:30:06 +02:00
|
|
|
vim9script
|
2020-09-27 19:05:33 +02:00
|
|
|
var test: dict<list<number>> = {'data': [3, 1, 2]}
|
2020-07-08 18:30:06 +02:00
|
|
|
test.data->sort()
|
|
|
|
assert_equal(#{data: [1, 2, 3]}, test)
|
|
|
|
END
|
|
|
|
CheckScriptSuccess(lines)
|
|
|
|
enddef
|
|
|
|
|
2020-07-05 14:57:51 +02:00
|
|
|
def Test_bar_after_command()
|
|
|
|
def RedrawAndEcho()
|
2020-09-27 19:05:33 +02:00
|
|
|
var x = 'did redraw'
|
2020-07-05 14:57:51 +02:00
|
|
|
redraw | echo x
|
|
|
|
enddef
|
|
|
|
RedrawAndEcho()
|
|
|
|
assert_match('did redraw', Screenline(&lines))
|
|
|
|
|
2020-07-05 15:32:17 +02:00
|
|
|
def CallAndEcho()
|
2020-09-27 19:05:33 +02:00
|
|
|
var x = 'did redraw'
|
2020-07-05 15:32:17 +02:00
|
|
|
reg_executing() | echo x
|
|
|
|
enddef
|
|
|
|
CallAndEcho()
|
|
|
|
assert_match('did redraw', Screenline(&lines))
|
|
|
|
|
2020-07-05 14:57:51 +02:00
|
|
|
if has('unix')
|
|
|
|
# bar in filter write command does not start new command
|
|
|
|
def WriteToShell()
|
|
|
|
new
|
|
|
|
setline(1, 'some text')
|
|
|
|
w !cat | cat > Xoutfile
|
|
|
|
bwipe!
|
|
|
|
enddef
|
|
|
|
WriteToShell()
|
|
|
|
assert_equal(['some text'], readfile('Xoutfile'))
|
|
|
|
delete('Xoutfile')
|
|
|
|
|
|
|
|
# bar in filter read command does not start new command
|
|
|
|
def ReadFromShell()
|
|
|
|
new
|
|
|
|
r! echo hello there | cat > Xoutfile
|
|
|
|
r !echo again | cat >> Xoutfile
|
|
|
|
bwipe!
|
|
|
|
enddef
|
|
|
|
ReadFromShell()
|
|
|
|
assert_equal(['hello there', 'again'], readfile('Xoutfile'))
|
|
|
|
delete('Xoutfile')
|
|
|
|
endif
|
|
|
|
enddef
|
|
|
|
|
2020-07-11 13:40:45 +02:00
|
|
|
def Test_filter_is_not_modifier()
|
2020-09-27 19:05:33 +02:00
|
|
|
var tags = [{'a': 1, 'b': 2}, {'x': 3, 'y': 4}]
|
2020-07-11 13:40:45 +02:00
|
|
|
filter(tags, { _, v -> has_key(v, 'x') ? 1 : 0 })
|
|
|
|
assert_equal([#{x: 3, y: 4}], tags)
|
|
|
|
enddef
|
|
|
|
|
2020-07-06 23:04:49 +02:00
|
|
|
def Test_eval_command()
|
2020-09-27 19:05:33 +02:00
|
|
|
var from = 3
|
|
|
|
var to = 5
|
2020-07-06 23:04:49 +02:00
|
|
|
g:val = 111
|
|
|
|
def Increment(nrs: list<number>)
|
|
|
|
for nr in nrs
|
|
|
|
g:val += nr
|
|
|
|
endfor
|
|
|
|
enddef
|
|
|
|
eval range(from, to)
|
|
|
|
->Increment()
|
|
|
|
assert_equal(111 + 3 + 4 + 5, g:val)
|
|
|
|
unlet g:val
|
|
|
|
enddef
|
|
|
|
|
2020-08-20 18:02:47 +02:00
|
|
|
def Test_map_command()
|
2020-09-27 19:05:33 +02:00
|
|
|
var lines =<< trim END
|
2020-08-20 18:02:47 +02:00
|
|
|
nnoremap <F3> :echo 'hit F3 #'<CR>
|
|
|
|
assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
|
|
|
|
END
|
|
|
|
CheckDefSuccess(lines)
|
|
|
|
CheckScriptSuccess(['vim9script'] + lines)
|
|
|
|
enddef
|
|
|
|
|
2020-08-23 21:46:32 +02:00
|
|
|
def Test_normal_command()
|
|
|
|
new
|
|
|
|
setline(1, 'doesnotexist')
|
2020-09-27 19:05:33 +02:00
|
|
|
var caught = 0
|
2020-08-23 21:46:32 +02:00
|
|
|
try
|
|
|
|
exe "norm! \<C-]>"
|
|
|
|
catch /E433/
|
|
|
|
caught = 2
|
|
|
|
endtry
|
|
|
|
assert_equal(2, caught)
|
|
|
|
|
|
|
|
try
|
|
|
|
exe "norm! 3\<C-]>"
|
|
|
|
catch /E433/
|
|
|
|
caught = 3
|
|
|
|
endtry
|
|
|
|
assert_equal(3, caught)
|
|
|
|
bwipe!
|
|
|
|
enddef
|
|
|
|
|
2020-09-08 22:45:35 +02:00
|
|
|
def Test_put_command()
|
|
|
|
new
|
|
|
|
@p = 'ppp'
|
|
|
|
put p
|
|
|
|
assert_equal('ppp', getline(2))
|
|
|
|
|
|
|
|
put ='below'
|
|
|
|
assert_equal('below', getline(3))
|
|
|
|
put! ='above'
|
|
|
|
assert_equal('above', getline(3))
|
|
|
|
assert_equal('below', getline(4))
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
enddef
|
|
|
|
|
2020-09-14 16:37:34 +02:00
|
|
|
def Test_command_star_range()
|
|
|
|
new
|
|
|
|
setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar'])
|
|
|
|
setpos("'<", [0, 1, 0, 0])
|
|
|
|
setpos("'>", [0, 3, 0, 0])
|
|
|
|
:*s/\(foo\|bar\)/baz/g
|
|
|
|
getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz'])
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
enddef
|
|
|
|
|
2020-09-08 22:45:35 +02:00
|
|
|
|
2020-06-28 18:43:40 +02:00
|
|
|
|
2020-04-25 20:02:55 +02:00
|
|
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|