File: not_tobe_test.go

package info (click to toggle)
golang-github-gomagedon-expectate 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: makefile: 2
file content (129 lines) | stat: -rw-r--r-- 3,131 bytes parent folder | download
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package expectate_test

import (
	"testing"
	"time"

	"github.com/gomagedon/expectate"
)

var notToBeTests = []ExpectTest{
	{
		name:            "2 is 2",
		subject:         2,
		object:          2,
		expectedFailure: "2 is 2",
	},
	{
		name:            "2 is not 3",
		subject:         2,
		object:          3,
		expectedFailure: "",
	},
	{
		name:            "'foo' is 'foo'",
		subject:         "foo",
		object:          "foo",
		expectedFailure: "'foo' is 'foo'",
	},
	{
		name:            "'foo' is not 'bar'",
		subject:         "foo",
		object:          "bar",
		expectedFailure: "",
	},
	{
		name:            "0 is 0",
		subject:         0,
		object:          0,
		expectedFailure: "0 is 0",
	},
	{
		name:            "0 is not ''",
		subject:         0,
		object:          "",
		expectedFailure: "",
	},
	{
		name:            "0 is not nil",
		subject:         0,
		object:          nil,
		expectedFailure: "",
	},
	{
		name:            "pointer to struct is itself",
		subject:         samplePointerToPerson,
		object:          samplePointerToPerson,
		expectedFailure: "&{John Doe 30 Electrician 1990-01-01 00:00:00 +0000 UTC} is &{John Doe 30 Electrician 1990-01-01 00:00:00 +0000 UTC}",
	},
	{
		name:            "pointer to struct is not copy of struct",
		subject:         samplePointerToPerson,
		object:          *samplePointerToPerson,
		expectedFailure: "",
	},
	{
		name: "pointer to struct is not pointer to copy of struct",
		subject: &Person{
			Name:     "Philip Fry",
			Age:      25,
			Job:      "Delivery Boy",
			Birthday: time.Date(1980, time.July, 7, 0, 0, 0, 0, time.UTC),
		},
		object: &Person{
			Name:     "Philip Fry",
			Age:      25,
			Job:      "Delivery Boy",
			Birthday: time.Date(1980, time.July, 7, 0, 0, 0, 0, time.UTC),
		},
		expectedFailure: "",
	},
	{
		name: "struct is copy of struct",
		subject: Person{
			Name:     "Hermes Conrad",
			Age:      38,
			Job:      "Beaurocrat",
			Birthday: time.Date(2967, time.August, 8, 0, 0, 0, 0, time.UTC),
		},
		object: Person{
			Name:     "Hermes Conrad",
			Age:      38,
			Job:      "Beaurocrat",
			Birthday: time.Date(2967, time.August, 8, 0, 0, 0, 0, time.UTC),
		},
		expectedFailure: "{Hermes Conrad 38 Beaurocrat 2967-08-08 00:00:00 +0000 UTC} is {Hermes Conrad 38 Beaurocrat 2967-08-08 00:00:00 +0000 UTC}",
	},
	{
		name: "struct is not struct with different values",
		subject: Person{
			Name:     "John Doe",
			Age:      30,
			Job:      "Electrician",
			Birthday: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
		},
		object: Person{
			Name:     "John Smith",
			Age:      30,
			Job:      "Electrician",
			Birthday: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
		},
		expectedFailure: "",
	},
}

func TestNotToBe(t *testing.T) {
	for _, test := range notToBeTests {
		t.Run(test.name, func(t *testing.T) {
			mockTestingT := new(MockTestingT)
			expect := expectate.Expect(mockTestingT)

			expect(test.subject).NotToBe(test.object)

			if mockTestingT.FataledWith != test.expectedFailure {
				t.Fatal("Expected:", test.expectedFailure,
					"\nGot:", mockTestingT.FataledWith)
			}
		})
	}
}