fzf/src/reader_test.go

57 lines
1.1 KiB
Go
Raw Normal View History

2015-01-01 19:49:30 +00:00
package fzf
2015-01-12 03:56:17 +00:00
import (
"testing"
"github.com/junegunn/fzf/src/util"
)
2015-01-01 19:49:30 +00:00
func TestReadFromCommand(t *testing.T) {
strs := []string{}
2015-01-12 03:56:17 +00:00
eb := util.NewEventBox()
2015-01-01 19:49:30 +00:00
reader := Reader{
pusher: func(s string) { strs = append(strs, s) },
eventBox: eb}
// Check EventBox
2015-02-17 10:28:10 +00:00
if eb.Peek(EvtReadNew) {
2015-01-11 18:01:24 +00:00
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-02-17 10:28:10 +00:00
if !eb.Peek(EvtReadNew) {
2015-01-11 18:01:24 +00:00
t.Error("EvtReadNew should be set yet")
2015-01-01 19:49:30 +00:00
}
// Wait should return immediately
2015-01-12 03:56:17 +00:00
eb.Wait(func(events *util.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-02-17 10:28:10 +00:00
if eb.Peek(EvtReadNew) {
2015-01-11 18:01:24 +00:00
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-02-17 10:28:10 +00:00
if eb.Peek(EvtReadNew) {
2015-01-11 18:01:24 +00:00
t.Error("Command failed. EvtReadNew should be set")
2015-01-01 19:49:30 +00:00
}
}