mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
refactor how we skip config reads in tests
This commit is contained in:
parent
c76990e3f0
commit
9d6d8a8531
|
|
@ -109,7 +109,7 @@ type Peco struct {
|
|||
singleKeyJumpPrefixMap map[rune]uint
|
||||
singleKeyJumpShowPrefix bool
|
||||
heightSpec *HeightSpec
|
||||
skipReadConfig bool
|
||||
readConfigFn func(*Config, string) error
|
||||
styles StyleSet
|
||||
enableANSI bool // Enable ANSI color code support
|
||||
use256Color bool
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func TestIssue345(t *testing.T) {
|
|||
defer os.Remove(cfg)
|
||||
|
||||
state := newPeco()
|
||||
state.skipReadConfig = false
|
||||
state.readConfigFn = readConfig
|
||||
if !assert.NoError(t, state.config.Init(), "Config.Init should succeed") {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ func TestGHIssue294_PromptStyleUsedForPromptPrefix(t *testing.T) {
|
|||
|
||||
state := New()
|
||||
state.screen = screen
|
||||
state.skipReadConfig = true
|
||||
|
||||
state.Filters().Add(filter.NewIgnoreCase())
|
||||
|
||||
prompt.Draw(state)
|
||||
|
|
@ -220,7 +220,6 @@ func TestGHIssue460_MatchedStyleDoesNotBleedToEndOfLine(t *testing.T) {
|
|||
|
||||
state := New()
|
||||
state.screen = screen
|
||||
state.skipReadConfig = true
|
||||
|
||||
mb := NewMemoryBuffer(0)
|
||||
raw := line.NewRaw(0, text, false, false)
|
||||
|
|
@ -301,7 +300,6 @@ func TestGHIssue455_DrawScreenForceSync(t *testing.T) {
|
|||
screen := NewDummyScreen()
|
||||
state := New()
|
||||
state.screen = screen
|
||||
state.skipReadConfig = true
|
||||
state.Filters().Add(filter.NewIgnoreCase())
|
||||
|
||||
mb := NewMemoryBuffer(0)
|
||||
|
|
@ -380,7 +378,6 @@ func TestNewLayout(t *testing.T) {
|
|||
makeState := func() *Peco {
|
||||
state := New()
|
||||
state.screen = NewDummyScreen()
|
||||
state.skipReadConfig = true
|
||||
state.Filters().Add(filter.NewIgnoreCase())
|
||||
return state
|
||||
}
|
||||
|
|
@ -424,7 +421,7 @@ func TestNewLayout(t *testing.T) {
|
|||
func TestTopDownQueryBottomLayout(t *testing.T) {
|
||||
state := New()
|
||||
state.screen = NewDummyScreen()
|
||||
state.skipReadConfig = true
|
||||
|
||||
state.Filters().Add(filter.NewIgnoreCase())
|
||||
|
||||
layout, err := NewTopDownQueryBottomLayout(state)
|
||||
|
|
|
|||
7
peco.go
7
peco.go
|
|
@ -118,6 +118,7 @@ func New() *Peco {
|
|||
idgen: newIDGen(),
|
||||
queryExecDelay: 50 * time.Millisecond,
|
||||
readyCh: make(chan struct{}),
|
||||
readConfigFn: readConfig,
|
||||
screen: NewTcellScreen(),
|
||||
selection: NewSelection(),
|
||||
maxScanBufferSize: bufio.MaxScanTokenSize,
|
||||
|
|
@ -328,10 +329,8 @@ func (p *Peco) Setup() (err error) {
|
|||
}
|
||||
|
||||
// Read config
|
||||
if !p.skipReadConfig { // This can only be set via test
|
||||
if err := readConfig(&p.config, opts.OptRcfile); err != nil {
|
||||
return fmt.Errorf("failed to setup configuration: %w", err)
|
||||
}
|
||||
if err := p.readConfigFn(&p.config, opts.OptRcfile); err != nil {
|
||||
return fmt.Errorf("failed to setup configuration: %w", err)
|
||||
}
|
||||
|
||||
// Take Args, Config, Options, and apply the configuration to
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ func newPeco() *Peco {
|
|||
state := New()
|
||||
state.Argv = []string{"peco", file}
|
||||
state.screen = NewDummyScreen()
|
||||
state.skipReadConfig = true
|
||||
state.readConfigFn = func(*Config, string) error { return nil }
|
||||
return state
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue