fzf/src/reader_test.go

53 lines
1.0 KiB
Go
Raw Normal View History

2015-01-01 19:49:30 +00:00
package fzf
import "testing"
func TestReadFromCommand(t *testing.T) {
strs := []string{}
eb := NewEventBox()
reader := Reader{
pusher: func(s string) { strs = append(strs, s) },
eventBox: eb}
// Check EventBox
2015-01-11 18:01:24 +00:00
if eb.Peak(EvtReadNew) {
t.Error("EvtReadNew should not be set yet")
2015-01-01 19:49:30 +00:00
}
// Normal command
reader.readFromCommand(`echo abc && echo def`)
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
t.Errorf("%s", strs)
}
// Check EventBox again
2015-01-11 18:01:24 +00:00
if !eb.Peak(EvtReadNew) {
t.Error("EvtReadNew should be set yet")
2015-01-01 19:49:30 +00:00
}
// Wait should return immediately
eb.Wait(func(events *Events) {
2015-01-11 18:01:24 +00:00
if _, found := (*events)[EvtReadNew]; !found {
2015-01-01 19:49:30 +00:00
t.Errorf("%s", events)
}
events.Clear()
})
// EventBox is cleared
2015-01-11 18:01:24 +00:00
if eb.Peak(EvtReadNew) {
t.Error("EvtReadNew should not be set yet")
2015-01-01 19:49:30 +00:00
}
// Failing command
reader.readFromCommand(`no-such-command`)
strs = []string{}
if len(strs) > 0 {
t.Errorf("%s", strs)
}
// Check EventBox again
2015-01-11 18:01:24 +00:00
if eb.Peak(EvtReadNew) {
t.Error("Command failed. EvtReadNew should be set")
2015-01-01 19:49:30 +00:00
}
}