Skip to content

Commit

Permalink
more test coverage for decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
denisenkom committed Sep 12, 2019
1 parent 29d79fd commit 19fca52
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/decimal/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func TestFromInt64(t *testing.T) {
{12345, 3, "12.345"},
{math.MaxInt64, 0, "9223372036854775807"},
{math.MinInt64, 0, "-9223372036854775808"},
{-100, 0, "-100"},
}
for _, v := range values {
dec := Int64ToDecimalScale(v.in, v.scale)
Expand Down Expand Up @@ -156,3 +157,27 @@ func TestFromString(t *testing.T) {
}
}
}

func TestFromStringBad(t *testing.T) {
arr := make([]rune, 256)
for i := range arr {
arr[i] = '0'
}
bigScaleNumber := "0." + string(arr) + "1"

values := []struct {
in string
scale uint8
}{
{"0.0001", 2},
{bigScaleNumber, 2},
{"not a number", 2},
{"400000000000000000000000000000000000000", 2},
}
for _, v := range values {
_, err := StringToDecimalScale(v.in, v.scale)
if err == nil {
t.Error("expected to fail but it didn't")
}
}
}

0 comments on commit 19fca52

Please sign in to comment.