comparison src/testdir/test_vim9_script.vim @ 19281:9fcdeaa18bd1 v8.2.0199

patch 8.2.0199: Vim9 script commands not sufficiently tested Commit: https://github.com/vim/vim/commit/0f18b6d17baa7d33f209a3184726a162c2bb7ed8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 2 17:22:27 2020 +0100 patch 8.2.0199: Vim9 script commands not sufficiently tested Problem: Vim9 script commands not sufficiently tested. Solution: Add more tests. Fix script-local function use.
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Feb 2020 17:30:03 +0100
parents a8d2d3c8f0b3
children 9dc843109c97
comparison
equal deleted inserted replaced
19280:669bd4306d67 19281:9fcdeaa18bd1
104 Increment() 104 Increment()
105 Increment() 105 Increment()
106 Increment() 106 Increment()
107 " works with and without :call 107 " works with and without :call
108 assert_equal(4, g:counter) 108 assert_equal(4, g:counter)
109 call assert_equal(4, g:counter) 109 assert_equal(4, g:counter)
110 unlet g:counter 110 unlet g:counter
111 enddef 111 enddef
112 112
113 def MyVarargs(arg: string, ...rest: list<string>): string 113 def MyVarargs(arg: string, ...rest: list<string>): string
114 let res = arg 114 let res = arg
352 " will be allocated as one piece of memory, check that changes work 352 " will be allocated as one piece of memory, check that changes work
353 let l = [1, 2, 3, 4] 353 let l = [1, 2, 3, 4]
354 l->remove(0) 354 l->remove(0)
355 l->add(5) 355 l->add(5)
356 l->insert(99, 1) 356 l->insert(99, 1)
357 call assert_equal([2, 99, 3, 4, 5], l) 357 assert_equal([2, 99, 3, 4, 5], l)
358 enddef 358 enddef
359 359
360 " Test that inside :function a Python function can be defined, :def is not 360 " Test that inside :function a Python function can be defined, :def is not
361 " recognized. 361 " recognized.
362 func Test_function_python() 362 func Test_function_python()
385 enddef 385 enddef
386 386
387 def Test_compile_const_expr() 387 def Test_compile_const_expr()
388 assert_equal("\nyes", execute('call HasEval()')) 388 assert_equal("\nyes", execute('call HasEval()'))
389 let instr = execute('disassemble HasEval') 389 let instr = execute('disassemble HasEval')
390 call assert_match('PUSHS "yes"', instr) 390 assert_match('PUSHS "yes"', instr)
391 call assert_notmatch('PUSHS "no"', instr) 391 assert_notmatch('PUSHS "no"', instr)
392 call assert_notmatch('JUMP', instr) 392 assert_notmatch('JUMP', instr)
393 393
394 assert_equal("\nno", execute('call HasNothing()')) 394 assert_equal("\nno", execute('call HasNothing()'))
395 instr = execute('disassemble HasNothing') 395 instr = execute('disassemble HasNothing')
396 call assert_notmatch('PUSHS "yes"', instr) 396 assert_notmatch('PUSHS "yes"', instr)
397 call assert_match('PUSHS "no"', instr) 397 assert_match('PUSHS "no"', instr)
398 call assert_notmatch('JUMP', instr) 398 assert_notmatch('JUMP', instr)
399 enddef
400
401 func NotCompiled()
402 echo "not"
403 endfunc
404
405 let s:scriptvar = 4
406 let g:globalvar = 'g'
407
408 def s:ScriptFunc(arg: string)
409 let local = 1
410 buffers
411 echo arg
412 echo local
413 echo v:version
414 echo s:scriptvar
415 echo g:globalvar
416 echo &tabstop
417 echo $ENVVAR
418 echo @z
419 enddef
420
421 def Test_disassemble()
422 assert_fails('disass NoFunc', 'E1061:')
423 assert_fails('disass NotCompiled', 'E1062:')
424
425 let res = execute('disass s:ScriptFunc')
426 assert_match('<SNR>\d*_ScriptFunc.*'
427 \ .. 'buffers.*'
428 \ .. ' EXEC \+buffers.*'
429 \ .. ' LOAD arg\[-1\].*'
430 \ .. ' LOAD $0.*'
431 \ .. ' LOADV v:version.*'
432 \ .. ' LOADS s:scriptvar from .*test_vim9_script.vim.*'
433 \ .. ' LOADG g:globalvar.*'
434 \ .. ' LOADENV $ENVVAR.*'
435 \ .. ' LOADREG @z.*', res)
399 enddef 436 enddef
400 437
401 438
402 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 439 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker