From d39319ad51276943ff615857f8ccf74e5055e425 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 4 Oct 2023 15:48:25 -0500 Subject: [PATCH] change naming --- field/binary_test.go | 66 ++++++++++++++++++------------------ field/hex_test.go | 76 ++++++++++++++++++++--------------------- field/numeric_test.go | 79 ++++++++++++++++++++++--------------------- field/string_test.go | 79 ++++++++++++++++++++++--------------------- 4 files changed, 151 insertions(+), 149 deletions(-) diff --git a/field/binary_test.go b/field/binary_test.go index 9ae02b5..227de55 100644 --- a/field/binary_test.go +++ b/field/binary_test.go @@ -144,73 +144,73 @@ func TestBinaryNil(t *testing.T) { func TestBinaryFieldUnmarshal(t *testing.T) { testValue := []byte{0x12, 0x34, 0x56} - str := NewBinaryValue(testValue) + binaryField := NewBinaryValue(testValue) - val1 := &Binary{} - err := str.Unmarshal(val1) + vBinary := &Binary{} + err := binaryField.Unmarshal(vBinary) require.NoError(t, err) - require.Equal(t, testValue, val1.Value()) + require.Equal(t, testValue, vBinary.Value()) - var val2 string - err = str.Unmarshal(&val2) + var s string + err = binaryField.Unmarshal(&s) require.NoError(t, err) - require.Equal(t, "123456", val2) + require.Equal(t, "123456", s) - var val3 []byte - err = str.Unmarshal(&val3) + var b []byte + err = binaryField.Unmarshal(&b) require.NoError(t, err) - require.Equal(t, testValue, val3) + require.Equal(t, testValue, b) - val4 := reflect.ValueOf(&val2).Elem() - err = str.Unmarshal(val4) + refStrValue := reflect.ValueOf(&s).Elem() + err = binaryField.Unmarshal(refStrValue) require.NoError(t, err) - require.Equal(t, "123456", val4.String()) + require.Equal(t, "123456", refStrValue.String()) - val5 := reflect.ValueOf(&val3).Elem() - err = str.Unmarshal(val5) + refBytesValue := reflect.ValueOf(&b).Elem() + err = binaryField.Unmarshal(refBytesValue) require.NoError(t, err) - require.Equal(t, testValue, val5.Bytes()) + require.Equal(t, testValue, refBytesValue.Bytes()) - val6 := reflect.ValueOf(val2) - err = str.Unmarshal(val6) + refStr := reflect.ValueOf(s) + err = binaryField.Unmarshal(refStr) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type string", err.Error()) - val7 := reflect.ValueOf(&val2) - err = str.Unmarshal(val7) + refStrPointer := reflect.ValueOf(&s) + err = binaryField.Unmarshal(refStrPointer) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type ptr", err.Error()) - err = str.Unmarshal(nil) + err = binaryField.Unmarshal(nil) require.Error(t, err) require.Equal(t, "unsupported type: expected *Binary, *string, *[]byte, or reflect.Value, got ", err.Error()) } func TestBinaryFieldMarshal(t *testing.T) { testValue := []byte{0x12, 0x34, 0x56} - str := NewBinaryValue(nil) + binaryField := NewBinaryValue(nil) - vstring := "123456" - err := str.Marshal(vstring) + inputStr := "123456" + err := binaryField.Marshal(inputStr) require.NoError(t, err) - require.Equal(t, testValue, str.Value()) + require.Equal(t, testValue, binaryField.Value()) - err = str.Marshal(&vstring) + err = binaryField.Marshal(&inputStr) require.NoError(t, err) - require.Equal(t, testValue, str.Value()) + require.Equal(t, testValue, binaryField.Value()) - err = str.Marshal(testValue) + err = binaryField.Marshal(testValue) require.NoError(t, err) - require.Equal(t, testValue, str.Value()) + require.Equal(t, testValue, binaryField.Value()) - err = str.Marshal(&testValue) + err = binaryField.Marshal(&testValue) require.NoError(t, err) - require.Equal(t, testValue, str.Value()) + require.Equal(t, testValue, binaryField.Value()) - err = str.Marshal(nil) + err = binaryField.Marshal(nil) require.NoError(t, err) - err = str.Marshal(123456) + err = binaryField.Marshal(123456) require.Error(t, err) require.Equal(t, "data does not match required *Binary or (string, *string, []byte, *[]byte) type", err.Error()) } diff --git a/field/hex_test.go b/field/hex_test.go index a0c0851..3b0edcb 100644 --- a/field/hex_test.go +++ b/field/hex_test.go @@ -146,83 +146,83 @@ func TestHexPack(t *testing.T) { func TestHexFieldUnmarshal(t *testing.T) { testValue := []byte{0x12, 0x34, 0x56} - str := NewHexValue("123456") + hexField := NewHexValue("123456") - val1 := &Hex{} - err := str.Unmarshal(val1) + vHex := &Hex{} + err := hexField.Unmarshal(vHex) require.NoError(t, err) - require.Equal(t, "123456", val1.Value()) - buf, _ := val1.Bytes() + require.Equal(t, "123456", vHex.Value()) + buf, _ := vHex.Bytes() require.Equal(t, testValue, buf) - var val2 string - err = str.Unmarshal(&val2) + var s string + err = hexField.Unmarshal(&s) require.NoError(t, err) - require.Equal(t, "123456", val2) + require.Equal(t, "123456", s) - var val3 []byte - err = str.Unmarshal(&val3) + var b []byte + err = hexField.Unmarshal(&b) require.NoError(t, err) - require.Equal(t, testValue, val3) + require.Equal(t, testValue, b) - val4 := reflect.ValueOf(&val2).Elem() - err = str.Unmarshal(val4) + refStrValue := reflect.ValueOf(&s).Elem() + err = hexField.Unmarshal(refStrValue) require.NoError(t, err) - require.Equal(t, "123456", val4.String()) + require.Equal(t, "123456", refStrValue.String()) - val5 := reflect.ValueOf(&val3).Elem() - err = str.Unmarshal(val5) + refBytesValue := reflect.ValueOf(&b).Elem() + err = hexField.Unmarshal(refBytesValue) require.NoError(t, err) - require.Equal(t, testValue, val5.Bytes()) + require.Equal(t, testValue, refBytesValue.Bytes()) - val6 := reflect.ValueOf(val2) - err = str.Unmarshal(val6) + refStr := reflect.ValueOf(s) + err = hexField.Unmarshal(refStr) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type string", err.Error()) - val7 := reflect.ValueOf(&val2) - err = str.Unmarshal(val7) + refStrPointer := reflect.ValueOf(&s) + err = hexField.Unmarshal(refStrPointer) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type ptr", err.Error()) - err = str.Unmarshal(nil) + err = hexField.Unmarshal(nil) require.Error(t, err) require.Equal(t, "unsupported type: expected *Hex, *string, *[]byte, or reflect.Value, got ", err.Error()) } func TestHexFieldMarshal(t *testing.T) { testValue := []byte{0x12, 0x34, 0x56} - str := NewHexValue("") + hexField := NewHexValue("") - vstring := "123456" - err := str.Marshal(vstring) + inputStr := "123456" + err := hexField.Marshal(inputStr) require.NoError(t, err) - require.Equal(t, "123456", str.Value()) - buf, _ := str.Bytes() + require.Equal(t, "123456", hexField.Value()) + buf, _ := hexField.Bytes() require.Equal(t, testValue, buf) - err = str.Marshal(&vstring) + err = hexField.Marshal(&inputStr) require.NoError(t, err) - require.Equal(t, "123456", str.Value()) - buf, _ = str.Bytes() + require.Equal(t, "123456", hexField.Value()) + buf, _ = hexField.Bytes() require.Equal(t, testValue, buf) - err = str.Marshal(testValue) + err = hexField.Marshal(testValue) require.NoError(t, err) - require.Equal(t, "123456", str.Value()) - buf, _ = str.Bytes() + require.Equal(t, "123456", hexField.Value()) + buf, _ = hexField.Bytes() require.Equal(t, testValue, buf) - err = str.Marshal(&testValue) + err = hexField.Marshal(&testValue) require.NoError(t, err) - require.Equal(t, "123456", str.Value()) - buf, _ = str.Bytes() + require.Equal(t, "123456", hexField.Value()) + buf, _ = hexField.Bytes() require.Equal(t, testValue, buf) - err = str.Marshal(nil) + err = hexField.Marshal(nil) require.NoError(t, err) - err = str.Marshal(123456) + err = hexField.Marshal(123456) require.Error(t, err) require.Equal(t, "data does not match required *Hex or (string, *string, []byte, *[]byte) type", err.Error()) } diff --git a/field/numeric_test.go b/field/numeric_test.go index 682014e..4845013 100644 --- a/field/numeric_test.go +++ b/field/numeric_test.go @@ -89,75 +89,76 @@ func TestNumericPack(t *testing.T) { } func TestNumericFieldUnmarshal(t *testing.T) { - str := NewNumericValue(123456) + numericField := NewNumericValue(123456) - val1 := &Numeric{} - err := str.Unmarshal(val1) + vNumeric := &Numeric{} + err := numericField.Unmarshal(vNumeric) require.NoError(t, err) - require.Equal(t, 123456, val1.Value()) + require.Equal(t, 123456, vNumeric.Value()) - var val2 string - err = str.Unmarshal(&val2) + var s string + err = numericField.Unmarshal(&s) require.NoError(t, err) - require.Equal(t, "123456", val2) + require.Equal(t, "123456", s) - var val3 int - err = str.Unmarshal(&val3) + var b int + err = numericField.Unmarshal(&b) require.NoError(t, err) - require.Equal(t, 123456, val3) + require.Equal(t, 123456, b) - val4 := reflect.ValueOf(&val2).Elem() - err = str.Unmarshal(val4) + refStrValue := reflect.ValueOf(&s).Elem() + err = numericField.Unmarshal(refStrValue) require.NoError(t, err) - require.Equal(t, "123456", val4.String()) + require.Equal(t, "123456", refStrValue.String()) - val5 := reflect.ValueOf(&val3).Elem() - err = str.Unmarshal(val5) + refIntValue := reflect.ValueOf(&b).Elem() + err = numericField.Unmarshal(refIntValue) require.NoError(t, err) - require.Equal(t, 123456, int(val5.Int())) + require.Equal(t, 123456, int(refIntValue.Int())) - val6 := reflect.ValueOf(val2) - err = str.Unmarshal(val6) + refStr := reflect.ValueOf(s) + err = numericField.Unmarshal(refStr) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type string", err.Error()) - val7 := reflect.ValueOf(&val2) - err = str.Unmarshal(val7) + refStrPointer := reflect.ValueOf(&s) + err = numericField.Unmarshal(refStrPointer) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type ptr", err.Error()) - err = str.Unmarshal(nil) + err = numericField.Unmarshal(nil) require.Error(t, err) require.Equal(t, "unsupported type: expected *Numeric, *int, or reflect.Value, got ", err.Error()) } func TestNumericFieldMarshal(t *testing.T) { - str := NewNumericValue(0) - vNumeric := NewNumericValue(123456) - str.Marshal(vNumeric) - require.Equal(t, 123456, vNumeric.Value()) + numericField := NewNumericValue(0) - str.Marshal(&vNumeric) - require.Equal(t, 123456, vNumeric.Value()) + inputNumeric := NewNumericValue(123456) + numericField.Marshal(inputNumeric) + require.Equal(t, 123456, numericField.Value()) - vstring := "123456" - str.Marshal(vstring) - require.Equal(t, 123456, vNumeric.Value()) + numericField.Marshal(&inputNumeric) + require.Equal(t, 123456, numericField.Value()) - str.Marshal(&vstring) - require.Equal(t, 123456, vNumeric.Value()) + inputStr := "123456" + numericField.Marshal(inputStr) + require.Equal(t, 123456, numericField.Value()) - vint := 123456 - str.Marshal(vint) - require.Equal(t, 123456, vNumeric.Value()) + numericField.Marshal(&inputStr) + require.Equal(t, 123456, numericField.Value()) - str.Marshal(&vint) - require.Equal(t, 123456, vNumeric.Value()) + inputInt := 123456 + numericField.Marshal(inputInt) + require.Equal(t, 123456, numericField.Value()) + + numericField.Marshal(&inputInt) + require.Equal(t, 123456, numericField.Value()) - err := str.Marshal(nil) + err := numericField.Marshal(nil) require.NoError(t, err) - err = str.Marshal([]byte("123456")) + err = numericField.Marshal([]byte("123456")) require.Error(t, err) require.Equal(t, "data does not match require *Numeric or (int, *int, string, *string) type", err.Error()) } diff --git a/field/string_test.go b/field/string_test.go index a0f210b..01d1b09 100644 --- a/field/string_test.go +++ b/field/string_test.go @@ -90,75 +90,76 @@ func TestStringPack(t *testing.T) { } func TestStringFieldUnmarshal(t *testing.T) { - str := NewStringValue("123456") + stringField := NewStringValue("123456") - val1 := &String{} - err := str.Unmarshal(val1) + vString := &String{} + err := stringField.Unmarshal(vString) require.NoError(t, err) - require.Equal(t, "123456", val1.Value()) + require.Equal(t, "123456", vString.Value()) - var val2 string - err = str.Unmarshal(&val2) + var s string + err = stringField.Unmarshal(&s) require.NoError(t, err) - require.Equal(t, "123456", val2) + require.Equal(t, "123456", s) - var val3 int - err = str.Unmarshal(&val3) + var b int + err = stringField.Unmarshal(&b) require.NoError(t, err) - require.Equal(t, 123456, val3) + require.Equal(t, 123456, b) - val4 := reflect.ValueOf(&val2).Elem() - err = str.Unmarshal(val4) + refStrValue := reflect.ValueOf(&s).Elem() + err = stringField.Unmarshal(refStrValue) require.NoError(t, err) - require.Equal(t, "123456", val4.String()) + require.Equal(t, "123456", refStrValue.String()) - val5 := reflect.ValueOf(&val3).Elem() - err = str.Unmarshal(val5) + refIntValue := reflect.ValueOf(&b).Elem() + err = stringField.Unmarshal(refIntValue) require.NoError(t, err) - require.Equal(t, 123456, int(val5.Int())) + require.Equal(t, 123456, int(refIntValue.Int())) - val6 := reflect.ValueOf(val2) - err = str.Unmarshal(val6) + refStr := reflect.ValueOf(s) + err = stringField.Unmarshal(refStr) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type string", err.Error()) - val7 := reflect.ValueOf(&val2) - err = str.Unmarshal(val7) + refStrPointer := reflect.ValueOf(&s) + err = stringField.Unmarshal(refStrPointer) require.Error(t, err) require.Equal(t, "cannot set reflect.Value of type ptr", err.Error()) - err = str.Unmarshal(nil) + err = stringField.Unmarshal(nil) require.Error(t, err) require.Equal(t, "unsupported type: expected *String, *string, or reflect.Value, got ", err.Error()) } func TestStringFieldMarshal(t *testing.T) { - str := NewStringValue("") - vString := NewStringValue("123456") - str.Marshal(vString) - require.Equal(t, "123456", str.Value()) + stringField := NewStringValue("") - str.Marshal(&vString) - require.Equal(t, "123456", str.Value()) + inputString := NewStringValue("123456") + stringField.Marshal(inputString) + require.Equal(t, "123456", stringField.Value()) - vstring := "123456" - str.Marshal(vstring) - require.Equal(t, "123456", str.Value()) + stringField.Marshal(&inputString) + require.Equal(t, "123456", stringField.Value()) - str.Marshal(&vstring) - require.Equal(t, "123456", str.Value()) + inputStr := "123456" + stringField.Marshal(inputStr) + require.Equal(t, "123456", stringField.Value()) - vint := 123456 - str.Marshal(vint) - require.Equal(t, "123456", str.Value()) + stringField.Marshal(&inputStr) + require.Equal(t, "123456", stringField.Value()) - str.Marshal(&vint) - require.Equal(t, "123456", str.Value()) + inputInt := 123456 + stringField.Marshal(inputInt) + require.Equal(t, "123456", stringField.Value()) - err := str.Marshal(nil) + stringField.Marshal(&inputInt) + require.Equal(t, "123456", stringField.Value()) + + err := stringField.Marshal(nil) require.NoError(t, err) - err = str.Marshal([]byte("123456")) + err = stringField.Marshal([]byte("123456")) require.Error(t, err) require.Equal(t, "data does not match required *String or (string, *string, int, *int) type", err.Error()) }