-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
sequenced_expectation.go
102 lines (90 loc) · 3.73 KB
/
sequenced_expectation.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
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
package queryhistory
// SequencedExpectation is an Expectation situated in an ExpectationSequence.
// In other words, it is an Expectation with temporal relationships to other
// Expectations.
type SequencedExpectation interface {
Expectation
// EventuallyAfter returns the SequencedExpectationSet containing
// SequencedExpectations which this SequencedExpectation eventually
// follows.
EventuallyAfter() SequencedExpectationSet
// EventuallyBefore returns the SequencedExpectationSet contains
// SequencedExpectations eventually follow this SequencedExpectation.
EventuallyBefore() SequencedExpectationSet
// ExpectImmediatelyAfter sets the SequencedExpectation which this
// SequencedExpectation immediately follows. It also sets the inverse
// relationship on the provided expectation.
ExpectImmediatelyAfter(SequencedExpectation)
// ExpectImmediatelyBefore sets the SequencedExpectation which immediately
// follow this SequencedExpectation. It also sets the inverse relationship
// on the provided expectation.
ExpectImmediatelyBefore(SequencedExpectation)
// ExpectEventuallyAfter adds a SequencedExpectation to the
// SequencedExpectationSet which this SequencedExpectation eventually
// follows. It also sets the inverse relationship on the provided
// expectation.
ExpectEventuallyAfter(SequencedExpectation)
// ExpectEventuallyAfter adds a SequencedExpectation to the
// SequencedExpectationSet which eventually follows this
// SequencedExpectation. It also sets the inverse relationship on the
// provided expectation.
ExpectEventuallyBefore(SequencedExpectation)
// ImmediatelyAfter returns the SequencedExpectation which this
// SequencedExpectation immediately follows.
ImmediatelyAfter() SequencedExpectation
// ImmediatelyBefore returns the SequencedExpectation which immediately
// follows this SequencedExpectation.
ImmediatelyBefore() SequencedExpectation
}
type sequencedExpectation struct {
Expectation
eventuallyAfter SequencedExpectationSet
eventuallyBefore SequencedExpectationSet
immediatelyAfter SequencedExpectation
immediatelyBefore SequencedExpectation
}
func newSequencedExpectation(expectation Expectation) SequencedExpectation {
eventuallyAfter := sequencedExpectationSet(make(map[SequencedExpectation]any))
eventuallyBefore := sequencedExpectationSet(make(map[SequencedExpectation]any))
return &sequencedExpectation{
Expectation: expectation,
eventuallyAfter: &eventuallyAfter,
eventuallyBefore: &eventuallyBefore,
}
}
func (se *sequencedExpectation) EventuallyAfter() SequencedExpectationSet {
return se.eventuallyAfter
}
func (se *sequencedExpectation) EventuallyBefore() SequencedExpectationSet {
return se.eventuallyBefore
}
func (se *sequencedExpectation) ExpectEventuallyAfter(expectation SequencedExpectation) {
if !se.eventuallyAfter.Contains(expectation) {
se.eventuallyAfter.Add(expectation)
expectation.ExpectEventuallyBefore(se)
}
}
func (se *sequencedExpectation) ExpectEventuallyBefore(expectation SequencedExpectation) {
if !se.eventuallyBefore.Contains(expectation) {
se.eventuallyBefore.Add(expectation)
expectation.ExpectEventuallyAfter(se)
}
}
func (se *sequencedExpectation) ExpectImmediatelyAfter(expectation SequencedExpectation) {
if se.immediatelyAfter != expectation {
se.immediatelyAfter = expectation
expectation.ExpectImmediatelyBefore(se)
}
}
func (se *sequencedExpectation) ExpectImmediatelyBefore(expectation SequencedExpectation) {
if se.immediatelyBefore != expectation {
se.immediatelyBefore = expectation
expectation.ExpectImmediatelyAfter(se)
}
}
func (se *sequencedExpectation) ImmediatelyAfter() SequencedExpectation {
return se.immediatelyAfter
}
func (se *sequencedExpectation) ImmediatelyBefore() SequencedExpectation {
return se.immediatelyBefore
}