@@ -13,6 +13,10 @@ import (
13
13
func TestRegister (t * testing.T ) {
14
14
t .Parallel ()
15
15
16
+ type testEval struct {
17
+ BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
18
+ }
19
+
16
20
p := plugin .New (nvimtest .NewChildProcess (t ))
17
21
18
22
// SimpleHandler
@@ -31,16 +35,14 @@ func TestRegister(t *testing.T) {
31
35
)
32
36
33
37
// FunctionEvalHandler
34
- type testEval struct {
35
- BaseDir string `eval:"fnamemodify(getcwd(), ':t')"`
36
- }
37
38
p .HandleFunction (
38
39
& plugin.FunctionOptions {Name : "TestEval" , Eval : "*" },
39
40
func (_ []string , eval * testEval ) (string , error ) {
40
41
return eval .BaseDir , nil
41
42
},
42
43
)
43
44
45
+ // CommandHandler
44
46
p .HandleCommand (
45
47
& plugin.CommandOptions {
46
48
Name : "Hello" ,
@@ -66,6 +68,23 @@ func TestRegister(t *testing.T) {
66
68
},
67
69
)
68
70
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
+
69
88
if err := p .RegisterForTests (); err != nil {
70
89
t .Fatalf ("register for test: %v" , err )
71
90
}
@@ -118,6 +137,18 @@ func TestRegister(t *testing.T) {
118
137
t .Fatalf ("Hello returned %q, want %q" , result , expected )
119
138
}
120
139
})
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
+ })
121
152
}
122
153
123
154
func TestSubscribe (t * testing.T ) {
0 commit comments