-
Notifications
You must be signed in to change notification settings - Fork 2
/
comparable_test.go
96 lines (88 loc) · 2.28 KB
/
comparable_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
package verify_test
import (
"testing"
"github.com/fluentassert/verify"
)
func TestObj(t *testing.T) {
type A struct {
Str string
Bool bool
}
t.Run("Equal", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
want := A{Str: "string", Bool: true}
got := A{Str: "string", Bool: true}
msg := verify.Obj(got).Equal(want)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
want := A{Str: "string", Bool: true}
got := A{Str: "wrong", Bool: true}
msg := verify.Obj(got).Equal(want)
assertFailed(t, msg, "the objects are not equal")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Obj(got).Equal(nil)
assertPassed(t, msg)
})
})
t.Run("NotEqual", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
want := A{Str: "string", Bool: true}
got := A{Str: "wrong", Bool: true}
msg := verify.Obj(got).NotEqual(want)
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
want := A{Str: "string", Bool: true}
got := A{Str: "string", Bool: true}
msg := verify.Obj(got).NotEqual(want)
assertFailed(t, msg, "the objects are equal")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Obj(got).NotEqual(nil)
assertFailed(t, msg, "the objects are equal")
})
})
t.Run("Zero", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
got := A{}
msg := verify.Obj(got).Zero()
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
got := A{Str: "wrong"}
msg := verify.Obj(got).Zero()
assertFailed(t, msg, "not a zero value\n")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Obj(got).Zero()
assertPassed(t, msg)
})
})
t.Run("NonZero", func(t *testing.T) {
t.Run("Passed", func(t *testing.T) {
got := A{Str: "string"}
msg := verify.Obj(got).NonZero()
assertPassed(t, msg)
})
t.Run("Failed", func(t *testing.T) {
got := A{}
msg := verify.Obj(got).NonZero()
assertFailed(t, msg, "a zero value")
})
t.Run("nil", func(t *testing.T) {
var got *A
msg := verify.Obj(got).NonZero()
assertFailed(t, msg, "a zero value")
})
})
t.Run("has assertions from Any", func(t *testing.T) {
want := A{}
got := verify.Obj(want).FluentAny.Got // type embedding done properly
assertEqual(t, got, want)
})
}