aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/binary/binary_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/binary/binary_test.go')
-rw-r--r--src/encoding/binary/binary_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/encoding/binary/binary_test.go b/src/encoding/binary/binary_test.go
index 341cd86766..4e1fb59f03 100644
--- a/src/encoding/binary/binary_test.go
+++ b/src/encoding/binary/binary_test.go
@@ -540,6 +540,30 @@ func testReadInvalidDestination(t *testing.T, order ByteOrder) {
}
}
+func TestNoFixedSize(t *testing.T) {
+ type Person struct {
+ Age int
+ Weight float64
+ Height float64
+ }
+
+ person := Person{
+ Age: 27,
+ Weight: 67.3,
+ Height: 177.8,
+ }
+
+ buf := new(bytes.Buffer)
+ err := Write(buf, LittleEndian, &person)
+ if err == nil {
+ t.Fatal("binary.Write: unexpected success as size of type *binary.Person is not fixed")
+ }
+ errs := "binary.Write: some values are not fixed-sized in type *binary.Person"
+ if err.Error() != errs {
+ t.Fatalf("got %q, want %q", err, errs)
+ }
+}
+
type byteSliceReader struct {
remain []byte
}