summaryrefslogtreecommitdiff
path: root/decode_scan_test.go
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 /decode_scan_test.go
parent659b2cd182132b0827484855689e3d21e8d9ce9f (diff)
.golangci.yml: Turn on 'paralleltest', fix
Diffstat (limited to 'decode_scan_test.go')
-rw-r--r--decode_scan_test.go39
1 files changed, 26 insertions, 13 deletions
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 } `),