1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-26 22:40:13 +02:00

use reflect2 to replace reflect

This commit is contained in:
Tao Wen
2018-02-22 10:12:08 +08:00
parent a3866383f5
commit 99fc16a363
22 changed files with 307 additions and 286 deletions

View File

@@ -7,4 +7,14 @@ func init() {
[1]*float64{&two},
[2]*float64{},
)
unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*[0]int)(nil),
input: `[1]`,
}, unmarshalCase{
ptr: (*[1]int)(nil),
input: `[2]`,
}, unmarshalCase{
ptr: (*[1]int)(nil),
input: `[]`,
})
}

View File

@@ -2,11 +2,11 @@ package test
import (
"testing"
"reflect"
"encoding/json"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go"
"fmt"
"github.com/v2pro/plz/reflect2"
)
type unmarshalCase struct {
@@ -42,9 +42,9 @@ func Test_unmarshal(t *testing.T) {
obj1 = testCase.obj()
obj2 = testCase.obj()
} else {
valType := reflect.TypeOf(testCase.ptr).Elem()
obj1 = reflect.New(valType).Interface()
obj2 = reflect.New(valType).Interface()
valType := reflect2.TypeOfPtr(testCase.ptr).Elem()
obj1 = valType.New()
obj2 = valType.New()
}
err1 := json.Unmarshal([]byte(testCase.input), obj1)
should.NoError(err1, "json")
@@ -66,7 +66,7 @@ func Test_marshal(t *testing.T) {
for i, testCase := range marshalCases {
var name string
if testCase != nil {
name = fmt.Sprintf("[%v]%v/%s", i, testCase, reflect.TypeOf(testCase).String())
name = fmt.Sprintf("[%v]%v/%s", i, testCase, reflect2.TypeOf(testCase).String())
}
t.Run(name, func(t *testing.T) {
should := require.New(t)