Skip to content

Commit

Permalink
Merge pull request chrislusf#53 from justicezyx/pr
Browse files Browse the repository at this point in the history
Add utils_test.go.
  • Loading branch information
justicezyx authored Jul 8, 2016
2 parents c2186bb + 4c9e90c commit 7fc24d6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions flow/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
}
}

0 comments on commit 7fc24d6

Please sign in to comment.