File: custom_test.go

package info (click to toggle)
golang-github-powerman-deepequal 0.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download | duplicates (2)
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
package deepequal_test

import (
	"testing"
	"time"

	"github.com/powerman/deepequal"
)

type Time time.Time

func (Time) Equal(time.Time) bool { return true } // Invalid signature.

func TestDeepEqualEqual(t *testing.T) {
	t.Parallel()

	type T struct {
		t1 time.Time
		t2 *time.Time
	}
	var (
		zero     time.Time
		now      = time.Now().In(time.FixedZone("test", 3600))
		now2     = now.UTC()
		nowTime  = Time(now)
		now2Time = Time(now2)
	)

	tests := []struct {
		a, b interface{}
		want bool
	}{
		{now, now, true},
		{now, zero, false},
		{&now, now, false},
		{&now, &now, true},
		{now, now2, true},
		{&now, &now2, true},
		{T{now, &now}, T{now2, &now2}, true},
		{T{now, &now}, T{now2, &zero}, false},
		{nowTime, now, false},
		{nowTime, nowTime, true},
		{nowTime, now2Time, false},
	}
	for _, tc := range tests {
		tc := tc
		t.Run("", func(t *testing.T) {
			if res := deepequal.DeepEqual(tc.a, tc.b); res != tc.want {
				t.Errorf("DeepEqual(%v, %v) = %v, want %v", tc.a, tc.b, res, tc.want)
			}
		})
	}
}