-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_test.go
More file actions
52 lines (42 loc) · 1.29 KB
/
interactive_test.go
File metadata and controls
52 lines (42 loc) · 1.29 KB
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
package cobi
import (
"errors"
"testing"
cobiEditor "github.com/arjit95/cobi/editor"
"github.com/gdamore/tcell"
"github.com/stretchr/testify/assert"
)
func TestInteractiveValidCmd(t *testing.T) {
editor := root.Editor
editor.SetCommandExecFunc(func(str string) error {
assert.Equal(t, "test1", str)
assert.Equal(t, root.InteractiveMode(), true)
return nil
})
root.App.SetBeforeDrawFunc(func(_ tcell.Screen) bool {
editor.Input.SetText("test1")
editor.Input.Done()
root.App.QueueEvent(tcell.NewEventKey(tcell.KeyCtrlO, 0, tcell.ModNone))
root.App.QueueEvent(tcell.NewEventKey(tcell.KeyCtrlE, 0, tcell.ModNone))
defer root.App.QueueEvent(tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone))
return true
})
err := root.ExecuteInteractive()
assert.NoError(t, err)
}
func TestInteractiveInvalidCmd(t *testing.T) {
editor := cobiEditor.NewEditor()
root = NewCommand(editor, root.Command)
editor.SetCommandExecFunc(func(str string) error {
assert.Equal(t, "test1 ", str)
return errors.New("Invalid command")
})
root.App.SetBeforeDrawFunc(func(_ tcell.Screen) bool {
editor.Input.SetText("test1 invalid")
editor.Input.Done()
root.App.QueueEvent(tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone))
return true
})
err := root.ExecuteInteractive()
assert.NoError(t, err)
}