File: error_test.go

package info (click to toggle)
golang-github-json-iterator-go 1.1.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 916 kB
  • sloc: sh: 19; makefile: 3
file content (36 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package test

import (
	"github.com/json-iterator/go"
	"github.com/stretchr/testify/require"
	"reflect"
	"testing"
)

func Test_errorInput(t *testing.T) {
	for _, testCase := range unmarshalCases {
		if testCase.obj != nil {
			continue
		}
		valType := reflect.TypeOf(testCase.ptr).Elem()
		t.Run(valType.String(), func(t *testing.T) {
			for _, data := range []string{
				`x`,
				`n`,
				`nul`,
				`{x}`,
				`{"x"}`,
				`{"x": "y"x}`,
				`{"x": "y"`,
				`{"x": "y", "a"}`,
				`[`,
				`[{"x": "y"}`,
			} {
				ptrVal := reflect.New(valType)
				ptr := ptrVal.Interface()
				err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(data), ptr)
				require.Error(t, err, "on input %q", data)
			}
		})
	}
}