add test for canParse with TextUnmarshaler
This commit is contained in:
parent
87be2d9790
commit
a15b6ad670
|
@ -9,8 +9,6 @@ import (
|
|||
|
||||
var textUnmarshalerType = reflect.TypeOf([]encoding.TextUnmarshaler{}).Elem()
|
||||
|
||||
// This file contains miscellaneous reflection utilities
|
||||
|
||||
// canParse returns true if the type can be parsed from a string
|
||||
func canParse(t reflect.Type) (parseable, boolean, multiple bool) {
|
||||
parseable = scalar.CanParse(t)
|
||||
|
|
|
@ -38,3 +38,18 @@ func TestCanParse(t *testing.T) {
|
|||
assertCanParse(t, reflect.TypeOf(is), true, false, true)
|
||||
assertCanParse(t, reflect.TypeOf(&is), true, false, true)
|
||||
}
|
||||
|
||||
type implementsTextUnmarshaler struct{}
|
||||
|
||||
func (*implementsTextUnmarshaler) UnmarshalText(text []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestCanParseTextUnmarshaler(t *testing.T) {
|
||||
var u implementsTextUnmarshaler
|
||||
var su []implementsTextUnmarshaler
|
||||
assertCanParse(t, reflect.TypeOf(u), true, false, false)
|
||||
assertCanParse(t, reflect.TypeOf(&u), true, false, false)
|
||||
assertCanParse(t, reflect.TypeOf(su), true, false, true)
|
||||
assertCanParse(t, reflect.TypeOf(&su), true, false, true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue