-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice_test.go
More file actions
83 lines (72 loc) · 2.81 KB
/
slice_test.go
File metadata and controls
83 lines (72 loc) · 2.81 KB
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
package assert
import (
"testing"
)
func TestElementContainsAndNotContains(t *testing.T) {
a := New(t)
mockA := New(new(testing.T))
testElementContainsAndNotContains(a, mockA, []int{1}, 1, true)
testElementContainsAndNotContains(a, mockA, []int{1, 2, 3}, 3, true)
testElementContainsAndNotContains(a, mockA, []int{1, 2, 3}, 4, false)
testElementContainsAndNotContains(a, mockA, []int{}, 1, false)
testElementContainsAndNotContains(a, mockA, [1]int{1}, 1, true)
testElementContainsAndNotContains(a, mockA, [3]int{1, 2, 3}, 3, true)
testElementContainsAndNotContains(a, mockA, [3]int{1, 2, 3}, 4, false)
testElementContainsAndNotContains(a, mockA, [0]int{}, 1, false)
}
func testElementContainsAndNotContains(
a, mockA *Assertion,
source, expect any,
isContains bool,
) {
a.T.Helper()
// ContainsElement
testAssertionFunction(a, "ContainsElement", func() error {
return ContainsElement(mockA.T, source, expect)
}, isContains)
testAssertionFunction(a, "Assertion.ContainsElement", func() error {
return mockA.ContainsElement(source, expect)
}, isContains)
// NotContainsElement
testAssertionFunction(a, "NotContainsElement", func() error {
return NotContainsElement(mockA.T, source, expect)
}, !isContains)
testAssertionFunction(a, "Assertion.NotContainsElement", func() error {
return mockA.NotContainsElement(source, expect)
}, !isContains)
// ContainsElementNow
testAssertionNowFunction(a, "ContainsElementNow", func() {
ContainsElementNow(mockA.T, source, expect)
}, !isContains)
testAssertionNowFunction(a, "Assertion.ContainsElementNow", func() {
mockA.ContainsElementNow(source, expect)
}, !isContains)
// NotContainsElementNow
testAssertionNowFunction(a, "NotContainsElementNow", func() {
NotContainsElementNow(mockA.T, source, expect)
}, isContains)
testAssertionNowFunction(a, "Assertion.NotContainsElementNow", func() {
mockA.NotContainsElementNow(source, expect)
}, isContains)
}
func TestIsContainsElement(t *testing.T) {
assert := New(t)
assert.PanicNow(func() {
isContainsElement("not array or slice", 1)
})
assert.PanicNow(func() {
isContainsElement([]string{"a", "b", "c"}, 1)
})
assert.NotTrueNow(isContainsElement([]string{}, "c"))
assert.TrueNow(isContainsElement([]string{"a", "b", "c"}, "c"))
assert.NotTrueNow(isContainsElement([]string{"a", "b", "c"}, "d"))
assert.TrueNow(isContainsElement([]int{1, 2, 3}, 3))
assert.NotTrueNow(isContainsElement([]int{1, 2, 3}, 4))
assert.TrueNow(isContainsElement([]int64{1, 2, 3}, 3))
assert.NotTrueNow(isContainsElement([]int64{1, 2, 3}, 4))
assert.TrueNow(isContainsElement([]uint64{1, 2, 3}, uint(3)))
assert.NotTrueNow(isContainsElement([]uint64{1, 2, 3}, uint(4)))
assert.TrueNow(isContainsElement(&[]int{1, 2, 3}, 3))
assert.TrueNow(isContainsElement([3]int{1, 2, 3}, 3))
assert.NotTrueNow(isContainsElement([3]int{1, 2, 3}, 4))
}