You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fzf/src/reader_test.go

65 lines
1.3 KiB
Go

10 years ago
package fzf
import (
"testing"
"time"
"github.com/junegunn/fzf/src/util"
)
10 years ago
func TestReadFromCommand(t *testing.T) {
strs := []string{}
eb := util.NewEventBox()
exec := util.NewExecutor("")
reader := NewReader(
func(s []byte) bool { strs = append(strs, string(s)); return true },
eb, exec, false, true)
reader.startEventPoller()
10 years ago
// Check EventBox
9 years ago
if eb.Peek(EvtReadNew) {
9 years ago
t.Error("EvtReadNew should not be set yet")
10 years ago
}
// Normal command
3 months ago
reader.fin(reader.readFromCommand(`echo abc&&echo def`, nil))
10 years ago
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
t.Errorf("%s", strs)
}
// Check EventBox again
eb.WaitFor(EvtReadFin)
10 years ago
// Wait should return immediately
eb.Wait(func(events *util.Events) {
10 years ago
events.Clear()
})
// EventBox is cleared
9 years ago
if eb.Peek(EvtReadNew) {
9 years ago
t.Error("EvtReadNew should not be set yet")
10 years ago
}
// Make sure that event poller is finished
time.Sleep(readerPollIntervalMax)
// Restart event poller
reader.startEventPoller()
10 years ago
// Failing command
3 months ago
reader.fin(reader.readFromCommand(`no-such-command`, nil))
10 years ago
strs = []string{}
if len(strs) > 0 {
t.Errorf("%s", strs)
}
// Check EventBox again
9 years ago
if eb.Peek(EvtReadNew) {
t.Error("Command failed. EvtReadNew should not be set")
}
if !eb.Peek(EvtReadFin) {
t.Error("EvtReadFin should be set")
10 years ago
}
}