Skip to content

Commit 547c511

Browse files
committed
nvim/plugin: add more testcases
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 3482243 commit 547c511

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

nvim/plugin/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ func (p *Plugin) RegisterForTests() error {
365365

366366
const host = "nvim-go-test"
367367
for path, specs := range specs {
368-
if err := p.Nvim.Call(`remote#host#RegisterPlugin`, nil, host, path, specs); err != nil {
368+
if err := p.Nvim.Call("remote#host#RegisterPlugin", nil, host, path, specs); err != nil {
369369
return err
370370
}
371371
}
372-
err := p.Nvim.Call(`remote#host#Register`, nil, host, `x`, p.Nvim.ChannelID())
372+
err := p.Nvim.Call("remote#host#Register", nil, host, "x", p.Nvim.ChannelID())
373373

374374
return err
375375
}

nvim/plugin/plugin_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@ import (
1313
func 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

Comments
 (0)