-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathawaitable_test.go
72 lines (64 loc) · 1.08 KB
/
awaitable_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
© 2023-present Harald Rudell <haraldrudell@proton.me> (https://haraldrudell.github.io/haraldrudell/)
All rights reserved
*/
package parl
import (
"testing"
)
func TestAwaitable(t *testing.T) {
var ch AwaitableCh
var isClosed, didClose bool
// Ch() Close() IsClosed()
var awaitable *Awaitable
var reset = func() {
awaitable = &Awaitable{}
}
// Ch is non-nil
reset()
ch = awaitable.Ch()
if ch == nil {
t.Error("Ch nil")
}
// Ch is open
var isOpen bool
select {
case <-ch:
isOpen = false
default:
isOpen = true
}
if !isOpen {
t.Error("Ch closed")
}
// IsClosed is false
isClosed = awaitable.IsClosed()
if isClosed {
t.Error("IsClosed true")
}
// Close works
didClose = awaitable.Close()
if !didClose {
t.Errorf("didClose false")
}
// Ch is closed
select {
case <-ch:
isOpen = false
default:
isOpen = true
}
if isOpen {
t.Error("Ch open")
}
// IsClosed is true
isClosed = awaitable.IsClosed()
if !isClosed {
t.Error("IsClosed false")
}
}
func TestZeroValue(t *testing.T) {
var awaitable Awaitable
awaitable.Close()
t.Log("OK")
}