mirror of https://github.com/junegunn/fzf
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.
61 lines
899 B
Go
61 lines
899 B
Go
10 years ago
|
package util
|
||
10 years ago
|
|
||
|
import "testing"
|
||
|
|
||
10 years ago
|
// fzf events
|
||
|
const (
|
||
|
EvtReadNew EventType = iota
|
||
|
EvtReadFin
|
||
|
EvtSearchNew
|
||
|
EvtSearchProgress
|
||
|
EvtSearchFin
|
||
|
)
|
||
|
|
||
10 years ago
|
func TestEventBox(t *testing.T) {
|
||
|
eb := NewEventBox()
|
||
|
|
||
|
// Wait should return immediately
|
||
|
ch := make(chan bool)
|
||
|
|
||
|
go func() {
|
||
10 years ago
|
eb.Set(EvtReadNew, 10)
|
||
10 years ago
|
ch <- true
|
||
|
<-ch
|
||
10 years ago
|
eb.Set(EvtSearchNew, 10)
|
||
|
eb.Set(EvtSearchNew, 15)
|
||
|
eb.Set(EvtSearchNew, 20)
|
||
|
eb.Set(EvtSearchProgress, 30)
|
||
10 years ago
|
ch <- true
|
||
|
<-ch
|
||
10 years ago
|
eb.Set(EvtSearchFin, 40)
|
||
10 years ago
|
ch <- true
|
||
|
<-ch
|
||
|
}()
|
||
|
|
||
|
count := 0
|
||
|
sum := 0
|
||
|
looping := true
|
||
|
for looping {
|
||
|
<-ch
|
||
|
eb.Wait(func(events *Events) {
|
||
|
for _, value := range *events {
|
||
|
switch val := value.(type) {
|
||
|
case int:
|
||
|
sum += val
|
||
|
looping = sum < 100
|
||
|
}
|
||
|
}
|
||
|
events.Clear()
|
||
|
})
|
||
|
ch <- true
|
||
10 years ago
|
count++
|
||
10 years ago
|
}
|
||
|
|
||
|
if count != 3 {
|
||
|
t.Error("Invalid number of events", count)
|
||
|
}
|
||
|
if sum != 100 {
|
||
|
t.Error("Invalid sum", sum)
|
||
|
}
|
||
|
}
|