From: David Symonds Date: Tue, 24 Jul 2012 23:31:27 +0000 (+1000) Subject: encoding/gob: test for type registration name. X-Git-Tag: go1.1rc2~2781 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3e980e24c115dba89f53e09d8c597db32a6ffc2e;p=gostls13.git encoding/gob: test for type registration name. R=r CC=golang-dev https://golang.org/cl/6435044 --- diff --git a/src/pkg/encoding/gob/type_test.go b/src/pkg/encoding/gob/type_test.go index 42bdb4cf7b..734fbb04b4 100644 --- a/src/pkg/encoding/gob/type_test.go +++ b/src/pkg/encoding/gob/type_test.go @@ -159,3 +159,33 @@ func TestRegistration(t *testing.T) { Register(new(T)) Register(new(T)) } + +type N1 struct{} +type N2 struct{} + +// See comment in type.go/Register. +func TestRegistrationNaming(t *testing.T) { + testCases := []struct { + t interface{} + name string + }{ + {&N1{}, "*gob.N1"}, + {N2{}, "encoding/gob.N2"}, + } + + for _, tc := range testCases { + Register(tc.t) + + tct := reflect.TypeOf(tc.t) + if ct := nameToConcreteType[tc.name]; ct != tct { + t.Errorf("nameToConcreteType[%q] = %v, want %v", tc.name, ct, tct) + } + // concreteTypeToName is keyed off the base type. + if tct.Kind() == reflect.Ptr { + tct = tct.Elem() + } + if n := concreteTypeToName[tct]; n != tc.name { + t.Errorf("concreteTypeToName[%v] got %v, want %v", tct, n, tc.name) + } + } +}