Skip to content

Commit 01a928e

Browse files
committed
nvim: add AddBufferUserCommand and DeleteBufferUserCommand testcase
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent f7394a4 commit 01a928e

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

nvim/api_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,72 @@ func testCommand(v *Nvim) func(*testing.T) {
21442144
})
21452145
}
21462146
})
2147+
2148+
t.Run("BufferUserCommand", func(t *testing.T) {
2149+
tests := map[string]struct {
2150+
name string
2151+
command UserCommand
2152+
opts map[string]interface{}
2153+
want string
2154+
}{
2155+
"SayHello": {
2156+
name: "SayHello",
2157+
command: UserVimCommand(`echo "Hello world!"`),
2158+
opts: map[string]interface{}{
2159+
"force": false,
2160+
},
2161+
want: "Hello world!",
2162+
},
2163+
}
2164+
for name, tt := range tests {
2165+
t.Run(path.Join(name, "Nvim"), func(t *testing.T) {
2166+
skipVersion(t, "v0.7.0")
2167+
2168+
if err := v.AddBufferUserCommand(Buffer(0), tt.name, tt.command, tt.opts); err != nil {
2169+
t.Fatal(err)
2170+
}
2171+
t.Cleanup(func() {
2172+
if err := v.DeleteBufferUserCommand(Buffer(0), tt.name); err != nil {
2173+
t.Fatal(err)
2174+
}
2175+
})
2176+
2177+
got, err := v.Exec(tt.name, true)
2178+
if err != nil {
2179+
t.Fatal(err)
2180+
}
2181+
if !strings.EqualFold(tt.want, got) {
2182+
t.Fatalf("expected %s but got %s", tt.want, got)
2183+
}
2184+
})
2185+
2186+
t.Run(path.Join(name, "Batch"), func(t *testing.T) {
2187+
skipVersion(t, "v0.7.0")
2188+
2189+
b := v.NewBatch()
2190+
2191+
b.AddBufferUserCommand(Buffer(0), tt.name, tt.command, tt.opts)
2192+
if err := b.Execute(); err != nil {
2193+
t.Fatal(err)
2194+
}
2195+
t.Cleanup(func() {
2196+
b.DeleteBufferUserCommand(Buffer(0), tt.name)
2197+
if err := b.Execute(); err != nil {
2198+
t.Fatal(err)
2199+
}
2200+
})
2201+
2202+
var got string
2203+
b.Exec(tt.name, true, &got)
2204+
if err := b.Execute(); err != nil {
2205+
t.Fatal(err)
2206+
}
2207+
if !strings.EqualFold(tt.want, got) {
2208+
t.Fatalf("expected %s but got %s", tt.want, got)
2209+
}
2210+
})
2211+
}
2212+
})
21472213
}
21482214
}
21492215

0 commit comments

Comments
 (0)