chore: coding style (#3413)

This commit is contained in:
Kevin Wan 2023-07-12 01:08:09 +08:00 committed by GitHub
parent b9c0c0f8b5
commit 0c6eaeda9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
target.SetFloat(fValue) target.SetFloat(fValue)
default: default:
return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String()) return newTypeMismatchErrorWithHint(fullName, typeKind.String(), value.Type().String())
} }
SetValue(fieldType, value, target) SetValue(fieldType, value, target)
@ -1054,8 +1054,9 @@ func newTypeMismatchError(name string) error {
return fmt.Errorf("type mismatch for field %q", name) return fmt.Errorf("type mismatch for field %q", name)
} }
func newTypeMismatchErrorWithHint(name, errorType, rightType string) error { func newTypeMismatchErrorWithHint(name, expectType, actualType string) error {
return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType) return fmt.Errorf("type mismatch for field %q, expect %q, actual %q",
name, expectType, actualType)
} }
func readKeys(key string) []string { func readKeys(key string) []string {

View File

@ -4991,10 +4991,12 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
value := reflect.ValueOf(&realValue) // pass a pointer to the value value := reflect.ValueOf(&realValue) // pass a pointer to the value
v := json.Number(expectValue) v := json.Number(expectValue)
m := NewUnmarshaler("field") m := NewUnmarshaler("field")
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field") err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
&fieldOptionsWithContext{}, "field")
assert.Error(t, err) assert.Error(t, err)
assert.Equal(t, "type mismatch for field \"field\", expected \"string\", got \"int\"", err.Error()) assert.Equal(t, `type mismatch for field "field", expect "string", actual "int"`, err.Error())
}) })
t.Run("right type", func(t *testing.T) { t.Run("right type", func(t *testing.T) {
expectValue := int64(1) expectValue := int64(1)
realValue := int64(1) realValue := int64(1)
@ -5002,10 +5004,10 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
value := reflect.ValueOf(&realValue) // pass a pointer to the value value := reflect.ValueOf(&realValue) // pass a pointer to the value
v := json.Number(strconv.FormatInt(expectValue, 10)) v := json.Number(strconv.FormatInt(expectValue, 10))
m := NewUnmarshaler("field") m := NewUnmarshaler("field")
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field") err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
&fieldOptionsWithContext{}, "field")
assert.NoError(t, err) assert.NoError(t, err)
}) })
} }
func TestGetValueWithChainedKeys(t *testing.T) { func TestGetValueWithChainedKeys(t *testing.T) {