-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarker_test.go
More file actions
104 lines (96 loc) · 2.28 KB
/
marker_test.go
File metadata and controls
104 lines (96 loc) · 2.28 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package xterm
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMarkerNew(t *testing.T) {
t.Parallel()
type Expectation struct {
Line int
IsDisposed bool
HasID bool
}
m := NewMarker(5)
got := Expectation{
Line: m.Line,
IsDisposed: m.IsDisposed,
HasID: m.ID() > 0,
}
expected := Expectation{Line: 5, IsDisposed: false, HasID: true}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}
func TestMarkerUniqueIDs(t *testing.T) {
t.Parallel()
type Expectation struct {
Different bool
}
m1 := NewMarker(0)
m2 := NewMarker(0)
got := Expectation{Different: m1.ID() != m2.ID()}
expected := Expectation{Different: true}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}
func TestMarkerDispose(t *testing.T) {
t.Parallel()
type Expectation struct {
IsDisposed bool
Line int
}
m := NewMarker(10)
m.Dispose()
got := Expectation{IsDisposed: m.IsDisposed, Line: m.Line}
expected := Expectation{IsDisposed: true, Line: -1}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}
func TestMarkerDisposeIdempotent(t *testing.T) {
t.Parallel()
type Expectation struct {
FireCount int
}
m := NewMarker(10)
fireCount := 0
m.OnDispose(func(struct{}) { fireCount++ })
m.Dispose()
m.Dispose() // second call should be no-op
got := Expectation{FireCount: fireCount}
expected := Expectation{FireCount: 1}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}
func TestMarkerOnDispose(t *testing.T) {
t.Parallel()
type Expectation struct {
Called bool
}
m := NewMarker(3)
called := false
m.OnDispose(func(struct{}) { called = true })
m.Dispose()
got := Expectation{Called: called}
expected := Expectation{Called: true}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}
func TestMarkerRegister(t *testing.T) {
t.Parallel()
type Expectation struct {
Disposed bool
}
m := NewMarker(0)
disposed := false
m.Register(toDisposable(func() { disposed = true }))
m.Dispose()
got := Expectation{Disposed: disposed}
expected := Expectation{Disposed: true}
if diff := cmp.Diff(expected, got); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
}