Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jan 4, 2025
1 parent fb4c5e0 commit e6ba2bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/typing/converters/string_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func (IntegerConverter) Convert(value any) (string, error) {
return fmt.Sprint(BooleanToBit(parsedVal)), nil
case int, int8, int16, int32, int64:
return fmt.Sprint(parsedVal), nil
case *decimal.Decimal:
return parsedVal.String(), nil
default:
return "", fmt.Errorf("unexpected value: '%v', type: %T", value, value)
}
Expand All @@ -175,6 +177,8 @@ func (FloatConverter) Convert(value any) (string, error) {
return Float64ToString(parsedVal), nil
case int, int8, int16, int32, int64:
return fmt.Sprint(parsedVal), nil
case *decimal.Decimal:
return parsedVal.String(), nil
default:
return "", fmt.Errorf("unexpected value: '%v', type: %T", value, value)
}
Expand Down
12 changes: 12 additions & 0 deletions lib/typing/converters/string_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func TestFloatConverter_Convert(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "123.45", val)
}
{
// *decimal.Decimal
val, err := FloatConverter{}.Convert(decimal.NewDecimal(numbers.MustParseDecimal("123.45")))
assert.NoError(t, err)
assert.Equal(t, "123.45", val)
}
{
// Integers
for _, input := range []any{42, int8(42), int16(42), int32(42), int64(42), float32(42), float64(42)} {
Expand All @@ -160,6 +166,12 @@ func TestIntegerConverter_Convert(t *testing.T) {
assert.Equal(t, "42", parsedVal)
}
}
{
// Test decimal.Decimal
val, err := IntegerConverter{}.Convert(decimal.NewDecimal(numbers.MustParseDecimal("123")))
assert.NoError(t, err)
assert.Equal(t, "123", val)
}
{
// Booleans
{
Expand Down

0 comments on commit e6ba2bc

Please sign in to comment.