github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/skip_tests/skip_test.go (about) 1 package skip_tests 2 3 import ( 4 "encoding/json" 5 "errors" 6 "io" 7 "reflect" 8 "testing" 9 10 "github.com/bingoohuang/gg/pkg/jsoni" 11 "github.com/stretchr/testify/require" 12 ) 13 14 type testCase struct { 15 ptr interface{} 16 inputs []string 17 } 18 19 var testCases []testCase 20 21 func Test_skip(t *testing.T) { 22 for _, testCase := range testCases { 23 valType := reflect.TypeOf(testCase.ptr).Elem() 24 for _, input := range testCase.inputs { 25 t.Run(input, func(t *testing.T) { 26 should := require.New(t) 27 ptrVal := reflect.New(valType) 28 stdErr := json.Unmarshal([]byte(input), ptrVal.Interface()) 29 iter := jsoni.ParseString(jsoni.ConfigDefault, input) 30 iter.Skip() 31 iter.ReadNil() // trigger looking forward 32 err := iter.Error 33 if err == io.EOF { 34 err = nil 35 } else { 36 err = errors.New("remaining bytes") 37 } 38 if stdErr == nil { 39 should.Nil(err) 40 } else { 41 should.NotNil(err) 42 } 43 }) 44 } 45 } 46 }