-
Notifications
You must be signed in to change notification settings - Fork 2
/
any_test.go
106 lines (98 loc) · 2.65 KB
/
any_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package verify_test
import (
"testing"
"github.com/fluentassert/verify"
)
func TestAny(t *testing.T) {
type A struct {
Str string
Bool bool
Slice []int
}
t.Run("DeepEqual", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
want := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
got := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
msg := verify.Any(got).DeepEqual(want)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
want := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
got := A{Str: "wrong", Bool: true, Slice: []int{1, 3}}
msg := verify.Any(got).DeepEqual(want)
assertFailed(t, msg, "mismatch (-want +got):\n")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Any(got).DeepEqual(nil)
assertPassed(t, msg)
})
})
t.Run("NotDeepEqual", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
want := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
got := A{Str: "wrong", Bool: true, Slice: []int{1, 3}}
msg := verify.Any(got).NotDeepEqual(want)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
want := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
got := A{Str: "string", Bool: true, Slice: []int{1, 2, 3}}
msg := verify.Any(got).NotDeepEqual(want)
assertFailed(t, msg, "the objects are equal")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Any(got).NotDeepEqual(nil)
assertFailed(t, msg, "the objects are equal")
})
})
t.Run("Check", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
fn := func(A) verify.FailureMessage {
return ""
}
msg := verify.Any(A{}).Check(fn)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
fn := func(A) verify.FailureMessage {
return "failure"
}
msg := verify.Any(A{}).Check(fn)
assertFailed(t, msg, "failure")
})
})
t.Run("Should", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
pred := func(A) bool {
return true
}
msg := verify.Any(A{}).Should(pred)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
pred := func(A) bool {
return false
}
msg := verify.Any(A{}).Should(pred)
assertFailed(t, msg, "object does not meet the predicate criteria")
})
})
t.Run("ShouldNot", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
pred := func(A) bool {
return false
}
msg := verify.Any(A{}).ShouldNot(pred)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
pred := func(A) bool {
return true
}
msg := verify.Any(A{}).ShouldNot(pred)
assertFailed(t, msg, "object meets the predicate criteria")
})
})
}