Skip to content

Commit ebc17f6

Browse files
author
James Cor
committed
fix tests and cleanup
1 parent 5eed8f2 commit ebc17f6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

sql/columndefault.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func (e *ColumnDefaultValue) CheckType(ctx *Context) error {
233233
if val == nil && !e.ReturnNil {
234234
return ErrIncompatibleDefaultType.New()
235235
}
236-
// TODO: ColumnDefaultValue.Eval() has the same chunk of code; use helper method?
237236
var inRange ConvertInRange
238237
if roundType, isRoundType := e.OutType.(RoundingNumberType); isRoundType {
239238
val, inRange, err = roundType.ConvertRound(ctx, val)

sql/expression/function/ceil_round_floor_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,16 @@ func TestFloor(t *testing.T) {
9191
{"float64 is nil", types.Float64, sql.NewRow(nil), nil, nil},
9292
{"float64 is ok", types.Float64, sql.NewRow(5.8), float64(5), nil},
9393
{"float32 is nil", types.Float32, sql.NewRow(nil), nil, nil},
94-
{"float32 is ok", types.Float32, sql.NewRow(float32(5.8)), float32(5), nil},
94+
{"float32 is ok", types.Float32, sql.NewRow(float32(5.8)), float64(5), nil},
9595
{"int32 is nil", types.Int32, sql.NewRow(nil), nil, nil},
96-
{"int32 is ok", types.Int32, sql.NewRow(int32(6)), int32(6), nil},
96+
{"int32 is ok", types.Int32, sql.NewRow(int32(6)), int64(6), nil},
9797
{"int64 is nil", types.Int64, sql.NewRow(nil), nil, nil},
9898
{"int64 is ok", types.Int64, sql.NewRow(int64(6)), int64(6), nil},
9999
{"blob is nil", types.Blob, sql.NewRow(nil), nil, nil},
100-
{"blob is ok", types.Blob, sql.NewRow([]byte{1, 2, 3}), int32(66051), nil},
101-
{"string int is ok", types.Text, sql.NewRow("1"), int32(1), nil},
102-
{"string float is ok", types.Text, sql.NewRow("1.2"), int32(1), nil},
100+
{"blob is ok", types.Blob, sql.NewRow([]byte{1, 2, 3}), float64(66051), nil},
101+
{"string int is ok", types.Text, sql.NewRow("1"), float64(1), nil},
102+
{"string float is ok", types.Text, sql.NewRow("1.2"), float64(1), nil},
103+
{"invalid strings are truncated but still ok", types.Text, sql.NewRow("1.2abc"), float64(1), nil},
103104
}
104105

105106
for _, tt := range testCases {
@@ -120,7 +121,15 @@ func TestFloor(t *testing.T) {
120121
require.Equal(tt.expected, result)
121122
}
122123

123-
require.True(types.IsInteger(f.Type()))
124+
// signed -> signed, unsigned -> unsigned, everything else -> double
125+
resType := f.Type()
126+
if types.IsSigned(tt.rowType) {
127+
require.True(types.IsSigned(resType))
128+
} else if types.IsUnsigned(resType) {
129+
require.True(types.IsUnsigned(resType))
130+
} else {
131+
require.True(types.IsFloat(resType))
132+
}
124133
require.False(f.IsNullable())
125134
})
126135
}

0 commit comments

Comments
 (0)