forked from chrislusf/glow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
48 lines (44 loc) · 941 Bytes
/
utils_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 flow
import (
"reflect"
"testing"
)
func TestGuessFunctionOutputType(t *testing.T) {
f := func(i int) int {
return 1
}
if got, want := guessFunctionOutputType(f), reflect.TypeOf(1); got != want {
t.Errorf("Type mismatch, got %v want %v", got, want)
}
}
func TestGuessKey(t *testing.T) {
testStruct := struct {
A string
}{
A: "test",
}
cases := []struct {
input reflect.Value
want reflect.Value
}{{
input: reflect.ValueOf(1),
want: reflect.ValueOf(1),
}, {
input: reflect.ValueOf("test"),
want: reflect.ValueOf("test"),
}, {
input: reflect.ValueOf([1]int{1}),
want: reflect.ValueOf(1),
}, {
input: reflect.ValueOf([]int{1}),
want: reflect.ValueOf(1),
}, {
input: reflect.ValueOf(testStruct),
want: reflect.ValueOf("test"),
}}
for _, c := range cases {
if got := guessKey(c.input); got.Interface() != c.want.Interface() {
t.Errorf("Got %v want %v", got, c.want)
}
}
}