-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathslices_test.go
95 lines (91 loc) · 1.57 KB
/
slices_test.go
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
package utils_test
import (
"testing"
"github.com/odpf/guardian/utils"
"github.com/stretchr/testify/assert"
)
func TestSubsliceExists(t *testing.T) {
testCases := []struct {
slice []string
subslice []string
expectedResult bool
expectedHeadIndex int
}{
{
[]string{"a", "b", "c", "d"},
[]string{"a", "b", "c", "d"},
true, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"a", "b"},
true, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"b", "c", "d"},
true, 1,
},
{
[]string{"a", "b", "c"},
[]string{"b"},
true, 1,
},
{
[]string{"a", "b", "c", "b"},
[]string{"c"},
true, 2,
},
{
[]string{"a", "b", "c", "d"},
[]string{"b", "c", "d"},
true, 1,
},
{
// return true for empty `subslice` elements
[]string{"a", "b", "c", "d"},
[]string{},
true, 0,
},
{
[]string{},
[]string{},
true, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"a", "c", "d"},
false, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"c", "c", "d"},
false, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"b", "d"},
false, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"a", "b", "x"},
false, 0,
},
{
[]string{"a", "b", "c", "d"},
[]string{"a", "b", "c", "d", "x", "y"},
false, 0,
},
{
[]string{},
[]string{"a"},
false, 0,
},
}
for _, tc := range testCases {
result, headIndex := utils.SubsliceExists(tc.slice, tc.subslice)
assert.Equal(t, tc.expectedResult, result)
assert.Equal(t, tc.expectedHeadIndex, headIndex)
}
}