-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
58 lines (45 loc) · 844 Bytes
/
event.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
package zc
import (
"fmt"
"slices"
"testing"
)
type Event interface {
Type() string
String() string
}
type Listener func(Event)
type StackEvent struct {
type_ string
stack []Item
}
func NewStackEvent(c Calc, type_ string) StackEvent {
return StackEvent{
type_: type_,
stack: slices.Clone(c.Stack()),
}
}
func (e StackEvent) Type() string {
return e.type_
}
func (e StackEvent) String() string {
return fmt.Sprintf("%4s: %v", e.type_, e.stack)
}
type OpEvent struct {
name string
}
func NewOpEvent(name string) OpEvent {
return OpEvent{name: name}
}
func (e OpEvent) Type() string { return "op" }
func (e OpEvent) String() string {
return fmt.Sprintf(" op: %v", e.name)
}
func TestLogger(t *testing.T) func(Event) {
return func(e Event) {
t.Log(e.String())
}
}
func ConsoleLogger(e Event) {
fmt.Println(e)
}