Skip to content

Commit 00c7f21

Browse files
committed
added test
1 parent 97128eb commit 00c7f21

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

table/types/cast_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package types
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestToDecimal(t *testing.T) {
11+
for _, tt := range []struct {
12+
v Value
13+
d *Decimal
14+
err bool
15+
}{
16+
{
17+
v: DecimalValue(&Decimal{
18+
Bytes: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5},
19+
Precision: 22,
20+
Scale: 9,
21+
}),
22+
d: &Decimal{
23+
Bytes: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5},
24+
Precision: 22,
25+
Scale: 9,
26+
},
27+
err: false,
28+
},
29+
{
30+
v: DecimalValueFromBigInt(big.NewInt(123456789), 22, 9),
31+
d: &Decimal{
32+
Bytes: [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 91, 205, 21},
33+
Precision: 22,
34+
Scale: 9,
35+
},
36+
err: false,
37+
},
38+
{
39+
v: Uint64Value(0),
40+
d: nil,
41+
err: true,
42+
},
43+
} {
44+
t.Run("", func(t *testing.T) {
45+
d, err := ToDecimal(tt.v)
46+
if tt.err {
47+
require.Error(t, err)
48+
} else {
49+
require.NoError(t, err)
50+
require.Equal(t, tt.d, d)
51+
}
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)