diff options
| author | Alex Flint <[email protected]> | 2018-11-19 12:48:00 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-11-19 12:48:00 -0800 |
| commit | 6ab8ad5e1c5b25ca2783fe83f493c3ab471407e2 (patch) | |
| tree | 52e1f2fbbc29c8a42a882e67a6830b64cc4ead9d /scalar_test.go | |
| parent | e80c3b7ed292b052c7083b6fd7154a8422c33f65 (diff) | |
| parent | e1338aeff04713f53befe44b42323f55fd60338c (diff) | |
Merge pull request #2 from pborzenkov/text-unmarshaler-value
Allow to use values (not pointers) with TextUnmarshaler
Diffstat (limited to 'scalar_test.go')
| -rw-r--r-- | scalar_test.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/scalar_test.go b/scalar_test.go index d70bd32..9a1ef6a 100644 --- a/scalar_test.go +++ b/scalar_test.go @@ -10,6 +10,15 @@ import ( "github.com/stretchr/testify/require" ) +type textUnmarshaler struct { + val int +} + +func (f *textUnmarshaler) UnmarshalText(b []byte) error { + f.val = len(b) + return nil +} + func assertParse(t *testing.T, expected interface{}, str string) { v := reflect.New(reflect.TypeOf(expected)).Elem() err := ParseValue(v, str) @@ -67,6 +76,9 @@ func TestParseValue(t *testing.T) { // MAC addresses assertParse(t, net.HardwareAddr("\x01\x23\x45\x67\x89\xab"), "01:23:45:67:89:ab") + + // custom text unmarshaler + assertParse(t, textUnmarshaler{3}, "abc") } func TestParse(t *testing.T) { |
