mirror of https://github.com/mum4k/termdash.git
The event queue can now report if it is empty.
This commit is contained in:
parent
fd186956f6
commit
0e620cf3ca
|
@ -75,6 +75,13 @@ func (u *Unbound) wake() {
|
|||
}
|
||||
}
|
||||
|
||||
// Empty determines if the queue is empty.
|
||||
func (u *Unbound) Empty() bool {
|
||||
u.mu.Lock()
|
||||
defer u.mu.Unlock()
|
||||
return u.empty()
|
||||
}
|
||||
|
||||
// empty determines if the queue is empty.
|
||||
func (u *Unbound) empty() bool {
|
||||
return u.first == nil
|
||||
|
|
|
@ -25,12 +25,14 @@ import (
|
|||
|
||||
func TestQueue(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
pushes []terminalapi.Event
|
||||
wantPops []terminalapi.Event
|
||||
desc string
|
||||
pushes []terminalapi.Event
|
||||
wantEmpty bool // Checked after pushes and before pops.
|
||||
wantPops []terminalapi.Event
|
||||
}{
|
||||
{
|
||||
desc: "empty queue returns nil",
|
||||
desc: "empty queue returns nil",
|
||||
wantEmpty: true,
|
||||
wantPops: []terminalapi.Event{
|
||||
nil,
|
||||
},
|
||||
|
@ -42,6 +44,7 @@ func TestQueue(t *testing.T) {
|
|||
terminalapi.NewError("error2"),
|
||||
terminalapi.NewError("error3"),
|
||||
},
|
||||
wantEmpty: false,
|
||||
wantPops: []terminalapi.Event{
|
||||
terminalapi.NewError("error1"),
|
||||
terminalapi.NewError("error2"),
|
||||
|
@ -59,6 +62,11 @@ func TestQueue(t *testing.T) {
|
|||
q.Push(ev)
|
||||
}
|
||||
|
||||
gotEmpty := q.Empty()
|
||||
if gotEmpty != tc.wantEmpty {
|
||||
t.Errorf("Empty => got %v, want %v", gotEmpty, tc.wantEmpty)
|
||||
}
|
||||
|
||||
for i, want := range tc.wantPops {
|
||||
got := q.Pop()
|
||||
if diff := pretty.Compare(want, got); diff != "" {
|
||||
|
|
Loading…
Reference in New Issue