aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/encoding/binary/binary_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/encoding/binary/binary_test.go')
-rw-r--r--src/pkg/encoding/binary/binary_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pkg/encoding/binary/binary_test.go b/src/pkg/encoding/binary/binary_test.go
index 1aa6ecd248..c80c90383a 100644
--- a/src/pkg/encoding/binary/binary_test.go
+++ b/src/pkg/encoding/binary/binary_test.go
@@ -265,6 +265,30 @@ func TestBlankFields(t *testing.T) {
}
}
+// An attempt to read into a struct with an unexported field will
+// panic. This is probably not the best choice, but at this point
+// anything else would be an API change.
+
+type Unexported struct {
+ a int32
+}
+
+func TestUnexportedRead(t *testing.T) {
+ var buf bytes.Buffer
+ u1 := Unexported{a: 1}
+ if err := Write(&buf, LittleEndian, &u1); err != nil {
+ t.Fatal(err)
+ }
+
+ defer func() {
+ if recover() == nil {
+ t.Fatal("did not panic")
+ }
+ }()
+ var u2 Unexported
+ Read(&buf, LittleEndian, &u2)
+}
+
type byteSliceReader struct {
remain []byte
}