Commit 3e980e24 authored by David Symonds's avatar David Symonds

encoding/gob: test for type registration name.

R=r
CC=golang-dev
https://golang.org/cl/6435044
parent c1f2ec38
......@@ -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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment