Skip to content

Commit 1dcffca

Browse files
test(unit): types.IsOptional
1 parent 78465f7 commit 1dcffca

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

table/types/cast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func CastTo(v Value, dst interface{}) error {
1818
return value.CastTo(v, dst)
1919
}
2020

21+
// IsOptional checks if type is optional and returns innerType if it is.
2122
func IsOptional(t Type) (isOptional bool, innerType Type) {
2223
if optionalType, isOptional := t.(interface {
2324
IsOptional()

table/types/cast_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ import (
77
"github.com/stretchr/testify/require"
88
)
99

10+
func TestIsOptional(t *testing.T) {
11+
for _, tt := range []struct {
12+
t Type
13+
isOptional bool
14+
innerType Type
15+
}{
16+
{
17+
t: nil,
18+
isOptional: false,
19+
innerType: nil,
20+
},
21+
{
22+
t: TypeBool,
23+
isOptional: false,
24+
innerType: nil,
25+
},
26+
{
27+
t: Optional(TypeBool),
28+
isOptional: true,
29+
innerType: TypeBool,
30+
},
31+
{
32+
t: Optional(Optional(TypeBool)),
33+
isOptional: true,
34+
innerType: Optional(TypeBool),
35+
},
36+
} {
37+
t.Run("", func(t *testing.T) {
38+
isOptional, innerType := IsOptional(tt.t)
39+
require.Equal(t, tt.isOptional, isOptional)
40+
require.Equal(t, tt.innerType, innerType)
41+
})
42+
}
43+
}
44+
1045
func TestToDecimal(t *testing.T) {
1146
for _, tt := range []struct {
1247
v Value

0 commit comments

Comments
 (0)