@@ -13,20 +13,25 @@ import (
13
13
func TestRegister (t * testing.T ) {
14
14
p := plugin .New (nvimtest .NewChildProcess (t ))
15
15
16
+ // simple handler
16
17
p .Handle ("hello" , func (s string ) (string , error ) {
17
18
return "Hello, " + s , nil
18
19
})
19
20
20
- p .HandleFunction (& plugin.FunctionOptions {Name : "Hello" }, func (args []string ) (string , error ) {
21
- return "Hello, " + strings .Join (args , " " ), nil
22
- })
21
+ // function handler
22
+ p .HandleFunction (& plugin.FunctionOptions {Name : "Hello" },
23
+ func (args []string ) (string , error ) {
24
+ return "Hello, " + strings .Join (args , " " ), nil
25
+ })
23
26
27
+ // function handler with eval
24
28
type testEval struct {
25
29
BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
26
30
}
27
- p .HandleFunction (& plugin.FunctionOptions {Name : "EvalTest" , Eval : "*" }, func (args []string , eval * testEval ) (string , error ) {
28
- return fmt .Sprintf ("BaseDir: %s" , eval .BaseDir ), nil
29
- })
31
+ p .HandleFunction (& plugin.FunctionOptions {Name : "TestEval" , Eval : "*" },
32
+ func (_ []string , eval * testEval ) (string , error ) {
33
+ return eval .BaseDir , nil
34
+ })
30
35
31
36
if err := p .RegisterForTests (); err != nil {
32
37
t .Fatalf ("register for test: %v" , err )
@@ -46,17 +51,16 @@ func TestRegister(t *testing.T) {
46
51
if err := p .Nvim .Call ("rpcrequest" , & result2 , cid , "hello" , "world" ); err != nil {
47
52
t .Fatalf ("call rpcrequest(%v, %v, %v, %v): %v" , & result2 , cid , "hello" , "world" , err )
48
53
}
49
- expected2 := " Hello, world"
54
+ expected2 := ` Hello, world`
50
55
if result2 != expected2 {
51
56
t .Fatalf ("hello returned %q, want %q" , result2 , expected2 )
52
57
}
53
58
54
59
var result3 string
55
- if err := p .Nvim .Eval (`EvalTest ()` , & result3 ); err != nil {
56
- t .Fatalf ("eval 'EvalTest ()' function: %v" , err )
60
+ if err := p .Nvim .Eval (`TestEval ()` , & result3 ); err != nil {
61
+ t .Fatalf ("eval 'TestEval ()' function: %v" , err )
57
62
}
58
-
59
- expected3 := "BaseDir: plugin"
63
+ expected3 := `plugin`
60
64
if result3 != expected3 {
61
65
t .Fatalf ("EvalTest returned %q, want %q" , result3 , expected3 )
62
66
}
0 commit comments