-
Notifications
You must be signed in to change notification settings - Fork 2
/
events_test.go
59 lines (44 loc) · 1.21 KB
/
events_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
package gommander
import "testing"
func TestListenerCreation(t *testing.T) {
em := newEmitter()
em.on(OutputHelp, func(ec *EventConfig) {}, 0)
em.on(OutputVersion, func(ec *EventConfig) {}, 0)
assert(t, len(em.listeners) == 2, "Failed to add listeners correctly")
}
func TestBeforeAllFn(t *testing.T) {
em := newEmitter()
em.insertBeforeAll(func(ec *EventConfig) {})
for _, v := range em.listeners {
assert(t, v[0].index == -5, "Failed to add before all listener")
}
}
func TestAfterAllFn(t *testing.T) {
em := newEmitter()
em.insertAfterAll(func(ec *EventConfig) {})
for _, v := range em.listeners {
assert(t, v[0].index == 5, "Failed to add after all listener")
}
}
func TestEmitterFunctionality(t *testing.T) {
em := newEmitter()
// Add some basic listeners
em.onErrors(func(ec *EventConfig) {})
for _, v := range em.listeners {
if v[0].index != -4 {
t.Error("Failed to add default listener")
}
}
}
func BenchmarkLstnrCreation(b *testing.B) {
for i := 0; i < b.N; i++ {
em := newEmitter()
em.on(OutputHelp, func(ec *EventConfig) {}, 0)
}
}
func BenchmarkBatchLstnrs(b *testing.B) {
for i := 0; i < b.N; i++ {
em := newEmitter()
em.insertBeforeAll(func(ec *EventConfig) {})
}
}