Skip to content

Commit 43574c8

Browse files
committed
test(equal): removed redundant tests covered by unified test cases
Signed-off-by: Frederic BIDON <[email protected]>
1 parent 39201bf commit 43574c8

File tree

2 files changed

+16
-205
lines changed

2 files changed

+16
-205
lines changed

internal/assertions/equal_impl_test.go

Lines changed: 0 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,21 @@
44
package assertions
55

66
import (
7-
"errors"
87
"fmt"
98
"iter"
109
"slices"
1110
"testing"
12-
"time"
1311
)
1412

1513
const shortpkg = "assertions"
1614

1715
func TestEqualUnexportedImplementationDetails(t *testing.T) {
1816
t.Parallel()
1917

20-
t.Run("samePointers", testSamePointers())
2118
t.Run("formatUnequalValue", testFormatUnequalValues())
22-
t.Run("isEmpty", testIsEmpty())
2319
t.Run("validateEqualArgs", testValidateEqualArgs())
2420
}
2521

26-
func testSamePointers() func(*testing.T) {
27-
return func(t *testing.T) {
28-
t.Parallel()
29-
30-
for tt := range equalSamePointersCases() {
31-
t.Run(tt.name, func(t *testing.T) {
32-
t.Parallel()
33-
34-
same, ok := samePointers(tt.args.first, tt.args.second)
35-
tt.same(t, same)
36-
tt.ok(t, ok)
37-
})
38-
}
39-
}
40-
}
41-
4222
func testFormatUnequalValues() func(*testing.T) {
4323
return func(t *testing.T) {
4424
t.Parallel()
@@ -55,131 +35,6 @@ func testFormatUnequalValues() func(*testing.T) {
5535
}
5636
}
5737

58-
func testIsEmpty() func(*testing.T) {
59-
return func(t *testing.T) {
60-
t.Parallel()
61-
62-
chWithValue := make(chan struct{}, 1)
63-
chWithValue <- struct{}{}
64-
65-
True(t, isEmpty(""))
66-
True(t, isEmpty(nil))
67-
True(t, isEmpty(error(nil)))
68-
True(t, isEmpty((*int)(nil)))
69-
True(t, isEmpty((*string)(nil)))
70-
True(t, isEmpty(new(string)))
71-
True(t, isEmpty([]string{}))
72-
True(t, isEmpty([]string(nil)))
73-
True(t, isEmpty([]byte(nil)))
74-
True(t, isEmpty([]byte{}))
75-
True(t, isEmpty([]byte("")))
76-
True(t, isEmpty([]bool(nil)))
77-
True(t, isEmpty([]bool{}))
78-
True(t, isEmpty([]any(nil)))
79-
True(t, isEmpty([]any{}))
80-
True(t, isEmpty(struct{}{}))
81-
True(t, isEmpty(&struct{}{}))
82-
True(t, isEmpty(struct{ A int }{A: 0}))
83-
True(t, isEmpty(struct{ a int }{a: 0}))
84-
True(t, isEmpty(struct {
85-
a int
86-
B int
87-
}{a: 0, B: 0}))
88-
True(t, isEmpty(0))
89-
True(t, isEmpty(int(0)))
90-
True(t, isEmpty(int8(0)))
91-
True(t, isEmpty(int16(0)))
92-
True(t, isEmpty(uint16(0)))
93-
True(t, isEmpty(int32(0)))
94-
True(t, isEmpty(uint32(0)))
95-
True(t, isEmpty(int64(0)))
96-
True(t, isEmpty(uint64(0)))
97-
True(t, isEmpty('\u0000')) // rune => int32
98-
True(t, isEmpty(float32(0)))
99-
True(t, isEmpty(float64(0)))
100-
True(t, isEmpty(0i)) // complex
101-
True(t, isEmpty(0.0i)) // complex
102-
True(t, isEmpty(false))
103-
True(t, isEmpty(new(bool)))
104-
True(t, isEmpty(map[string]string{}))
105-
True(t, isEmpty(map[string]string(nil)))
106-
True(t, isEmpty(new(time.Time)))
107-
True(t, isEmpty(time.Time{}))
108-
True(t, isEmpty(make(chan struct{})))
109-
True(t, isEmpty(chan struct{}(nil)))
110-
True(t, isEmpty(chan<- struct{}(nil)))
111-
True(t, isEmpty(make(chan struct{})))
112-
True(t, isEmpty(make(chan<- struct{})))
113-
True(t, isEmpty(make(chan struct{}, 1)))
114-
True(t, isEmpty(make(chan<- struct{}, 1)))
115-
True(t, isEmpty([1]int{0}))
116-
True(t, isEmpty([2]int{0, 0}))
117-
True(t, isEmpty([8]int{}))
118-
True(t, isEmpty([...]int{7: 0}))
119-
True(t, isEmpty([...]bool{false, false}))
120-
True(t, isEmpty(errors.New(""))) // BEWARE
121-
True(t, isEmpty([]error{}))
122-
True(t, isEmpty([]error(nil)))
123-
True(t, isEmpty(&[1]int{0}))
124-
True(t, isEmpty(&[2]int{0, 0}))
125-
False(t, isEmpty("something"))
126-
False(t, isEmpty(errors.New("something")))
127-
False(t, isEmpty([]string{"something"}))
128-
False(t, isEmpty(1))
129-
False(t, isEmpty(int(1)))
130-
False(t, isEmpty(uint(1)))
131-
False(t, isEmpty(byte(1)))
132-
False(t, isEmpty(int8(1)))
133-
False(t, isEmpty(uint8(1)))
134-
False(t, isEmpty(int16(1)))
135-
False(t, isEmpty(uint16(1)))
136-
False(t, isEmpty(int32(1)))
137-
False(t, isEmpty(uint32(1)))
138-
False(t, isEmpty(int64(1)))
139-
False(t, isEmpty(uint64(1)))
140-
False(t, isEmpty('A')) // rune => int32
141-
False(t, isEmpty(true))
142-
False(t, isEmpty(1.0))
143-
False(t, isEmpty(1i)) // complex
144-
False(t, isEmpty([]byte{0})) // elements values are ignored for slices
145-
False(t, isEmpty([]byte{0, 0})) // elements values are ignored for slices
146-
False(t, isEmpty([]string{""})) // elements values are ignored for slices
147-
False(t, isEmpty([]string{"a"})) // elements values are ignored for slices
148-
False(t, isEmpty([]bool{false})) // elements values are ignored for slices
149-
False(t, isEmpty([]bool{true})) // elements values are ignored for slices
150-
False(t, isEmpty([]error{errors.New("xxx")}))
151-
False(t, isEmpty([]error{nil})) // BEWARE
152-
False(t, isEmpty([]error{errors.New("")})) // BEWARE
153-
False(t, isEmpty(map[string]string{"Hello": "World"}))
154-
False(t, isEmpty(map[string]string{"": ""}))
155-
False(t, isEmpty(map[string]string{"foo": ""}))
156-
False(t, isEmpty(map[string]string{"": "foo"}))
157-
False(t, isEmpty(chWithValue))
158-
False(t, isEmpty([1]bool{true}))
159-
False(t, isEmpty([2]bool{false, true}))
160-
False(t, isEmpty([...]bool{10: true}))
161-
False(t, isEmpty([]int{0}))
162-
False(t, isEmpty([]int{42}))
163-
False(t, isEmpty([1]int{42}))
164-
False(t, isEmpty([2]int{0, 42}))
165-
False(t, isEmpty(&[1]int{42}))
166-
False(t, isEmpty(&[2]int{0, 42}))
167-
False(t, isEmpty([1]*int{new(int)})) // array elements must be the zero value, not any Empty value
168-
False(t, isEmpty(struct{ A int }{A: 42}))
169-
False(t, isEmpty(struct{ a int }{a: 42}))
170-
False(t, isEmpty(struct{ a *int }{a: new(int)})) // fields must be the zero value, not any Empty value
171-
False(t, isEmpty(struct{ a []int }{a: []int{}})) // fields must be the zero value, not any Empty value
172-
False(t, isEmpty(struct {
173-
a int
174-
B int
175-
}{a: 0, B: 42}))
176-
False(t, isEmpty(struct {
177-
a int
178-
B int
179-
}{a: 42, B: 0}))
180-
}
181-
}
182-
18338
func testValidateEqualArgs() func(*testing.T) {
18439
return func(t *testing.T) {
18540
t.Parallel()
@@ -230,63 +85,3 @@ func formatUnequalCases() iter.Seq[formatUnequalCase] {
23085
{uint64(123), uint64(124), `123`, `124`, "uint64 should print clean"},
23186
})
23287
}
233-
234-
type samePointersCase struct {
235-
name string
236-
args args
237-
same BoolAssertionFunc
238-
ok BoolAssertionFunc
239-
}
240-
241-
type args struct {
242-
first any
243-
second any
244-
}
245-
246-
func equalSamePointersCases() iter.Seq[samePointersCase] {
247-
p := ptr(2)
248-
return slices.Values([]samePointersCase{
249-
{
250-
name: "1 != 2",
251-
args: args{first: 1, second: 2},
252-
same: False,
253-
ok: False,
254-
},
255-
{
256-
name: "1 != 1 (not same ptr)",
257-
args: args{first: 1, second: 1},
258-
same: False,
259-
ok: False,
260-
},
261-
{
262-
name: "ptr(1) == ptr(1)",
263-
args: args{first: p, second: p},
264-
same: True,
265-
ok: True,
266-
},
267-
{
268-
name: "int(1) != float32(1)",
269-
args: args{first: int(1), second: float32(1)},
270-
same: False,
271-
ok: False,
272-
},
273-
{
274-
name: "array != slice",
275-
args: args{first: [2]int{1, 2}, second: []int{1, 2}},
276-
same: False,
277-
ok: False,
278-
},
279-
{
280-
name: "non-pointer vs pointer (1 != ptr(2))",
281-
args: args{first: 1, second: p},
282-
same: False,
283-
ok: False,
284-
},
285-
{
286-
name: "pointer vs non-pointer (ptr(2) != 1)",
287-
args: args{first: p, second: 1},
288-
same: False,
289-
ok: False,
290-
},
291-
})
292-
}

internal/assertions/equal_unary_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ func unifiedUnaryCases() iter.Seq[unaryTestCase] {
5151
xP := &x
5252
z := 0
5353
zP := &z
54+
var arr [1]int
5455

5556
type TString string
5657
type TStruct struct {
5758
x int
5859
}
60+
type FStruct struct {
61+
x func()
62+
}
5963

6064
return slices.Values([]unaryTestCase{
6165
// Nil category
@@ -74,9 +78,16 @@ func unifiedUnaryCases() iter.Seq[unaryTestCase] {
7478
{"empty/aliased-string", TString(""), emptyNonNil},
7579
{"empty/zero-array", [1]int{}, emptyNonNil},
7680
{"empty/zero-ptr", zP, emptyNonNil},
81+
{"empty/zero-struct-ptr", &TStruct{}, emptyNonNil},
82+
{"empty/zero-array-ptr", &arr, emptyNonNil},
83+
{"empty/rune", '\u0000', emptyNonNil},
84+
{"empty/complex", 0i, emptyNonNil},
85+
{"empty/error", errors.New(""), emptyNonNil},
86+
{"empty/struct-with-func", FStruct{x: nil}, emptyNonNil},
7787

7888
// Non-empty comparable category
7989
{"non-empty/int", 42, nonEmptyComparable},
90+
{"non-empty/rune", 'A', nonEmptyComparable},
8091
{"non-empty/string", "hello", nonEmptyComparable},
8192
{"non-empty/bool", true, nonEmptyComparable},
8293
{"non-empty/slice", []int{1}, nonEmptyComparable},
@@ -88,6 +99,11 @@ func unifiedUnaryCases() iter.Seq[unaryTestCase] {
8899

89100
// Non-empty non-comparable category
90101
{"non-empty/error", errors.New("something"), nonEmptyNonComparable},
102+
{"non-empty/slice-error", []error{errors.New("")}, nonEmptyNonComparable},
103+
{"non-empty/slice-nil-error", []error{nil}, nonEmptyNonComparable},
104+
{"non-empty/slice-zero", []int{0}, nonEmptyNonComparable},
105+
{"non-empty/slice-nil", []*int{nil}, nonEmptyNonComparable},
106+
{"non-empty/struct-with-func", FStruct{x: func() {}}, nonEmptyNonComparable},
91107
})
92108
}
93109

0 commit comments

Comments
 (0)