-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
expectation_sequencer.go
58 lines (51 loc) · 1.85 KB
/
expectation_sequencer.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 queryhistory
// ExpectationSequencer is a convenient way to compose ExpectationSequences.
type ExpectationSequencer interface {
ExpectationSequence
// Return the current SequencedExpectation.
Current() SequencedExpectation
// Eventually returns an ExpectationSequencerFn that can be used to compose
// this ExpectationSequencer with another.
//
// For example...
// sequencer1.Then(sequencer2.Eventually())
//
// Produces an ExpectationSequence that starts with sequence1, and is
// eventually followed by the head of sequence2.
Eventually() ExpectationSequencerFn
// Immediately returns an ExpectationSequencerFn that can be used to
// compose this ExpectationSequencer with another.
//
// For example...
// sequencer1.Then(sequencer2.Immediately())
//
// Produces an ExpectationSequence that starts with sequence1, and is
// immediately followed by the head of sequence2.
Immediately() ExpectationSequencerFn
// Then passes this ExpectationSequencer to ExpectationSequencerFn,
// and returns the resulting ExpectationSequencer.
Then(ExpectationSequencerFn) ExpectationSequencer
}
type ExpectationSequencerFn func(ExpectationSequencer) ExpectationSequencer
type expectationSequencer struct {
ExpectationSequence
current SequencedExpectation
}
func (es *expectationSequencer) Current() SequencedExpectation {
return es.current
}
func (es *expectationSequencer) Eventually() ExpectationSequencerFn {
return func(parent ExpectationSequencer) ExpectationSequencer {
es.Current().ExpectEventuallyAfter(parent.Current())
return es
}
}
func (es *expectationSequencer) Immediately() ExpectationSequencerFn {
return func(parent ExpectationSequencer) ExpectationSequencer {
es.Current().ExpectImmediatelyAfter(parent.Current())
return es
}
}
func (es *expectationSequencer) Then(then ExpectationSequencerFn) ExpectationSequencer {
return then(es)
}