junegunn / vader.vim

A simple Vimscript test framework
588 stars 40 forks source link

Can Vader work with Vim9 script? #225

Open Aster89 opened 2 years ago

Aster89 commented 2 years ago

Such a code passes (and it expectedly fails if I change the second argument to AssertEqual), suggesting that Vader is indeed executing Vim9 script code:

Execute (vim9 var):
  vim9cmd var path = '/some/path/to/file.txt'
  AssertEqual path, '/some/path/to/file.txt'

But if I write this

Execute (vim9 lambda):
  vim9cmd var Identity = (x) => x
  AssertEqual Identity(3), 3

it fails like this

Starting Vader: 1 suite(s), 1 case(s)
  Starting Vader: /home/enrico/.vim/plugged/WinZoZ/test/winzoz.vader
    (1/1) [EXECUTE] vim9 lambda
    (1/1) [EXECUTE] (X) Vim(call):E117: Unknown function: Identity
      > command line..function <SNR>24_vader[5]..vader#run[63]..<SNR>96_run[42]..<SNR>96_execute[2]..vader#window#execute[11]..script /tmp/vvIdE4r/3, line 2
  Success/Total: 0/1
Success/Total: 0/1 (assertions: 0/0)
Elapsed time: 0.01 sec.
Failure

suggesting that something is not quite right...

Anybody knows?

igbanam commented 1 year ago

You'd need to modify your test in a few ways.

tl;dr

Execute (vim9 lambda):
  vim9cmd g:Identity = (x) => x
  AssertEqual Identity(3), 3

Modifications…

  1. Identity must be global to be used with Assert...
  2. Vim9 does not allow us "declare" global variables with var