junegunn / junegunn/vader.vim

Can Vader test imported Vim9 functions?

Open
#226 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
599
Forks
40
PR merge metrics
No merged PRs in 30d

Description

I have a function which checks that some string starts with another string in my `utils.vim`

```
# Checks if the left string starts with the right
export def StartsWith(longer: string, shorter: string): bool
if (shorter->len() > longer->len())
return false
endif

var right_bound = shorter->len() - 1

return longer[0 : right_bound] ==# shorter
enddef
```

_culled from https://vi.stackexchange.com/a/29063_

I want to write a test that this works, so I create a `utils.vader` with the following content

```
Execute (Forza):
import getcwd() .. '/utils.vim'
Assert v:true, 'vim'->utils.StartsWith('vi')
```

[`:h vim9-import`](https://vimhelp.org/vim9.txt.html#vim9-import) allows us use the exported functions from the imported script in the current script's scope. [`:h getcwd()`](https://vimhelp.org/builtin.txt.html#getcwd%28%29) is there to ensure I'm loading the right file.

The error I get back hints that the script wasn't loaded.

```
Starting Vader: 1 suite(s), 1 case(s)
Starting Vader: /Users/igbanam/projects/X/utils.vader
(1/1) [EXECUTE] Linter
(1/1) [EXECUTE] (X) Vim(call):E121: Undefined variable: utils
> function test#run[27]..test#execute[23]..test#shell[19]..test#strategy#vimscript[1]..vader#run[63]..244_run[42]..244_execute[2]..vader#window#execute[11]..script /private/var/folders/bd/2lzxs5dn6rqg5xdpbk9m52pc0000gn/T/vJFrhtt/18, line 2
Success/Total: 0/1
Success/Total: 0/1 (assertions: 0/0)
Elapsed time: 0.04 sec.

```

Any ideas?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.