summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-27 00:02:29 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-29 02:14:51 -0700
commitbdfb423cbaff683269c7448afe6d93d224c5a482 (patch)
tree2f10c3a13f56f94e498b8e3aac3e519a91d86518
parent659b2cd182132b0827484855689e3d21e8d9ce9f (diff)
.golangci.yml: Turn on 'paralleltest', fix
-rw-r--r--.golangci.yml1
-rw-r--r--compat/json/borrowed_decode_test.go39
-rw-r--r--compat/json/borrowed_encode_test.go29
-rw-r--r--compat/json/borrowed_number_test.go1
-rw-r--r--compat/json/borrowed_scanner_test.go12
-rw-r--r--compat/json/borrowed_stream_test.go9
-rw-r--r--compat/json/borrowed_tagkey_test.go1
-rw-r--r--compat/json/borrowed_tags_test.go1
-rw-r--r--decode_scan_test.go39
-rw-r--r--decode_test.go2
-rw-r--r--encode_test.go3
-rw-r--r--methods_test.go1
-rw-r--r--reencode_test.go5
13 files changed, 128 insertions, 15 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 0e81d1f..f9e1160 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -54,7 +54,6 @@ linters:
- gomnd
- ireturn
- lll
- - paralleltest
- prealloc
- revive
- stylecheck
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 {
diff --git a/compat/json/borrowed_encode_test.go b/compat/json/borrowed_encode_test.go
index 2b14032..3d5d675 100644
--- a/compat/json/borrowed_encode_test.go
+++ b/compat/json/borrowed_encode_test.go
@@ -59,6 +59,7 @@ var optionalsExpected = `{
}`
func TestOmitEmpty(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var o Optionals
o.Sw = "something"
o.Mr = map[string]any{}
@@ -82,6 +83,7 @@ type StringTag struct {
}
func TestRoundtripStringTag(t *testing.T) {
+ t.Parallel() // MODIFIED: added
tests := []struct {
name string
in StringTag
@@ -121,7 +123,9 @@ func TestRoundtripStringTag(t *testing.T) {
},
}
for _, test := range tests {
+ test := test // MODIFIED: added
t.Run(test.name, func(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// Indent with a tab prefix to make the multi-line string
// literals in the table nicer to read.
got, err := MarshalIndent(&test.in, "\t\t\t", "\t")
@@ -150,6 +154,7 @@ type renamedByteSlice []byte
type renamedRenamedByteSlice []renamedByte
func TestEncodeRenamedByteSlice(t *testing.T) {
+ t.Parallel() // MODIFIED: added
s := renamedByteSlice("abc")
result, err := Marshal(s)
if err != nil {
@@ -213,12 +218,14 @@ func init() {
}
func TestSamePointerNoCycle(t *testing.T) {
+ t.Parallel() // MODIFIED: added
if _, err := Marshal(samePointerNoCycle); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
func TestSliceNoCycle(t *testing.T) {
+ t.Parallel() // MODIFIED: added
if _, err := Marshal(sliceNoCycle); err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -236,6 +243,7 @@ var unsupportedValues = []any{
}
func TestUnsupportedValues(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, v := range unsupportedValues {
if _, err := Marshal(v); err != nil {
if _, ok := err.(*UnsupportedValueError); !ok {
@@ -249,6 +257,7 @@ func TestUnsupportedValues(t *testing.T) {
// Issue 43207
func TestMarshalTextFloatMap(t *testing.T) {
+ t.Parallel() // MODIFIED: added
m := map[textfloat]string{
textfloat(math.NaN()): "1",
textfloat(math.NaN()): "1",
@@ -302,6 +311,7 @@ func (ValText) MarshalText() ([]byte, error) {
}
func TestRefValMarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var s = struct {
R0 Ref
R1 *Ref
@@ -346,6 +356,7 @@ func (CText) MarshalText() ([]byte, error) {
}
func TestMarshalerEscaping(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var c C
want := `"\u003c\u0026\u003e"`
b, err := Marshal(c)
@@ -368,6 +379,7 @@ func TestMarshalerEscaping(t *testing.T) {
}
func TestAnonymousFields(t *testing.T) {
+ t.Parallel() // MODIFIED: added
tests := []struct {
label string // Test name
makeInput func() any // Function to create input value
@@ -532,7 +544,9 @@ func TestAnonymousFields(t *testing.T) {
}}
for _, tt := range tests {
+ tt := tt // MODIFIED: added
t.Run(tt.label, func(t *testing.T) {
+ t.Parallel() // MODIFIED: added
b, err := Marshal(tt.makeInput())
if err != nil {
t.Fatalf("Marshal() = %v, want nil error", err)
@@ -590,6 +604,7 @@ func (nm *nilTextMarshaler) MarshalText() ([]byte, error) {
// See golang.org/issue/16042 and golang.org/issue/34235.
func TestNilMarshal(t *testing.T) {
+ t.Parallel() // MODIFIED: added
testCases := []struct {
v any
want string
@@ -620,6 +635,7 @@ func TestNilMarshal(t *testing.T) {
// Issue 5245.
func TestEmbeddedBug(t *testing.T) {
+ t.Parallel() // MODIFIED: added
v := BugB{
BugA{"A"},
"B",
@@ -660,6 +676,7 @@ type BugY struct {
// Test that a field with a tag dominates untagged fields.
func TestTaggedFieldDominates(t *testing.T) {
+ t.Parallel() // MODIFIED: added
v := BugY{
BugA{"BugA"},
BugD{"BugD"},
@@ -683,6 +700,7 @@ type BugZ struct {
}
func TestDuplicatedFieldDisappears(t *testing.T) {
+ t.Parallel() // MODIFIED: added
v := BugZ{
BugA{"BugA"},
BugC{"BugC"},
@@ -751,6 +769,7 @@ func TestStringBytes(t *testing.T) {
}
func TestIssue10281(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type Foo struct {
N Number
}
@@ -763,6 +782,7 @@ func TestIssue10281(t *testing.T) {
}
func TestHTMLEscape(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var b, want bytes.Buffer
m := `{"M":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}`
want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`))
@@ -774,6 +794,7 @@ func TestHTMLEscape(t *testing.T) {
// golang.org/issue/8582
func TestEncodePointerString(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type stringPointer struct {
N *int64 `json:"n,string"`
}
@@ -837,6 +858,7 @@ var encodeStringTests = []struct {
}
func TestEncodeString(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range encodeStringTests {
b, err := Marshal(tt.in)
if err != nil {
@@ -878,6 +900,7 @@ func (f textfloat) MarshalText() ([]byte, error) { return tenc(`TF:%0.2f`, f) }
// Issue 13783
func TestEncodeBytekind(t *testing.T) {
+ t.Parallel() // MODIFIED: added
testdata := []struct {
data any
want string
@@ -910,6 +933,7 @@ func TestEncodeBytekind(t *testing.T) {
}
func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
+ t.Parallel() // MODIFIED: added
b, err := Marshal(map[unmarshalerText]int{
{"x", "y"}: 1,
{"y", "x"}: 2,
@@ -927,6 +951,7 @@ func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
// https://golang.org/issue/33675
func TestNilMarshalerTextMapKey(t *testing.T) {
+ t.Parallel() // MODIFIED: added
b, err := Marshal(map[*unmarshalerText]int{
(*unmarshalerText)(nil): 1,
{"A", "B"}: 2,
@@ -1048,6 +1073,7 @@ func TestMarshalFloat(t *testing.T) {
}
func TestMarshalRawMessageValue(t *testing.T) {
+ t.Parallel() // MODIFIED: added
type (
T1 struct {
M RawMessage `json:",omitempty"`
@@ -1153,6 +1179,7 @@ type marshalPanic struct{}
func (marshalPanic) MarshalJSON() ([]byte, error) { panic(0xdead) }
func TestMarshalPanic(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)
@@ -1163,6 +1190,7 @@ func TestMarshalPanic(t *testing.T) {
}
func TestMarshalUncommonFieldNames(t *testing.T) {
+ t.Parallel() // MODIFIED: added
v := struct {
A0, À, Aβ int
}{}
@@ -1178,6 +1206,7 @@ func TestMarshalUncommonFieldNames(t *testing.T) {
}
func TestMarshalerError(t *testing.T) {
+ t.Parallel() // MODIFIED: added
s := "test variable"
st := reflect.TypeOf(s)
errText := "json: test error"
diff --git a/compat/json/borrowed_number_test.go b/compat/json/borrowed_number_test.go
index f18f74e..e7819c6 100644
--- a/compat/json/borrowed_number_test.go
+++ b/compat/json/borrowed_number_test.go
@@ -12,6 +12,7 @@ import (
)
func TestNumberIsValid(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// From: https://stackoverflow.com/a/13340826
var jsonNumberRegexp = regexp.MustCompile(`^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$`)
diff --git a/compat/json/borrowed_scanner_test.go b/compat/json/borrowed_scanner_test.go
index 64d3318..c68fd8f 100644
--- a/compat/json/borrowed_scanner_test.go
+++ b/compat/json/borrowed_scanner_test.go
@@ -11,6 +11,7 @@ import (
"math"
"math/rand"
"reflect"
+ "sync" // MODIFIED: added
"testing"
)
@@ -27,6 +28,7 @@ var validTests = []struct {
}
func TestValid(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range validTests {
if ok := Valid([]byte(tt.data)); ok != tt.ok {
t.Errorf("Valid(%#q) = %v, want %v", tt.data, ok, tt.ok)
@@ -67,6 +69,7 @@ var ex1i = `[
]`
func TestCompact(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var buf bytes.Buffer
for _, tt := range examples {
buf.Reset()
@@ -87,6 +90,7 @@ func TestCompact(t *testing.T) {
}
func TestCompactSeparators(t *testing.T) {
+ t.Parallel() // MODIFIED: added
// U+2028 and U+2029 should be escaped inside strings.
// They should not appear outside strings.
tests := []struct {
@@ -106,6 +110,7 @@ func TestCompactSeparators(t *testing.T) {
}
func TestIndent(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var buf bytes.Buffer
for _, tt := range examples {
buf.Reset()
@@ -128,6 +133,7 @@ func TestIndent(t *testing.T) {
// Tests of a large random structure.
func TestCompactBig(t *testing.T) {
+ t.Parallel() // MODIFIED: added
initBig()
var buf bytes.Buffer
if err := Compact(&buf, jsonBig); err != nil {
@@ -191,6 +197,7 @@ var indentErrorTests = []indentErrorTest{
}
func TestIndentErrors(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for i, tt := range indentErrorTests {
slice := make([]uint8, 0)
buf := bytes.NewBuffer(slice)
@@ -227,7 +234,12 @@ func trim(b []byte) []byte {
var jsonBig []byte
+var jsonBigOnce sync.Once
+
func initBig() {
+ jsonBigOnce.Do(realInitBig) // MODIFIED: added
+} // MODIFIED: added
+func realInitBig() { // MODIFIED: added
n := 10000
if testing.Short() {
n = 100
diff --git a/compat/json/borrowed_stream_test.go b/compat/json/borrowed_stream_test.go
index 80f6f03..6c3a403 100644
--- a/compat/json/borrowed_stream_test.go
+++ b/compat/json/borrowed_stream_test.go
@@ -41,6 +41,7 @@ false
`
func TestEncoder(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for i := 0; i <= len(streamTest); i++ {
var buf bytes.Buffer
enc := NewEncoder(&buf)
@@ -78,6 +79,7 @@ false
`
func TestEncoderIndent(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var buf bytes.Buffer
enc := NewEncoder(&buf)
enc.SetIndent(">", ".")
@@ -105,6 +107,7 @@ func (s *strPtrMarshaler) MarshalJSON() ([]byte, error) {
}
func TestEncoderSetEscapeHTML(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var c C
var ct CText
var tagStruct struct {
@@ -173,6 +176,7 @@ func TestEncoderSetEscapeHTML(t *testing.T) {
}
func TestDecoder(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for i := 0; i <= len(streamTest); i++ {
// Use stream without newlines as input,
// just to stress the decoder even more.
@@ -205,6 +209,7 @@ func TestDecoder(t *testing.T) {
}
func TestDecoderBuffered(t *testing.T) {
+ t.Parallel() // MODIFIED: added
r := strings.NewReader(`{"Name": "Gopher"} extra `)
var m struct {
Name string
@@ -241,6 +246,7 @@ func nlines(s string, n int) string {
}
func TestRawMessage(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var data struct {
X float64
Id RawMessage
@@ -265,6 +271,7 @@ func TestRawMessage(t *testing.T) {
}
func TestNullRawMessage(t *testing.T) {
+ t.Parallel() // MODIFIED: added
var data struct {
X float64
Id RawMessage
@@ -297,6 +304,7 @@ var blockingTests = []string{
}
func TestBlocking(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, enc := range blockingTests {
r, w := net.Pipe()
ch := make(chan error) // MODIFIED: added
@@ -451,6 +459,7 @@ func TestDecodeInStream(t *testing.T) {
// Test from golang.org/issue/11893
func TestHTTPDecoding(t *testing.T) {
+ t.Parallel() // MODIFIED: added
const raw = `{ "foo": "bar" }`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/compat/json/borrowed_tagkey_test.go b/compat/json/borrowed_tagkey_test.go
index d48cc67..07139cf 100644
--- a/compat/json/borrowed_tagkey_test.go
+++ b/compat/json/borrowed_tagkey_test.go
@@ -99,6 +99,7 @@ var structTagObjectKeyTests = []struct {
}
func TestStructTagObjectKey(t *testing.T) {
+ t.Parallel() // MODIFIED: added
for _, tt := range structTagObjectKeyTests {
b, err := Marshal(tt.raw)
if err != nil {
diff --git a/compat/json/borrowed_tags_test.go b/compat/json/borrowed_tags_test.go
index 71d26e1..e48df0a 100644
--- a/compat/json/borrowed_tags_test.go
+++ b/compat/json/borrowed_tags_test.go
@@ -11,6 +11,7 @@ import (
)
func TestTagParsing(t *testing.T) {
+ t.Parallel() // MODIFIED: added
name, opts := parseTag("field,foobar,foo")
if name != "field" {
t.Fatalf("name = %q, want field", name)
diff --git a/decode_scan_test.go b/decode_scan_test.go
index ac8c2fc..5d1542f 100644
--- a/decode_scan_test.go
+++ b/decode_scan_test.go
@@ -35,7 +35,9 @@ type runeTypeScannerTestcase struct {
func testRuneTypeScanner(t *testing.T, testcases map[string]runeTypeScannerTestcase, factory func(io.RuneScanner) runeTypeScanner) {
for tcName, tc := range testcases {
+ tc := tc
t.Run(tcName, func(t *testing.T) {
+ t.Parallel()
reader := strings.NewReader(tc.Input)
sc := factory(reader)
var exp, act []string
@@ -57,6 +59,7 @@ func testRuneTypeScanner(t *testing.T, testcases map[string]runeTypeScannerTestc
}
func TestRuneTypeScanner(t *testing.T) {
+ t.Parallel()
testcases := map[string]runeTypeScannerTestcase{
"basic": {`{"foo": 12.0}`, ``, []ReadRuneTypeResult{
{'{', 1, internal.RuneTypeObjectBeg, nil},
@@ -168,6 +171,7 @@ func TestRuneTypeScanner(t *testing.T) {
}
func TestNoWSRuneTypeScanner(t *testing.T) {
+ t.Parallel()
testcases := map[string]runeTypeScannerTestcase{
"basic": {`{"foo": 12.0}`, ``, []ReadRuneTypeResult{
{'{', 1, internal.RuneTypeObjectBeg, nil},
@@ -242,7 +246,8 @@ func TestNoWSRuneTypeScanner(t *testing.T) {
}
func TestElemRuneTypeScanner(t *testing.T) {
- testcases := map[string]runeTypeScannerTestcase{
+ t.Parallel()
+ toplevelTestcases := map[string]runeTypeScannerTestcase{
"basic": {`1`, ``, []ReadRuneTypeResult{
{'1', 1, internal.RuneTypeNumberIntDig, nil},
{0, 0, internal.RuneTypeEOF, nil},
@@ -277,8 +282,24 @@ func TestElemRuneTypeScanner(t *testing.T) {
{0, 0, internal.RuneTypeError, &DecodeSyntaxError{Offset: 1, Err: io.ErrUnexpectedEOF}},
}},
}
+
+ childTestcases := make(map[string]runeTypeScannerTestcase, len(toplevelTestcases))
+ for tcName, tc := range toplevelTestcases {
+ tc.Input = `[` + tc.Input
+ tc.Exp = append([]ReadRuneTypeResult(nil), tc.Exp...) // copy
+ for i, res := range tc.Exp {
+ if se, ok := res.e.(*DecodeSyntaxError); ok {
+ seCopy := *se
+ seCopy.Offset++
+ tc.Exp[i].e = &seCopy
+ }
+ }
+ childTestcases[tcName] = tc
+ }
+
t.Run("top-level", func(t *testing.T) {
- testRuneTypeScanner(t, testcases, func(reader io.RuneScanner) runeTypeScanner {
+ t.Parallel()
+ testRuneTypeScanner(t, toplevelTestcases, func(reader io.RuneScanner) runeTypeScanner {
return &elemRuneTypeScanner{
inner: &noWSRuneTypeScanner{
inner: &runeTypeScannerImpl{
@@ -288,18 +309,9 @@ func TestElemRuneTypeScanner(t *testing.T) {
}
})
})
-
- for tcName, tc := range testcases {
- tc.Input = `[` + tc.Input
- for _, res := range tc.Exp {
- if se, ok := res.e.(*DecodeSyntaxError); ok {
- se.Offset++
- }
- }
- testcases[tcName] = tc
- }
t.Run("child", func(t *testing.T) {
- testRuneTypeScanner(t, testcases, func(reader io.RuneScanner) runeTypeScanner {
+ t.Parallel()
+ testRuneTypeScanner(t, childTestcases, func(reader io.RuneScanner) runeTypeScanner {
inner := &noWSRuneTypeScanner{
inner: &runeTypeScannerImpl{
inner: reader,
@@ -319,6 +331,7 @@ func TestElemRuneTypeScanner(t *testing.T) {
}
func TestElemRuneTypeScanner2(t *testing.T) {
+ t.Parallel()
parent := &noWSRuneTypeScanner{
inner: &runeTypeScannerImpl{
inner: strings.NewReader(` { "foo" : 12.0 } `),
diff --git a/decode_test.go b/decode_test.go
index 90729fa..73ce903 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -13,6 +13,7 @@ import (
)
func TestDecodeNumber(t *testing.T) {
+ t.Parallel()
r := strings.NewReader(`1{}`)
var num int
@@ -22,6 +23,7 @@ func TestDecodeNumber(t *testing.T) {
}
func TestDecodeObject(t *testing.T) {
+ t.Parallel()
err := DecodeObject(strings.NewReader(`{"foo":9}`),
func(r io.RuneScanner) error {
return nil
diff --git a/encode_test.go b/encode_test.go
index e50ddd0..df12582 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -12,6 +12,7 @@ import (
)
func TestEncoder(t *testing.T) {
+ t.Parallel()
var out strings.Builder
enc := NewEncoder(&out)
@@ -24,6 +25,7 @@ func TestEncoder(t *testing.T) {
}
func TestEncoderIndent(t *testing.T) {
+ t.Parallel()
var out strings.Builder
enc := NewEncoder(&ReEncoder{
Out: &out,
@@ -41,6 +43,7 @@ func TestEncoderIndent(t *testing.T) {
}
func TestEncode(t *testing.T) {
+ t.Parallel()
var out strings.Builder
assert.NoError(t, NewEncoder(&out).Encode(1))
diff --git a/methods_test.go b/methods_test.go
index 3a5254f..5e2209a 100644
--- a/methods_test.go
+++ b/methods_test.go
@@ -100,6 +100,7 @@ func (sg *SumRunWithGaps) DecodeJSON(r io.RuneScanner) error {
}
func TestMethods(t *testing.T) {
+ t.Parallel()
in := SumRunWithGaps{
Addr: 13631488,
Size: 416033783808,
diff --git a/reencode_test.go b/reencode_test.go
index 7f1634f..f4b962f 100644
--- a/reencode_test.go
+++ b/reencode_test.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -12,6 +12,7 @@ import (
)
func TestReEncode(t *testing.T) {
+ t.Parallel()
type testcase struct {
enc ReEncoder
in any
@@ -121,7 +122,9 @@ func TestReEncode(t *testing.T) {
},
}
for tcName, tc := range testcases {
+ tc := tc
t.Run(tcName, func(t *testing.T) {
+ t.Parallel()
var out strings.Builder
fmter := tc.enc
fmter.Out = &out