Skip to content

Commit 368a9ec

Browse files
committed
encoding/json: cleanup tests
Perform minor cleanups in tests to improve printout of diffs and/or follow modern coding style. This reduces the amount of diffs between v1 and the v2 prototype. Change-Id: I019bb9642e2135f2fa3eac6abfa6df91c397aa82 Reviewed-on: https://go-review.googlesource.com/c/go/+/642257 Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent bd80d89 commit 368a9ec

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/encoding/json/decode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ func TestUnmarshal(t *testing.T) {
13211321
var scan scanner
13221322
if err := checkValid(in, &scan); err != nil {
13231323
if !equalError(err, tt.err) {
1324-
t.Fatalf("%s: checkValid error: %#v", tt.Where, err)
1324+
t.Fatalf("%s: checkValid error:\n\tgot %#v\n\twant %#v", tt.Where, err, tt.err)
13251325
}
13261326
}
13271327
if tt.ptr == nil {
@@ -1355,7 +1355,7 @@ func TestUnmarshal(t *testing.T) {
13551355
dec.DisallowUnknownFields()
13561356
}
13571357
if err := dec.Decode(v.Interface()); !equalError(err, tt.err) {
1358-
t.Fatalf("%s: Decode error:\n\tgot: %#v\n\twant: %#v", tt.Where, err, tt.err)
1358+
t.Fatalf("%s: Decode error:\n\tgot: %v\n\twant: %v\n\n\tgot: %#v\n\twant: %#v", tt.Where, err, tt.err, err, tt.err)
13591359
} else if err != nil && tt.out == nil {
13601360
// Initialize tt.out during an error where there are no mutations,
13611361
// so the output is just the zero value of the input type.

src/encoding/json/stream_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func TestEncoder(t *testing.T) {
7979
t.Fatalf("#%d.%d Encode error: %v", i, j, err)
8080
}
8181
}
82-
if have, want := buf.String(), nlines(streamEncoded, i); have != want {
82+
if got, want := buf.String(), nlines(streamEncoded, i); got != want {
8383
t.Errorf("encoding %d items: mismatch:", i)
84-
diff(t, []byte(have), []byte(want))
84+
diff(t, []byte(got), []byte(want))
8585
break
8686
}
8787
}
@@ -148,9 +148,9 @@ func TestEncoderIndent(t *testing.T) {
148148
for _, v := range streamTest {
149149
enc.Encode(v)
150150
}
151-
if have, want := buf.String(), streamEncodedIndent; have != want {
152-
t.Error("Encode mismatch:")
153-
diff(t, []byte(have), []byte(want))
151+
if got, want := buf.String(), streamEncodedIndent; got != want {
152+
t.Errorf("Encode mismatch:\ngot:\n%s\n\nwant:\n%s", got, want)
153+
diff(t, []byte(got), []byte(want))
154154
}
155155
}
156156

src/encoding/json/tags_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
package json
66

7-
import (
8-
"testing"
9-
)
7+
import "testing"
108

119
func TestTagParsing(t *testing.T) {
1210
name, opts := parseTag("field,foobar,foo")

0 commit comments

Comments
 (0)