From 5214e17d0bdbd365b14ae1aba8805fb761452ed6 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 9 Jul 2009 14:33:43 -0700 Subject: store ids rather than Types in the structs so they can be encoded. change Type to gobType. fix some bugs around recursive structures. lots of cleanup. add the first cut at a type encoder. R=rsc DELTA=400 (287 added, 11 deleted, 102 changed) OCL=31401 CL=31406 --- src/pkg/gob/codec_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/pkg/gob/codec_test.go') diff --git a/src/pkg/gob/codec_test.go b/src/pkg/gob/codec_test.go index e25a719fa..23ff885f0 100644 --- a/src/pkg/gob/codec_test.go +++ b/src/pkg/gob/codec_test.go @@ -13,7 +13,6 @@ import ( "testing"; "unsafe"; ) -import "fmt" // TODO DELETE // Guarantee encoding format by comparing some encodings to hand-written values type EncodeT struct { @@ -560,6 +559,30 @@ func TestEndToEnd(t *testing.T) { } } +func TestNesting(t *testing.T) { + type RT struct { + a string; + next *RT + } + rt := new(RT); + rt.a = "level1"; + rt.next = new(RT); + rt.next.a = "level2"; + b := new(bytes.Buffer); + Encode(b, rt); + var drt RT; + Decode(b, &drt); + if drt.a != rt.a { + t.Errorf("nesting: encode expected %v got %v", *rt, drt); + } + if drt.next == nil { + t.Errorf("nesting: recursion failed"); + } + if drt.next.a != rt.next.a { + t.Errorf("nesting: encode expected %v got %v", *rt.next, *drt.next); + } +} + // These three structures have the same data with different indirections type T0 struct { a int; -- cgit v1.2.3