var tFloat32 Type
var tFloat64 Type
var tString Type
+var tBytes Type
// Array type
type arrayType struct {
case reflect.StringKind:
return tString
case reflect.ArrayKind:
- // TODO(r): worth a special case for array of bytes?
at := rt.(reflect.ArrayType);
if at.IsSlice() {
+ // []byte == []uint8 is a special case
+ if at.Elem().Kind() == reflect.Uint8Kind {
+ return tBytes
+ }
return newSliceType(name, newType("", at.Elem()));
} else {
return newArrayType(name, newType("", at.Elem()), at.Len());
tUint = bootstrapType("uint", uint(0));
tFloat32 = bootstrapType("float32", float32(0));
tFloat64 = bootstrapType("float64", float64(0));
+ // The string for tBytes is "bytes" not "[]byte" to signify its specialness.
+ tBytes = bootstrapType("bytes", make([]byte, 0));
tString= bootstrapType("string", "");
}
typeT { tUint, "uint" },
typeT { tFloat32, "float32" },
typeT { tFloat64, "float64" },
+ typeT { tBytes, "bytes" },
typeT { tString, "string" },
}
a int;
b int32; // will become int
c string;
- d *float; // will become float32
- e ****float64; // will become float64
- f *Bar;
- g *Bar; // should not interpolate the definition of Bar again
- h *Foo; // will not explode
+ d []byte;
+ e *float; // will become float32
+ f ****float64; // will become float64
+ g *Bar;
+ h *Bar; // should not interpolate the definition of Bar again
+ i *Foo; // will not explode
}
func TestStructType(t *testing.T) {
sstruct := GetType("Foo", Foo{});
str := sstruct.String();
// If we can print it correctly, we built it correctly.
- expected := "Foo = struct { a int; b int; c string; d float32; e float64; f Bar = struct { x string; }; g Bar; h Foo; }";
+ expected := "Foo = struct { a int; b int; c string; d bytes; e float32; f float64; g Bar = struct { x string; }; h Bar; i Foo; }";
if str != expected {
t.Errorf("struct printed as %q; expected %q", str, expected);
}