1
0
mirror of https://github.com/golang/go synced 2024-11-26 02:07:57 -07:00

gofmt-ify gob

(the one-line struct types used in composite literals will become
one line again in another cleanup round; don't worry about them now)

R=r
http://go/go-review/1016056
This commit is contained in:
Robert Griesemer 2009-11-05 14:53:42 -08:00
parent 790c9b59d6
commit f65e42d039
3 changed files with 328 additions and 245 deletions

File diff suppressed because it is too large Load Diff

View File

@ -358,7 +358,7 @@ func decodeStruct(engine *decEngine, rtyp *reflect.StructType, b *bytes.Buffer,
if indir > 0 { if indir > 0 {
up := unsafe.Pointer(p); up := unsafe.Pointer(p);
if indir > 1 { if indir > 1 {
up = decIndirect(up, indir) up = decIndirect(up, indir);
} }
if *(*unsafe.Pointer)(up) == nil { if *(*unsafe.Pointer)(up) == nil {
// Allocate object by making a slice of bytes and recording the // Allocate object by making a slice of bytes and recording the
@ -579,9 +579,7 @@ func decIgnoreOpFor(wireId typeId) (decOp, os.Error) {
if err != nil { if err != nil {
return nil, err; return nil, err;
} }
op = func(i *decInstr, state *decodeState, p unsafe.Pointer) { op = func(i *decInstr, state *decodeState, p unsafe.Pointer) { state.err = ignoreSlice(state, elemOp) };
state.err = ignoreSlice(state, elemOp);
};
case *arrayType: case *arrayType:
elemId := wireId.gobType().(*arrayType).Elem; elemId := wireId.gobType().(*arrayType).Elem;

View File

@ -17,23 +17,23 @@ type ET2 struct {
} }
type ET1 struct { type ET1 struct {
a int; a int;
et2 *ET2; et2 *ET2;
next *ET1; next *ET1;
} }
// Like ET1 but with a different name for a field // Like ET1 but with a different name for a field
type ET3 struct { type ET3 struct {
a int; a int;
et2 *ET2; et2 *ET2;
differentNext *ET1; differentNext *ET1;
} }
// Like ET1 but with a different type for a field // Like ET1 but with a different type for a field
type ET4 struct { type ET4 struct {
a int; a int;
et2 *ET1; et2 *ET1;
next int; next int;
} }
func TestBasicEncoder(t *testing.T) { func TestBasicEncoder(t *testing.T) {
@ -44,7 +44,7 @@ func TestBasicEncoder(t *testing.T) {
et1.et2 = new(ET2); et1.et2 = new(ET2);
enc.Encode(et1); enc.Encode(et1);
if enc.state.err != nil { if enc.state.err != nil {
t.Error("encoder fail:", enc.state.err) t.Error("encoder fail:", enc.state.err);
} }
// Decode the result by hand to verify; // Decode the result by hand to verify;
@ -114,14 +114,14 @@ func TestBasicEncoder(t *testing.T) {
} }
// 9) EOF // 9) EOF
if b.Len() != 0 { if b.Len() != 0 {
t.Error("not at eof;", b.Len(), "bytes left") t.Error("not at eof;", b.Len(), "bytes left");
} }
// Now do it again. This time we should see only the type id and value. // Now do it again. This time we should see only the type id and value.
b.Reset(); b.Reset();
enc.Encode(et1); enc.Encode(et1);
if enc.state.err != nil { if enc.state.err != nil {
t.Error("2nd round: encoder fail:", enc.state.err) t.Error("2nd round: encoder fail:", enc.state.err);
} }
// The length. // The length.
length = decodeUint(state); length = decodeUint(state);
@ -144,7 +144,7 @@ func TestBasicEncoder(t *testing.T) {
} }
// 7a) EOF // 7a) EOF
if b.Len() != 0 { if b.Len() != 0 {
t.Error("2nd round: not at eof;", b.Len(), "bytes left") t.Error("2nd round: not at eof;", b.Len(), "bytes left");
} }
} }
@ -156,7 +156,7 @@ func TestEncoderDecoder(t *testing.T) {
et1.et2 = new(ET2); et1.et2 = new(ET2);
enc.Encode(et1); enc.Encode(et1);
if enc.state.err != nil { if enc.state.err != nil {
t.Error("encoder fail:", enc.state.err) t.Error("encoder fail:", enc.state.err);
} }
dec := NewDecoder(b); dec := NewDecoder(b);
newEt1 := new(ET1); newEt1 := new(ET1);
@ -169,7 +169,7 @@ func TestEncoderDecoder(t *testing.T) {
t.Fatalf("invalid data for et1: expected %+v; got %+v\n", *et1, *newEt1); t.Fatalf("invalid data for et1: expected %+v; got %+v\n", *et1, *newEt1);
} }
if b.Len() != 0 { if b.Len() != 0 {
t.Error("not at eof;", b.Len(), "bytes left") t.Error("not at eof;", b.Len(), "bytes left");
} }
enc.Encode(et1); enc.Encode(et1);
@ -182,13 +182,13 @@ func TestEncoderDecoder(t *testing.T) {
t.Fatalf("round 2: invalid data for et1: expected %+v; got %+v\n", *et1, *newEt1); t.Fatalf("round 2: invalid data for et1: expected %+v; got %+v\n", *et1, *newEt1);
} }
if b.Len() != 0 { if b.Len() != 0 {
t.Error("round 2: not at eof;", b.Len(), "bytes left") t.Error("round 2: not at eof;", b.Len(), "bytes left");
} }
// Now test with a running encoder/decoder pair that we recognize a type mismatch. // Now test with a running encoder/decoder pair that we recognize a type mismatch.
enc.Encode(et1); enc.Encode(et1);
if enc.state.err != nil { if enc.state.err != nil {
t.Error("round 3: encoder fail:", enc.state.err) t.Error("round 3: encoder fail:", enc.state.err);
} }
newEt2 := new(ET2); newEt2 := new(ET2);
dec.Decode(newEt2); dec.Decode(newEt2);
@ -207,7 +207,7 @@ func badTypeCheck(e interface{}, shouldFail bool, msg string, t *testing.T) {
et1.et2 = new(ET2); et1.et2 = new(ET2);
enc.Encode(et1); enc.Encode(et1);
if enc.state.err != nil { if enc.state.err != nil {
t.Error("encoder fail:", enc.state.err) t.Error("encoder fail:", enc.state.err);
} }
dec := NewDecoder(b); dec := NewDecoder(b);
dec.Decode(e); dec.Decode(e);
@ -244,15 +244,15 @@ func TestBadData(t *testing.T) {
// Types not supported by the Encoder (only structs work at the top level). // Types not supported by the Encoder (only structs work at the top level).
// Basic types work implicitly. // Basic types work implicitly.
var unsupportedValues = []interface{} { var unsupportedValues = []interface{}{
3, 3,
"hi", "hi",
7.2, 7.2,
[]int{ 1, 2, 3 }, []int{1, 2, 3},
[3]int{ 1, 2, 3 }, [3]int{1, 2, 3},
make(chan int), make(chan int),
func(a int) bool { return true }, func(a int) bool { return true },
make(map[string] int), make(map[string]int),
new(interface{}), new(interface{}),
} }
@ -262,7 +262,7 @@ func TestUnsupported(t *testing.T) {
for _, v := range unsupportedValues { for _, v := range unsupportedValues {
err := enc.Encode(v); err := enc.Encode(v);
if err == nil { if err == nil {
t.Errorf("expected error for %T; got none", v) t.Errorf("expected error for %T; got none", v);
} }
} }
} }
@ -272,39 +272,45 @@ func encAndDec(in, out interface{}) os.Error {
enc := NewEncoder(b); enc := NewEncoder(b);
enc.Encode(in); enc.Encode(in);
if enc.state.err != nil { if enc.state.err != nil {
return enc.state.err return enc.state.err;
} }
dec := NewDecoder(b); dec := NewDecoder(b);
dec.Decode(out); dec.Decode(out);
if dec.state.err != nil { if dec.state.err != nil {
return dec.state.err return dec.state.err;
} }
return nil; return nil;
} }
func TestTypeToPtrType(t *testing.T) { func TestTypeToPtrType(t *testing.T) {
// Encode a T, decode a *T // Encode a T, decode a *T
type Type0 struct { a int } type Type0 struct {
a int;
}
t0 := Type0{7}; t0 := Type0{7};
t0p := (*Type0)(nil); t0p := (*Type0)(nil);
if err := encAndDec(t0, t0p); err != nil { if err := encAndDec(t0, t0p); err != nil {
t.Error(err) t.Error(err);
} }
} }
func TestPtrTypeToType(t *testing.T) { func TestPtrTypeToType(t *testing.T) {
// Encode a *T, decode a T // Encode a *T, decode a T
type Type1 struct { a uint } type Type1 struct {
a uint;
}
t1p := &Type1{17}; t1p := &Type1{17};
var t1 Type1; var t1 Type1;
if err := encAndDec(t1, t1p); err != nil { if err := encAndDec(t1, t1p); err != nil {
t.Error(err) t.Error(err);
} }
} }
func TestTypeToPtrPtrPtrPtrType(t *testing.T) { func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
// Encode a *T, decode a T // Encode a *T, decode a T
type Type2 struct { a ****float } type Type2 struct {
a ****float;
}
t2 := Type2{}; t2 := Type2{};
t2.a = new(***float); t2.a = new(***float);
*t2.a = new(**float); *t2.a = new(**float);
@ -313,7 +319,7 @@ func TestTypeToPtrPtrPtrPtrType(t *testing.T) {
****t2.a = 27.4; ****t2.a = 27.4;
t2pppp := new(***Type2); t2pppp := new(***Type2);
if err := encAndDec(t2, t2pppp); err != nil { if err := encAndDec(t2, t2pppp); err != nil {
t.Error(err) t.Error(err);
} }
if ****(****t2pppp).a != ****t2.a { if ****(****t2pppp).a != ****t2.a {
t.Errorf("wrong value after decode: %g not %g", ****(****t2pppp).a, ****t2.a); t.Errorf("wrong value after decode: %g not %g", ****(****t2pppp).a, ****t2.a);