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 } }