Skip to content

Commit 2b49e3e

Browse files
add tests
1 parent 7f07f7a commit 2b49e3e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

table/types/cast_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"math/big"
5+
"strconv"
56
"testing"
67

78
"github.com/stretchr/testify/require"
@@ -87,3 +88,32 @@ func TestToDecimal(t *testing.T) {
8788
})
8889
}
8990
}
91+
92+
func TestDecimalParse(t *testing.T) {
93+
for i, tt := range []struct {
94+
raw string
95+
literal string
96+
err bool
97+
}{
98+
{
99+
raw: "-1234567.890123456",
100+
literal: `Decimal("-1234567.890123456",22,9)`,
101+
err: false,
102+
},
103+
{
104+
raw: "not a decimal",
105+
literal: ``,
106+
err: true,
107+
},
108+
} {
109+
t.Run(strconv.Itoa(i)+"."+tt.raw, func(t *testing.T) {
110+
dec, err := DecimalValueFromString(tt.raw, 22, 9)
111+
if err != nil {
112+
require.True(t, tt.err)
113+
require.Nil(t, dec)
114+
} else {
115+
require.Equal(t, tt.literal, dec.Yql())
116+
}
117+
})
118+
}
119+
}

0 commit comments

Comments
 (0)