@@ -13,20 +13,25 @@ import (
1313func TestRegister (t * testing.T ) {
1414 p := plugin .New (nvimtest .NewChildProcess (t ))
1515
16+ // simple handler
1617 p .Handle ("hello" , func (s string ) (string , error ) {
1718 return "Hello, " + s , nil
1819 })
1920
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+ })
2326
27+ // function handler with eval
2428 type testEval struct {
2529 BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
2630 }
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+ })
3035
3136 if err := p .RegisterForTests (); err != nil {
3237 t .Fatalf ("register for test: %v" , err )
@@ -46,17 +51,16 @@ func TestRegister(t *testing.T) {
4651 if err := p .Nvim .Call ("rpcrequest" , & result2 , cid , "hello" , "world" ); err != nil {
4752 t .Fatalf ("call rpcrequest(%v, %v, %v, %v): %v" , & result2 , cid , "hello" , "world" , err )
4853 }
49- expected2 := " Hello, world"
54+ expected2 := ` Hello, world`
5055 if result2 != expected2 {
5156 t .Fatalf ("hello returned %q, want %q" , result2 , expected2 )
5257 }
5358
5459 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 )
5762 }
58-
59- expected3 := "BaseDir: plugin"
63+ expected3 := `plugin`
6064 if result3 != expected3 {
6165 t .Fatalf ("EvalTest returned %q, want %q" , result3 , expected3 )
6266 }
0 commit comments