mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
can't encode array or slice - catch in sendType rather than failing in Encode
R=rsc DELTA=38 (33 added, 3 deleted, 2 changed) OCL=34101 CL=34104
This commit is contained in:
parent
fda0e78b23
commit
c62b9d8f2a
2 changed files with 35 additions and 5 deletions
|
|
@ -243,3 +243,25 @@ func TestBadData(t *testing.T) {
|
|||
corruptDataCheck("\x7Fhi", io.ErrUnexpectedEOF, t);
|
||||
corruptDataCheck("\x03now is the time for all good men", errBadType, t);
|
||||
}
|
||||
|
||||
// Types not supported by the Encoder (only structs work at the top level).
|
||||
// Basic types work implicitly.
|
||||
var unsupportedValues = []interface{} {
|
||||
[]int{ 1, 2, 3 },
|
||||
[3]int{ 1, 2, 3 },
|
||||
make(chan int),
|
||||
func(a int) bool { return true },
|
||||
make(map[string] int),
|
||||
new(interface{}),
|
||||
}
|
||||
|
||||
func TestUnsupported(t *testing.T) {
|
||||
var b bytes.Buffer;
|
||||
enc := NewEncoder(&b);
|
||||
for _, v := range unsupportedValues {
|
||||
err := enc.Encode(v);
|
||||
if err == nil {
|
||||
t.Errorf("expected error for %T; got none", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue