github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/value_tests/error_test.go (about)

     1  package test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/bingoohuang/gg/pkg/jsoni"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func Test_errorInput(t *testing.T) {
    12  	for _, testCase := range unmarshalCases {
    13  		if testCase.obj != nil {
    14  			continue
    15  		}
    16  		valType := reflect.TypeOf(testCase.ptr).Elem()
    17  		t.Run(valType.String(), func(t *testing.T) {
    18  			for _, data := range []string{
    19  				`x`,
    20  				`n`,
    21  				`nul`,
    22  				`{x}`,
    23  				`{"x"}`,
    24  				`{"x": "y"x}`,
    25  				`{"x": "y"`,
    26  				`{"x": "y", "a"}`,
    27  				`[`,
    28  				`[{"x": "y"}`,
    29  			} {
    30  				ptrVal := reflect.New(valType)
    31  				ptr := ptrVal.Interface()
    32  				err := jsoni.ConfigCompatibleWithStandardLibrary.Unmarshal(nil, []byte(data), ptr)
    33  				require.Error(t, err, "on input %q", data)
    34  			}
    35  		})
    36  	}
    37  }