aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/gob/encoder_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/encoding/gob/encoder_test.go
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.xz
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/encoding/gob/encoder_test.go')
-rw-r--r--src/encoding/gob/encoder_test.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/encoding/gob/encoder_test.go b/src/encoding/gob/encoder_test.go
index a358d5bc30..6934841b3a 100644
--- a/src/encoding/gob/encoder_test.go
+++ b/src/encoding/gob/encoder_test.go
@@ -18,7 +18,7 @@ import (
// Test basic operations in a safe manner.
func TestBasicEncoderDecoder(t *testing.T) {
- var values = []interface{}{
+ var values = []any{
true,
int(123),
int8(123),
@@ -228,7 +228,7 @@ func TestEncoderDecoder(t *testing.T) {
// Run one value through the encoder/decoder, but use the wrong type.
// Input is always an ET1; we compare it to whatever is under 'e'.
-func badTypeCheck(e interface{}, shouldFail bool, msg string, t *testing.T) {
+func badTypeCheck(e any, shouldFail bool, msg string, t *testing.T) {
b := new(bytes.Buffer)
enc := NewEncoder(b)
et1 := new(ET1)
@@ -256,7 +256,7 @@ func TestWrongTypeDecoder(t *testing.T) {
}
// Types not supported at top level by the Encoder.
-var unsupportedValues = []interface{}{
+var unsupportedValues = []any{
make(chan int),
func(a int) bool { return true },
}
@@ -272,7 +272,7 @@ func TestUnsupported(t *testing.T) {
}
}
-func encAndDec(in, out interface{}) error {
+func encAndDec(in, out any) error {
b := new(bytes.Buffer)
enc := NewEncoder(b)
err := enc.Encode(in)
@@ -418,8 +418,8 @@ var testMap map[string]int
var testArray [7]int
type SingleTest struct {
- in interface{}
- out interface{}
+ in any
+ out any
err string
}
@@ -536,7 +536,7 @@ func TestInterfaceIndirect(t *testing.T) {
// encoder and decoder don't skew with respect to type definitions.
type Struct0 struct {
- I interface{}
+ I any
}
type NewType0 struct {
@@ -544,7 +544,7 @@ type NewType0 struct {
}
type ignoreTest struct {
- in, out interface{}
+ in, out any
}
var ignoreTests = []ignoreTest{
@@ -559,7 +559,7 @@ var ignoreTests = []ignoreTest{
// Decode struct containing an interface into a nil.
{&Struct0{&NewType0{"value0"}}, nil},
// Decode singleton slice of interfaces into a nil.
- {[]interface{}{"hi", &NewType0{"value1"}, 23}, nil},
+ {[]any{"hi", &NewType0{"value1"}, 23}, nil},
}
func TestDecodeIntoNothing(t *testing.T) {
@@ -621,7 +621,7 @@ func TestIgnoreRecursiveType(t *testing.T) {
// Another bug from golang-nuts, involving nested interfaces.
type Bug0Outer struct {
- Bug0Field interface{}
+ Bug0Field any
}
type Bug0Inner struct {
@@ -635,7 +635,7 @@ func TestNestedInterfaces(t *testing.T) {
Register(new(Bug0Outer))
Register(new(Bug0Inner))
f := &Bug0Outer{&Bug0Outer{&Bug0Inner{7}}}
- var v interface{} = f
+ var v any = f
err := e.Encode(&v)
if err != nil {
t.Fatal("Encode:", err)
@@ -694,7 +694,7 @@ func TestMapBug1(t *testing.T) {
}
func TestGobMapInterfaceEncode(t *testing.T) {
- m := map[string]interface{}{
+ m := map[string]any{
"up": uintptr(0),
"i0": []int{-1},
"i1": []int8{-1},
@@ -876,10 +876,10 @@ func TestGobPtrSlices(t *testing.T) {
// getDecEnginePtr cached engine for ut.base instead of ut.user so we passed
// a *map and then tried to reuse its engine to decode the inner map.
func TestPtrToMapOfMap(t *testing.T) {
- Register(make(map[string]interface{}))
- subdata := make(map[string]interface{})
+ Register(make(map[string]any))
+ subdata := make(map[string]any)
subdata["bar"] = "baz"
- data := make(map[string]interface{})
+ data := make(map[string]any)
data["foo"] = subdata
b := new(bytes.Buffer)
@@ -887,7 +887,7 @@ func TestPtrToMapOfMap(t *testing.T) {
if err != nil {
t.Fatal("encode:", err)
}
- var newData map[string]interface{}
+ var newData map[string]any
err = NewDecoder(b).Decode(&newData)
if err != nil {
t.Fatal("decode:", err)
@@ -927,7 +927,7 @@ func TestTopLevelNilPointer(t *testing.T) {
}
}
-func encodeAndRecover(value interface{}) (encodeErr, panicErr error) {
+func encodeAndRecover(value any) (encodeErr, panicErr error) {
defer func() {
e := recover()
if e != nil {
@@ -959,7 +959,7 @@ func TestNilPointerPanics(t *testing.T) {
)
testCases := []struct {
- value interface{}
+ value any
mustPanic bool
}{
{nilStringPtr, true},
@@ -991,7 +991,7 @@ func TestNilPointerPanics(t *testing.T) {
func TestNilPointerInsideInterface(t *testing.T) {
var ip *int
si := struct {
- I interface{}
+ I any
}{
I: ip,
}
@@ -1049,7 +1049,7 @@ type Z struct {
func Test29ElementSlice(t *testing.T) {
Register(Z{})
- src := make([]interface{}, 100) // Size needs to be bigger than size of type definition.
+ src := make([]any, 100) // Size needs to be bigger than size of type definition.
for i := range src {
src[i] = Z{}
}
@@ -1060,7 +1060,7 @@ func Test29ElementSlice(t *testing.T) {
return
}
- var dst []interface{}
+ var dst []any
err = NewDecoder(buf).Decode(&dst)
if err != nil {
t.Errorf("decode: %v", err)
@@ -1091,9 +1091,9 @@ func TestErrorForHugeSlice(t *testing.T) {
}
type badDataTest struct {
- input string // The input encoded as a hex string.
- error string // A substring of the error that should result.
- data interface{} // What to decode into.
+ input string // The input encoded as a hex string.
+ error string // A substring of the error that should result.
+ data any // What to decode into.
}
var badDataTests = []badDataTest{