generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirst_test.go
85 lines (70 loc) · 2.22 KB
/
first_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
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
package linger_test
import (
"time"
. "github.com/dogmatiq/linger"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("func First()", func() {
It("returns the first value that matches the predicate", func() {
v, ok := First(Positive, 0*time.Second, -1*time.Second, 1*time.Second, 2*time.Second)
Expect(ok).To(BeTrue())
Expect(v).To(Equal(1 * time.Second))
})
It("returns false if no values match", func() {
_, ok := First(Positive, 0*time.Second, -1*time.Second)
Expect(ok).To(BeFalse())
})
})
var _ = Describe("func MustFirst()", func() {
It("returns the first value that matches the predicate", func() {
v := MustFirst(Positive, 0*time.Second, -1*time.Second, 1*time.Second, 2*time.Second)
Expect(v).To(Equal(1 * time.Second))
})
It("panics if no values match", func() {
Expect(func() {
MustFirst(Positive, 0*time.Second, -1*time.Second)
}).To(Panic())
})
})
var _ = Describe("func FirstT()", func() {
epoch := time.Unix(0, 0)
now := time.Now()
It("returns the first value that matches the predicate", func() {
v, ok := FirstT(NonZeroT, time.Time{}, epoch, now)
Expect(ok).To(BeTrue())
Expect(v).To(BeTemporally("==", epoch))
})
It("returns false if no values match", func() {
_, ok := FirstT(NonZeroT, time.Time{})
Expect(ok).To(BeFalse())
})
})
var _ = Describe("func MustFirstT()", func() {
epoch := time.Unix(0, 0)
now := time.Now()
It("returns the first value that matches the predicate", func() {
v := MustFirstT(NonZeroT, time.Time{}, epoch, now)
Expect(v).To(BeTemporally("==", epoch))
})
It("panics if no values match", func() {
Expect(func() {
MustFirstT(NonZeroT, time.Time{})
}).To(Panic())
})
})
var _ = Describe("func Defaulter()", func() {
It("returns the first value that matches the predicate", func() {
v := Defaulter(Positive, -1*time.Second, 1*time.Second)(0 * time.Second)
Expect(v).To(Equal(1 * time.Second))
})
It("returns the input value if it matches the predicate", func() {
v := Defaulter(Positive, -1*time.Second, 1*time.Second)(5 * time.Second)
Expect(v).To(Equal(5 * time.Second))
})
It("panics if no values match", func() {
Expect(func() {
Defaulter(Positive, -1*time.Second)(0 * time.Second)
}).To(Panic())
})
})