-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprotobuf-go-lite_test.go
87 lines (81 loc) · 1.49 KB
/
protobuf-go-lite_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
package protobuf_go_lite
import "testing"
type testCase struct {
val int
}
func (t *testCase) EqualVT(ot *testCase) bool {
if t == ot {
return true
}
if (ot == nil) != (t == nil) {
return false
}
if ot == nil {
return true
}
return t.val == ot.val
}
func TestCompareVT(t *testing.T) {
t1, t2 := &testCase{val: 1}, &testCase{val: 2}
cmp := CompareEqualVT[*testCase]()
if cmp(t1, t2) {
t.Fail()
}
if !cmp(t1, t1) {
t.Fail()
}
if !cmp(nil, nil) {
t.Fail()
}
if cmp(t1, nil) {
t.Fail()
}
}
func TestIsEqualVTSlice(t *testing.T) {
testCases := []struct {
s1, s2 []*testCase
expect bool
}{
{
s1: []*testCase{{val: 1}, {val: 2}},
s2: []*testCase{{val: 1}, {val: 2}},
expect: true,
},
{
s1: []*testCase{{val: 1}, {val: 2}},
s2: []*testCase{{val: 1}, {val: 3}},
expect: false,
},
{
s1: []*testCase{{val: 1}, {val: 2}},
s2: []*testCase{{val: 1}, {val: 2}, {val: 3}},
expect: false,
},
{
s1: []*testCase{{val: 1}, nil},
s2: []*testCase{{val: 1}, nil},
expect: true,
},
{
s1: []*testCase{{val: 1}, nil},
s2: []*testCase{{val: 1}, {val: 2}},
expect: false,
},
{
s1: []*testCase{},
s2: []*testCase{},
expect: true,
},
{
s1: nil,
s2: nil,
expect: true,
},
}
for _, tc := range testCases {
actual := IsEqualVTSlice(tc.s1, tc.s2)
if actual != tc.expect {
t.Errorf("IsEqualVTSlice(%v, %v) = %v; want %v", tc.s1, tc.s2, actual, tc.expect)
}
}
}