Skip to content

Commit bdbf30c

Browse files
committed
nvim/plugin: add CommandRangeDotHandler and CommandCountHandler tests
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent a5a9c4d commit bdbf30c

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

nvim/plugin/plugin_test.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ func TestRegister(t *testing.T) {
5656
},
5757
func(n *nvim.Nvim, args []string) error {
5858
chunks := []nvim.TextChunk{
59-
{
60-
Text: `Hello`,
61-
},
59+
{Text: `Hello`},
6260
}
6361
for _, arg := range args {
6462
chunks = append(chunks, nvim.TextChunk{Text: arg})
@@ -68,6 +66,36 @@ func TestRegister(t *testing.T) {
6866
},
6967
)
7068

69+
// CommandRangeDotHandler
70+
p.HandleCommand(
71+
&plugin.CommandOptions{
72+
Name: "HelloRangeDot",
73+
Range: ".",
74+
},
75+
func(n *nvim.Nvim) error {
76+
chunks := []nvim.TextChunk{
77+
{Text: `Hello`},
78+
}
79+
80+
return n.Echo(chunks, true, make(map[string]interface{}))
81+
},
82+
)
83+
84+
// CommandCountHandler
85+
p.HandleCommand(
86+
&plugin.CommandOptions{
87+
Name: "HelloCount",
88+
Count: "0",
89+
},
90+
func(n *nvim.Nvim) error {
91+
chunks := []nvim.TextChunk{
92+
{Text: `Hello`},
93+
}
94+
95+
return n.Echo(chunks, true, make(map[string]interface{}))
96+
},
97+
)
98+
7199
// CommandEvalHandler
72100
p.HandleCommand(
73101
&plugin.CommandOptions{
@@ -86,7 +114,7 @@ func TestRegister(t *testing.T) {
86114
)
87115

88116
if err := p.RegisterForTests(); err != nil {
89-
t.Fatalf("register for test: %v", err)
117+
t.Fatalf("register handlers for test: %v", err)
90118
}
91119

92120
t.Run("SimpleHandler", func(t *testing.T) {
@@ -138,6 +166,30 @@ func TestRegister(t *testing.T) {
138166
}
139167
})
140168

169+
t.Run("CommandRangeDotHandler", func(t *testing.T) {
170+
result, err := p.Nvim.Exec(`HelloRangeDot`, true)
171+
if err != nil {
172+
t.Fatalf("exec 'Hello' command: %v", err)
173+
}
174+
175+
expected := `Hello`
176+
if result != expected {
177+
t.Fatalf("Hello returned %q, want %q", result, expected)
178+
}
179+
})
180+
181+
t.Run("CommandCountHandler", func(t *testing.T) {
182+
result, err := p.Nvim.Exec(`HelloCount`, true)
183+
if err != nil {
184+
t.Fatalf("exec 'Hello' command: %v", err)
185+
}
186+
187+
expected := `Hello`
188+
if result != expected {
189+
t.Fatalf("Hello returned %q, want %q", result, expected)
190+
}
191+
})
192+
141193
t.Run("CommandEvalHandler", func(t *testing.T) {
142194
result, err := p.Nvim.Exec(`HelloEval`, true)
143195
if err != nil {

0 commit comments

Comments
 (0)