From a15b6ad67063562c974b346ca71dfceea045b0e4 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Thu, 2 May 2019 09:32:23 -0700 Subject: [PATCH] add test for canParse with TextUnmarshaler --- reflect.go | 2 -- reflect_test.go | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/reflect.go b/reflect.go index 32efe04..e113583 100644 --- a/reflect.go +++ b/reflect.go @@ -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) diff --git a/reflect_test.go b/reflect_test.go index 0f285f7..47e68b5 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -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) +}