-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathoptions_test.go
More file actions
97 lines (84 loc) · 2.36 KB
/
options_test.go
File metadata and controls
97 lines (84 loc) · 2.36 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package tea
import (
"bytes"
"context"
"os"
"sync/atomic"
"testing"
)
func TestOptions(t *testing.T) {
t.Run("output", func(t *testing.T) {
var b bytes.Buffer
p := NewProgram(nil, WithOutput(&b))
if f, ok := p.output.(*os.File); ok {
t.Errorf("expected output to custom, got %v", f.Fd())
}
})
t.Run("renderer", func(t *testing.T) {
p := NewProgram(nil, WithoutRenderer())
if !p.disableRenderer {
t.Errorf("expected renderer to be a nilRenderer, got %v", p.renderer)
}
})
t.Run("without signals", func(t *testing.T) {
p := NewProgram(nil, WithoutSignals())
if atomic.LoadUint32(&p.ignoreSignals) == 0 {
t.Errorf("ignore signals should have been set")
}
})
t.Run("filter", func(t *testing.T) {
p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg }))
if p.filter == nil {
t.Errorf("expected filter to be set")
}
})
t.Run("external context", func(t *testing.T) {
extCtx, extCancel := context.WithCancel(context.Background())
defer extCancel()
p := NewProgram(nil, WithContext(extCtx))
if p.externalCtx != extCtx || p.externalCtx == context.Background() {
t.Errorf("expected passed in external context, got default")
}
})
t.Run("input options", func(t *testing.T) {
exercise := func(t *testing.T, opt ProgramOption, fn func(*Program)) {
p := NewProgram(nil, opt)
fn(p)
}
t.Run("nil input", func(t *testing.T) {
exercise(t, WithInput(nil), func(p *Program) {
if !p.disableInput || p.input != nil {
t.Errorf("expected input to be disabled, got %v", p.input)
}
})
})
t.Run("custom input", func(t *testing.T) {
var b bytes.Buffer
exercise(t, WithInput(&b), func(p *Program) {
if p.input != &b {
t.Errorf("expected input to be custom, got %v", p.input)
}
})
})
})
t.Run("startup options", func(t *testing.T) {
exercise := func(t *testing.T, opt ProgramOption, fn func(*Program)) {
p := NewProgram(nil, opt)
fn(p)
}
t.Run("without catch panics", func(t *testing.T) {
exercise(t, WithoutCatchPanics(), func(p *Program) {
if !p.disableCatchPanics {
t.Errorf("expected catch panics to be disabled")
}
})
})
t.Run("without signal handler", func(t *testing.T) {
exercise(t, WithoutSignalHandler(), func(p *Program) {
if !p.disableSignalHandler {
t.Errorf("expected signal handler to be disabled")
}
})
})
})
}