mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-17 02:25:14 +00:00
88d74a15aa
Most of the "expected" strings in terminal.go test were changed to "text/template" values. Quotes in those string were parametrized in the templates. Two functions handling templates were added for convenience. Templates has the advantage of: - parametrize repetitive strings inside "expected" values - inner and outer quotes were parametrized in templates - long and confusing test values are more readable - templates can be localized for other operating systems
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package fzf
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/junegunn/fzf/src/util"
|
|
)
|
|
|
|
func TestReadFromCommand(t *testing.T) {
|
|
strs := []string{}
|
|
eb := util.NewEventBox()
|
|
reader := NewReader(
|
|
func(s []byte) bool { strs = append(strs, string(s)); return true },
|
|
eb, false, true)
|
|
|
|
reader.startEventPoller()
|
|
|
|
// Check EventBox
|
|
if eb.Peek(EvtReadNew) {
|
|
t.Error("EvtReadNew should not be set yet")
|
|
}
|
|
|
|
// Normal command
|
|
reader.fin(reader.readFromCommand(nil, `echo abc&&echo def`))
|
|
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
|
|
t.Errorf("%s", strs)
|
|
}
|
|
|
|
// Check EventBox again
|
|
eb.WaitFor(EvtReadFin)
|
|
|
|
// Wait should return immediately
|
|
eb.Wait(func(events *util.Events) {
|
|
events.Clear()
|
|
})
|
|
|
|
// EventBox is cleared
|
|
if eb.Peek(EvtReadNew) {
|
|
t.Error("EvtReadNew should not be set yet")
|
|
}
|
|
|
|
// Make sure that event poller is finished
|
|
time.Sleep(readerPollIntervalMax)
|
|
|
|
// Restart event poller
|
|
reader.startEventPoller()
|
|
|
|
// Failing command
|
|
reader.fin(reader.readFromCommand(nil, `no-such-command`))
|
|
strs = []string{}
|
|
if len(strs) > 0 {
|
|
t.Errorf("%s", strs)
|
|
}
|
|
|
|
// Check EventBox again
|
|
if eb.Peek(EvtReadNew) {
|
|
t.Error("Command failed. EvtReadNew should not be set")
|
|
}
|
|
if !eb.Peek(EvtReadFin) {
|
|
t.Error("EvtReadFin should be set")
|
|
}
|
|
}
|