summaryrefslogtreecommitdiff
path: root/compat/json/borrowed_decode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compat/json/borrowed_decode_test.go')
-rw-r--r--compat/json/borrowed_decode_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/compat/json/borrowed_decode_test.go b/compat/json/borrowed_decode_test.go
index 38e2a1d..e08fa0a 100644
--- a/compat/json/borrowed_decode_test.go
+++ b/compat/json/borrowed_decode_test.go
@@ -985,6 +985,7 @@ var unmarshalTests = []unmarshalTest{
}
func TestMarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
b, err := Marshal(allValue)
if err != nil {
t.Fatalf("Marshal allValue: %v", err)
@@ -1018,6 +1019,7 @@ var badUTF8 = []struct {
}
func TestMarshalBadUTF8(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range badUTF8 {
b, err := Marshal(tt.in)
if string(b) != tt.out || err != nil {
@@ -1027,6 +1029,7 @@ func TestMarshalBadUTF8(t *testing.T) {
}
func TestMarshalNumberZeroVal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var n Number
out, err := Marshal(n)
if err != nil {
@@ -1039,6 +1042,7 @@ func TestMarshalNumberZeroVal(t *testing.T) {
}
func TestMarshalEmbeds(t *testing.T) {
+ t.Parallel() // MODIFIED: added
top := &Top{
Level0: 1,
Embed0: Embed0{
@@ -1091,6 +1095,7 @@ func equalError(a, b error) bool {
}
func TestUnmarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for i, tt := range unmarshalTests {
var scan scanner
in := []byte(tt.in)
@@ -1183,6 +1188,7 @@ func TestUnmarshal(t *testing.T) {
}
func TestUnmarshalMarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
initBig()
var v any
if err := Unmarshal(jsonBig, &v); err != nil {
@@ -1213,6 +1219,7 @@ var numberTests = []struct {
// Independent of Decode, basic coverage of the accessors in Number
func TestNumberAccessors(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range numberTests {
n := Number(tt.in)
if s := n.String(); s != tt.in {
@@ -1232,6 +1239,7 @@ func TestNumberAccessors(t *testing.T) {
}
func TestLargeByteSlice(t *testing.T) {
+ t.Parallel() // MODIFIED: added
s0 := make([]byte, 2000)
for i := range s0 {
s0[i] = byte(i)
@@ -1255,6 +1263,7 @@ type Xint struct {
}
func TestUnmarshalInterface(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var xint Xint
var i any = &xint
if err := Unmarshal([]byte(`{"X":1}`), &i); err != nil {
@@ -1266,6 +1275,7 @@ func TestUnmarshalInterface(t *testing.T) {
}
func TestUnmarshalPtrPtr(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var xint Xint
pxint := &xint
if err := Unmarshal([]byte(`{"X":1}`), &pxint); err != nil {
@@ -1277,6 +1287,7 @@ func TestUnmarshalPtrPtr(t *testing.T) {
}
func TestEscape(t *testing.T) {
+ t.Parallel() // MODIFIED: added
const input = `"foobar"<html>` + " [\u2028 \u2029]"
const expected = `"\"foobar\"\u003chtml\u003e [\u2028 \u2029]"`
b, err := Marshal(input)
@@ -1309,6 +1320,7 @@ var wrongStringTests = []wrongStringTest{
// If people misuse the ,string modifier, the error message should be
// helpful, telling the user that they're doing it wrong.
func TestErrorMessageFromMisusedString(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for n, tt := range wrongStringTests {
r := strings.NewReader(tt.in)
var s WrongString
@@ -1646,6 +1658,7 @@ var pallValueIndent = `{
var pallValueCompact = strings.Map(noSpace, pallValueIndent)
func TestRefUnmarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type S struct {
// Ref is defined in encode_test.go.
R0 Ref
@@ -1674,6 +1687,7 @@ func TestRefUnmarshal(t *testing.T) {
// Test that the empty string doesn't panic decoding when ,string is specified
// Issue 3450
func TestEmptyString(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type T2 struct {
Number1 int `json:",string"`
Number2 int `json:",string"`
@@ -1693,6 +1707,7 @@ func TestEmptyString(t *testing.T) {
// Test that a null for ,string is not replaced with the previous quoted string (issue 7046).
// It should also not be an error (issue 2540, issue 8587).
func TestNullString(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type T struct {
A int `json:",string"`
B int `json:",string"`
@@ -1745,6 +1760,7 @@ var interfaceSetTests = []struct {
}
func TestInterfaceSet(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range interfaceSetTests {
b := struct{ X any }{tt.pre}
blob := `{"X":` + tt.json + `}`
@@ -1796,6 +1812,7 @@ type NullTest struct {
// JSON null values should be ignored for primitives and string values instead of resulting in an error.
// Issue 2540
func TestUnmarshalNulls(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// Unmarshal docs:
// The JSON null value unmarshals into an interface, map, pointer, or slice
// by setting that Go value to nil. Because null is often used in JSON to mean
@@ -1931,6 +1948,7 @@ func (x MustNotUnmarshalText) UnmarshalText(text []byte) error {
}
func TestStringKind(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type stringKind string
var m1, m2 map[stringKind]int
@@ -1957,6 +1975,7 @@ func TestStringKind(t *testing.T) {
// and then unmarshaled.
// Issue 8962.
func TestByteKind(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type byteKind []byte
a := byteKind("hello")
@@ -1981,6 +2000,7 @@ func TestByteKind(t *testing.T) {
// The fix for issue 8962 introduced a regression.
// Issue 12921.
func TestSliceOfCustomByte(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type Uint8 uint8
a := []Uint8("hello")
@@ -2015,6 +2035,7 @@ var decodeTypeErrorTests = []struct {
}
func TestUnmarshalTypeError(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, item := range decodeTypeErrorTests {
err := Unmarshal([]byte(item.src), item.dest)
if _, ok := err.(*UnmarshalTypeError); !ok {
@@ -2036,6 +2057,7 @@ var unmarshalSyntaxTests = []string{
}
func TestUnmarshalSyntax(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var x any
for _, src := range unmarshalSyntaxTests {
err := Unmarshal([]byte(src), &x)
@@ -2056,6 +2078,7 @@ type unexportedFields struct {
}
func TestUnmarshalUnexported(t *testing.T) {
+ t.Parallel() // MODIFIED: added
input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}, "abcd": {"z": 789}, "s": [2, 3]}`
want := &unexportedFields{Name: "Bob"}
@@ -2086,6 +2109,7 @@ func (t *Time3339) UnmarshalJSON(b []byte) error {
}
func TestUnmarshalJSONLiteralError(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var t3 Time3339
err := Unmarshal([]byte(`"0000-00-00T00:00:00Z"`), &t3)
if err == nil {
@@ -2100,6 +2124,7 @@ func TestUnmarshalJSONLiteralError(t *testing.T) {
// "data changing underfoot" error.
// Issue 3717
func TestSkipArrayObjects(t *testing.T) {
+ t.Parallel() // MODIFIED: added
json := `[{}]`
var dest [0]any
@@ -2113,6 +2138,7 @@ func TestSkipArrayObjects(t *testing.T) {
// slices, and arrays.
// Issues 4900 and 8837, among others.
func TestPrefilled(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// Values here change, cannot reuse table across runs.
var prefillTests = []struct {
in string
@@ -2173,6 +2199,7 @@ var invalidUnmarshalTests = []struct {
}
func TestInvalidUnmarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
buf := []byte(`{"a":"1"}`)
for _, tt := range invalidUnmarshalTests {
err := Unmarshal(buf, tt.v)
@@ -2197,6 +2224,7 @@ var invalidUnmarshalTextTests = []struct {
}
func TestInvalidUnmarshalText(t *testing.T) {
+ t.Parallel() // MODIFIED: added
buf := []byte(`123`)
for _, tt := range invalidUnmarshalTextTests {
err := Unmarshal(buf, tt.v)
@@ -2213,6 +2241,7 @@ func TestInvalidUnmarshalText(t *testing.T) {
// Test that string option is ignored for invalid types.
// Issue 9812.
func TestInvalidStringOption(t *testing.T) {
+ t.Parallel() // MODIFIED: added
num := 0
item := struct {
T time.Time `json:",string"` //nolint:staticcheck // testing handling of bad options // MODIFIED: added nolint annotation
@@ -2245,6 +2274,7 @@ func TestInvalidStringOption(t *testing.T) {
// (Issue 28145) If the embedded struct is given an explicit name and has
// exported methods, don't cause a panic trying to get its value.
func TestUnmarshalEmbeddedUnexported(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type (
embed1 struct{ Q int }
embed2 struct{ Q int }
@@ -2366,6 +2396,7 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) {
}
func TestUnmarshalErrorAfterMultipleJSON(t *testing.T) {
+ t.Parallel() // MODIFIED: added
tests := []struct {
in string
err error
@@ -2405,6 +2436,7 @@ type unmarshalPanic struct{}
func (unmarshalPanic) UnmarshalJSON([]byte) error { panic(0xdead) }
func TestUnmarshalPanic(t *testing.T) {
+ t.Parallel() // MODIFIED: added
defer func() {
if got := recover(); !reflect.DeepEqual(got, 0xdead) {
t.Errorf("panic() = (%T)(%v), want 0xdead", got, got)
@@ -2417,6 +2449,7 @@ func TestUnmarshalPanic(t *testing.T) {
// The decoder used to hang if decoding into an interface pointing to its own address.
// See golang.org/issues/31740.
func TestUnmarshalRecursivePointer(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var v any
v = &v
data := []byte(`{"a": "b"}`)
@@ -2436,6 +2469,7 @@ func (m *textUnmarshalerString) UnmarshalText(text []byte) error {
// Test unmarshal to a map, where the map key is a user defined type.
// See golang.org/issues/34437.
func TestUnmarshalMapWithTextUnmarshalerStringKey(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var p map[textUnmarshalerString]string
if err := Unmarshal([]byte(`{"FOO": "1"}`), &p); err != nil {
t.Fatalf("Unmarshal unexpected error: %v", err)
@@ -2447,6 +2481,7 @@ func TestUnmarshalMapWithTextUnmarshalerStringKey(t *testing.T) {
}
func TestUnmarshalRescanLiteralMangledUnquote(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// See golang.org/issues/38105.
var p map[textUnmarshalerString]string
if err := Unmarshal([]byte(`{"开源":"12345开源"}`), &p); err != nil {
@@ -2492,6 +2527,7 @@ func TestUnmarshalRescanLiteralMangledUnquote(t *testing.T) {
}
func TestUnmarshalMaxDepth(t *testing.T) {
+ t.Parallel() // MODIFIED: added
testcases := []struct {
name string
data string
@@ -2568,8 +2604,11 @@ func TestUnmarshalMaxDepth(t *testing.T) {
}
for _, tc := range testcases {
+ tc := tc // MODIFIED: added
for _, target := range targets {
+ target := target // MODIFIED: added
t.Run(target.name+"-"+tc.name, func(t *testing.T) {
+ t.Parallel() // MODIFIED: added
err := Unmarshal([]byte(tc.data), target.newValue())
if !tc.errMaxDepth {
if err != nil {