-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcommands_test.go
More file actions
59 lines (53 loc) · 1.28 KB
/
commands_test.go
File metadata and controls
59 lines (53 loc) · 1.28 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
53
54
55
56
57
58
59
package tea
import (
"testing"
"time"
)
func TestEvery(t *testing.T) {
expected := "every ms"
msg := Every(time.Millisecond, func(t time.Time) Msg {
return expected
})()
if expected != msg {
t.Fatalf("expected a msg %v but got %v", expected, msg)
}
}
func TestTick(t *testing.T) {
expected := "tick"
msg := Tick(time.Millisecond, func(t time.Time) Msg {
return expected
})()
if expected != msg {
t.Fatalf("expected a msg %v but got %v", expected, msg)
}
}
func TestBatch(t *testing.T) {
testMultipleCommands[BatchMsg](t, Batch)
}
func TestSequence(t *testing.T) {
testMultipleCommands[sequenceMsg](t, Sequence)
}
func testMultipleCommands[T ~[]Cmd](t *testing.T, createFn func(cmd ...Cmd) Cmd) {
t.Run("nil cmd", func(t *testing.T) {
if b := createFn(nil); b != nil {
t.Fatalf("expected nil, got %+v", b)
}
})
t.Run("empty cmd", func(t *testing.T) {
if b := createFn(); b != nil {
t.Fatalf("expected nil, got %+v", b)
}
})
t.Run("single cmd", func(t *testing.T) {
b := createFn(Quit)()
if _, ok := b.(QuitMsg); !ok {
t.Fatalf("expected a QuitMsg, got %T", b)
}
})
t.Run("mixed nil cmds", func(t *testing.T) {
b := createFn(nil, Quit, nil, Quit, nil, nil)()
if l := len(b.(T)); l != 2 {
t.Fatalf("expected a []Cmd with len 2, got %d", l)
}
})
}