Skip to content
Myr

eventbox_test.go

This file

Path

src/util/eventbox_test.go

60 lines · 899 bytes · Go

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 76efddd point at it.

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1–60why, one step back
1package util
23import "testing"45// fzf events6const (7 EvtReadNew EventType = iota8 EvtReadFin9 EvtSearchNew10 EvtSearchProgress11 EvtSearchFin12)1314func TestEventBox(t *testing.T) {15 eb := NewEventBox()1617 // Wait should return immediately18 ch := make(chan bool)1920 go func() {21 eb.Set(EvtReadNew, 10)22 ch <- true23 <-ch24 eb.Set(EvtSearchNew, 10)25 eb.Set(EvtSearchNew, 15)26 eb.Set(EvtSearchNew, 20)27 eb.Set(EvtSearchProgress, 30)28 ch <- true29 <-ch30 eb.Set(EvtSearchFin, 40)31 ch <- true32 <-ch33 }()3435 count := 036 sum := 037 looping := true38 for looping {39 <-ch40 eb.Wait(func(events *Events) {41 for _, value := range *events {42 switch val := value.(type) {43 case int:44 sum += val45 looping = sum < 10046 }47 }48 events.Clear()49 })50 ch <- true51 count++52 }5354 if count != 3 {55 t.Error("Invalid number of events", count)56 }57 if sum != 100 {58 t.Error("Invalid sum", sum)59 }60}