Debian Codegraph @

custom_test.go

raw symbols SCIP
1 package deepequal_test
2
3 import (
4 "testing"
5 "time"
6 "unsafe"
7
8 "github.com/powerman/deepequal"
9 )
10
11 type Time time.Time
12
13 func (Time) Equal(time.Time) bool { return true } // Invalid signature.
14
15 //go:notinheap
16 type NotInHeap struct{}
17
18 var xy [2]int
19
20 func TestDeepEqualEqual(t *testing.T) {
21 t.Parallel()
22
23 type T struct {
24 t1 time.Time
25 t2 *time.Time
26 }
27 var (
28 zero time.Time
29 now = time.Now().In(time.FixedZone("test", 3600))
30 now2 = now.UTC()
31 nowTime = Time(now)
32 now2Time = Time(now2)
33 x = (*NotInHeap)(unsafe.Pointer(&xy[0]))
34 y = (*NotInHeap)(unsafe.Pointer(&xy[1]))
35 )
36
37 tests := []struct {
38 a, b any
39 want bool
40 }{
41 {now, now, true},
42 {now, zero, false},
43 {&now, now, false},
44 {&now, &now, true},
45 {now, now2, true},
46 {&now, &now2, true},
47 {T{now, &now}, T{now2, &now2}, true},
48 {T{now, &now}, T{now2, &zero}, false},
49 {nowTime, now, false},
50 {nowTime, nowTime, true},
51 {nowTime, now2Time, false},
52 {x, y, true}, // https://github.com/golang/go/issues/42076
53 }
54 for _, tc := range tests {
55 t.Run("", func(t *testing.T) {
56 t.Parallel()
57
58 if res := deepequal.DeepEqual(tc.a, tc.b); res != tc.want {
59 t.Errorf("DeepEqual(%v, %v) = %v, want %v", tc.a, tc.b, res, tc.want)
60 }
61 })
62 }
63 }