-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions_test.go
73 lines (63 loc) · 1.96 KB
/
options_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
61
62
63
64
65
66
67
68
69
70
71
72
73
package catwalk
import (
"testing"
tea "github.com/charmbracelet/bubbletea"
)
// TestDisableAutoInit checks the WithAutoInitDisabled configuration option.
func TestDisableAutoInit(t *testing.T) {
RunModel(t, "testdata/disable_auto_start", emptyModel{}, WithAutoInitDisabled())
}
// TestInitWindowSize checks that a WindowSizeMsg is sent at the first interaction.
func TestInitWindowSize(t *testing.T) {
RunModel(t, "testdata/window_size", emptyModel{}, WithWindowSize(80, 25))
}
func TestChainUpdaters(t *testing.T) {
upd1 := func(_ tea.Model, cmd string, _ ...string) (bool, tea.Model, tea.Cmd, error) {
if cmd == "hello" {
return true, nil, nil, nil
}
return false, nil, nil, nil
}
upd2 := func(_ tea.Model, cmd string, _ ...string) (bool, tea.Model, tea.Cmd, error) {
if cmd == "world" {
return true, nil, nil, nil
}
return false, nil, nil, nil
}
upd := ChainUpdaters(upd1, upd2)
if s, _, _, _ := ChainUpdaters(upd1)(nil, "hello"); !s {
t.Errorf("updater doesn't propagate single argument")
}
if s, _, _, _ := upd(nil, "hello"); !s {
t.Errorf("first updater did not register")
}
if s, _, _, _ := upd(nil, "world"); !s {
t.Errorf("2nd updater did not register")
}
if s, _, _, _ := upd(nil, "unknown"); s {
t.Errorf("surprising updater result")
}
if s, _, _, _ := ChainUpdaters()(nil, "unknown"); s {
t.Errorf("surprising updater result")
}
}
func TestChainComplexUpdaters(t *testing.T) {
hm := &helpModelR{}
upd1 := KeyMapUpdater("hello", SimpleKeyMapApplier(&hm.KeyMap))
upd2 := StylesUpdater("help", SimpleStylesApplier(&hm.help.Styles))
upd3 := func(m tea.Model, cmd string, args ...string) (bool, tea.Model, tea.Cmd, error) {
m.(*helpModelR).val = 123
return true, m, nil, nil
}
const test = `
run
keybind hello.MyKey ctrl+c
keyhelp hello.MyKey C-c break
restyle help.Ellipsis foreground: #f00
othercmd
----
-- view:
VALUE: 123
C-c break 🛇`
RunModelFromString(t, test, hm, WithUpdater(upd1), WithUpdater(upd2), WithUpdater(upd3))
}