-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues_test.go
115 lines (93 loc) · 2.67 KB
/
issues_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package peco
import (
"io"
"io/ioutil"
"os"
"testing"
"time"
termbox "github.com/nsf/termbox-go"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestIssue212_SanityCheck(t *testing.T) {
state := newPeco()
ctx, cancel := context.WithCancel(context.Background())
go state.Run(ctx)
defer cancel()
<-state.Ready()
// Check if the default layout type is honored */
// This the main issue on 212, but while we're at it, we're just
// going to check that all the default values are as expected
if !assert.Equal(t, state.config.Layout, "top-down", "Default layout type should be 'top-down', got '%s'", state.config.Layout) {
return
}
if !assert.Equal(t, len(state.config.Keymap), 0, "Default keymap should be empty, but got '%#v'", state.config.Keymap) {
return
}
if !assert.Equal(t, state.config.InitialMatcher, IgnoreCaseMatch, "Default matcher should be IgnoreCaseMatch, but got '%s'", state.config.InitialMatcher) {
return
}
defstyle := StyleSet{}
defstyle.Init()
if !assert.Equal(t, state.config.Style, defstyle, "should be default style") {
return
}
if !assert.Equal(t, state.config.Prompt, "QUERY>", "Default prompt should be 'QUERY>', but got '%s'", state.config.Prompt) {
return
}
// Okay, this time create a dummy config file, and read that in
f, err := ioutil.TempFile("", "peco-test-config")
if !assert.NoError(t, err, "Failed to create temporary config file: %s", err) {
return
}
fn := f.Name()
defer os.Remove(fn)
io.WriteString(f, `{
"Layout": "bottom-up"
}`)
f.Close()
state = newPeco()
go state.Run(ctx)
<-state.Ready()
if !assert.NoError(t, state.config.ReadFilename(fn), "Failed to read config: %s", err) {
return
}
if !assert.Equal(t, state.config.Layout, "bottom-up", "Default layout type should be 'bottom-up', got '%s'", state.config.Layout) {
return
}
}
func TestIssue345(t *testing.T) {
cfg, err := newConfig(`{
"Keymap": {
"C-t": "my.ToggleSelectionInAboveLine"
},
"Action": {
"my.ToggleSelectionInAboveLine": [
"peco.SelectUp",
"peco.ToggleSelectionAndSelectNext"
]
}
}`)
if !assert.NoError(t, err, "newConfig should succeed") {
return
}
defer os.Remove(cfg)
state := newPeco()
state.skipReadConfig = false
if !assert.NoError(t, state.config.Init(), "Config.Init should succeed") {
return
}
state.Argv = append(state.Argv, []string{"--rcfile", cfg}...)
ctx, cancel := context.WithCancel(context.Background())
go state.Run(ctx)
defer cancel()
<-state.Ready()
ev := termbox.Event{
Type: termbox.EventKey,
Key: termbox.KeyCtrlT,
}
if !assert.NoError(t, state.Keymap().ExecuteAction(ctx, state, ev), "ExecuteAction should succeed") {
return
}
time.Sleep(time.Second)
}