-
Notifications
You must be signed in to change notification settings - Fork 9
/
register_test.go
60 lines (45 loc) · 1.22 KB
/
register_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2014 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package commands
import (
"fmt"
"testing"
"github.com/limetext/backend"
)
type DummyApplicationCommand struct {
backend.DefaultCommand
}
func (c *DummyApplicationCommand) Run() error {
return fmt.Errorf("Ran")
}
func (c *DummyApplicationCommand) IsChecked() bool {
return false
}
func TestRegisterByName(t *testing.T) {
ed := backend.GetEditor()
name := "dummy"
registerByName([]namedCmd{
{name, &DummyApplicationCommand{}},
})
err := ed.CommandHandler().RunApplicationCommand(name, nil)
if err == nil {
t.Errorf("Expected %s to run, but it didn't", name)
} else if err.Error() != "Ran" {
t.Errorf("Expected %s to run, but it got an error: %v", name, err)
}
}
func TestRegister(t *testing.T) {
ed := backend.GetEditor()
ac := &DummyApplicationCommand{}
register([]backend.Command{
ac,
})
name := backend.DefaultName(ac)
err := ed.CommandHandler().RunApplicationCommand(name, nil)
if err == nil {
t.Errorf("Expected %s to run, but it didn't", name)
} else if err.Error() != "Ran" {
t.Errorf("Expected %s to run, but it got an error: %v", name, err)
}
}