Skip to content

Commit a5a9c4d

Browse files
committed
nvim/plugin: add CommandEvalHandler testcases
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent a2878fa commit a5a9c4d

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

nvim/plugin/plugin_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
func TestRegister(t *testing.T) {
1414
t.Parallel()
1515

16+
type testEval struct {
17+
BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
18+
}
19+
1620
p := plugin.New(nvimtest.NewChildProcess(t))
1721

1822
// SimpleHandler
@@ -31,16 +35,14 @@ func TestRegister(t *testing.T) {
3135
)
3236

3337
// FunctionEvalHandler
34-
type testEval struct {
35-
BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
36-
}
3738
p.HandleFunction(
3839
&plugin.FunctionOptions{Name: "TestEval", Eval: "*"},
3940
func(_ []string, eval *testEval) (string, error) {
4041
return eval.BaseDir, nil
4142
},
4243
)
4344

45+
// CommandHandler
4446
p.HandleCommand(
4547
&plugin.CommandOptions{
4648
Name: "Hello",
@@ -66,6 +68,23 @@ func TestRegister(t *testing.T) {
6668
},
6769
)
6870

71+
// CommandEvalHandler
72+
p.HandleCommand(
73+
&plugin.CommandOptions{
74+
Name: "HelloEval",
75+
Eval: "*",
76+
},
77+
func(n *nvim.Nvim, eval *testEval) error {
78+
chunks := []nvim.TextChunk{
79+
{
80+
Text: eval.BaseDir,
81+
},
82+
}
83+
84+
return n.Echo(chunks, true, make(map[string]interface{}))
85+
},
86+
)
87+
6988
if err := p.RegisterForTests(); err != nil {
7089
t.Fatalf("register for test: %v", err)
7190
}
@@ -118,6 +137,18 @@ func TestRegister(t *testing.T) {
118137
t.Fatalf("Hello returned %q, want %q", result, expected)
119138
}
120139
})
140+
141+
t.Run("CommandEvalHandler", func(t *testing.T) {
142+
result, err := p.Nvim.Exec(`HelloEval`, true)
143+
if err != nil {
144+
t.Fatalf("exec 'Hello' command: %v", err)
145+
}
146+
147+
expected := `plugin`
148+
if result != expected {
149+
t.Fatalf("Hello returned %q, want %q", result, expected)
150+
}
151+
})
121152
}
122153

123154
func TestSubscribe(t *testing.T) {

0 commit comments

Comments
 (0)