-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues_test.go
70 lines (56 loc) · 1.78 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
package peco
import (
"io"
"io/ioutil"
"os"
"testing"
"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 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
}
}