-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
48 lines (41 loc) · 980 Bytes
/
util_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
package jqtop
import "testing"
func TestGetFieldValues(t *testing.T) {
s := struct {
Exclude string
Include string
}{"exclude", "include"}
if !sliceEqual([]string{"exclude", "include"}, getFieldValues(s)) {
t.Errorf("getFieldValues didn't fetch the right values")
}
}
// sliceEqual tells whether a and b contain the same elements.
// A nil argument is equivalent to an empty slice.
func sliceEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func TestSliceContains(t *testing.T) {
mySlice := []string{"hello", "world"}
var testCases = []struct {
in string
expected bool
}{
{"hello", true},
{"not_exist", false},
}
for _, tt := range testCases {
t.Run(tt.in, func(t *testing.T) {
if ret := sliceContains(mySlice, tt.in); ret != tt.expected {
t.Errorf("TestSliceContains: For input: %s, we expected: %t", tt.in, tt.expected)
}
})
}
}