]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: test for type registration name.
authorDavid Symonds <dsymonds@golang.org>
Tue, 24 Jul 2012 23:31:27 +0000 (09:31 +1000)
committerDavid Symonds <dsymonds@golang.org>
Tue, 24 Jul 2012 23:31:27 +0000 (09:31 +1000)
R=r
CC=golang-dev
https://golang.org/cl/6435044

src/pkg/encoding/gob/type_test.go

index 42bdb4cf7bb224198162fb626c6394df1ef1560c..734fbb04b4c87244894041578801fd52b1788fd5 100644 (file)
@@ -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)
+               }
+       }
+}