Content-Length: 302102 | pFad | http://github.com/golang/go/commit/368a9ec99834652ca3f7d8fe24862a7581e12358

2C encoding/json: cleanup tests · golang/go@368a9ec · GitHub
Skip to content

Commit

Permalink
encoding/json: cleanup tests
Browse files Browse the repository at this point in the history
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 <dneil@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
  • Loading branch information
dsnet committed Jan 14, 2025
1 parent bd80d89 commit 368a9ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/encoding/json/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func TestUnmarshal(t *testing.T) {
var scan scanner
if err := checkValid(in, &scan); err != nil {
if !equalError(err, tt.err) {
t.Fatalf("%s: checkValid error: %#v", tt.Where, err)
t.Fatalf("%s: checkValid error:\n\tgot %#v\n\twant %#v", tt.Where, err, tt.err)
}
}
if tt.ptr == nil {
Expand Down Expand Up @@ -1355,7 +1355,7 @@ func TestUnmarshal(t *testing.T) {
dec.DisallowUnknownFields()
}
if err := dec.Decode(v.Interface()); !equalError(err, tt.err) {
t.Fatalf("%s: Decode error:\n\tgot: %#v\n\twant: %#v", tt.Where, err, tt.err)
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)
} else if err != nil && tt.out == nil {
// Initialize tt.out during an error where there are no mutations,
// so the output is just the zero value of the input type.
Expand Down
10 changes: 5 additions & 5 deletions src/encoding/json/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func TestEncoder(t *testing.T) {
t.Fatalf("#%d.%d Encode error: %v", i, j, err)
}
}
if have, want := buf.String(), nlines(streamEncoded, i); have != want {
if got, want := buf.String(), nlines(streamEncoded, i); got != want {
t.Errorf("encoding %d items: mismatch:", i)
diff(t, []byte(have), []byte(want))
diff(t, []byte(got), []byte(want))
break
}
}
Expand Down Expand Up @@ -148,9 +148,9 @@ func TestEncoderIndent(t *testing.T) {
for _, v := range streamTest {
enc.Encode(v)
}
if have, want := buf.String(), streamEncodedIndent; have != want {
t.Error("Encode mismatch:")
diff(t, []byte(have), []byte(want))
if got, want := buf.String(), streamEncodedIndent; got != want {
t.Errorf("Encode mismatch:\ngot:\n%s\n\nwant:\n%s", got, want)
diff(t, []byte(got), []byte(want))
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/encoding/json/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package json

import (
"testing"
)
import "testing"

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

0 comments on commit 368a9ec

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/golang/go/commit/368a9ec99834652ca3f7d8fe24862a7581e12358

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy