From 0c6eaeda9ff5ede223c1ac4ed0160433abfd8294 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Wed, 12 Jul 2023 01:08:09 +0800 Subject: [PATCH] chore: coding style (#3413) --- core/mapping/unmarshaler.go | 7 ++++--- core/mapping/unmarshaler_test.go | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go index 24920338..a346469e 100644 --- a/core/mapping/unmarshaler.go +++ b/core/mapping/unmarshaler.go @@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type target.SetFloat(fValue) default: - return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String()) + return newTypeMismatchErrorWithHint(fullName, typeKind.String(), value.Type().String()) } SetValue(fieldType, value, target) @@ -1054,8 +1054,9 @@ func newTypeMismatchError(name string) error { return fmt.Errorf("type mismatch for field %q", name) } -func newTypeMismatchErrorWithHint(name, errorType, rightType string) error { - return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType) +func newTypeMismatchErrorWithHint(name, expectType, actualType string) error { + return fmt.Errorf("type mismatch for field %q, expect %q, actual %q", + name, expectType, actualType) } func readKeys(key string) []string { diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go index fae6f3ef..8739d49b 100644 --- a/core/mapping/unmarshaler_test.go +++ b/core/mapping/unmarshaler_test.go @@ -4991,10 +4991,12 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) { value := reflect.ValueOf(&realValue) // pass a pointer to the value v := json.Number(expectValue) 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.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) { expectValue := int64(1) realValue := int64(1) @@ -5002,10 +5004,10 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) { value := reflect.ValueOf(&realValue) // pass a pointer to the value v := json.Number(strconv.FormatInt(expectValue, 10)) 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) }) - } func TestGetValueWithChainedKeys(t *testing.T) {