@@ -160,6 +160,9 @@ func TestNamedExpr(t *testing.T) {
160160 }
161161}
162162
163+ type namedFloat64s []float64
164+ type namedBytes []byte
165+
163166func TestExpression (t * testing.T ) {
164167 column := "column-name"
165168 results := []struct {
@@ -214,6 +217,58 @@ func TestExpression(t *testing.T) {
214217 clause.Eq {Column : column , Value : []string {}},
215218 },
216219 Result : "`column-name` IN (NULL)" ,
220+ }, {
221+ // slice element types other than the hard-coded ones in Eq/Neq must
222+ // still render as an IN/NOT IN list, not `= (?,?)`
223+ Expressions : []clause.Expression {
224+ clause.Eq {Column : column , Value : []float64 {1.5 , 2.5 }},
225+ },
226+ ExpectedVars : []interface {}{1.5 , 2.5 },
227+ Result : "`column-name` IN (?,?)" ,
228+ }, {
229+ Expressions : []clause.Expression {
230+ clause.Neq {Column : column , Value : []float64 {1.5 , 2.5 }},
231+ },
232+ ExpectedVars : []interface {}{1.5 , 2.5 },
233+ Result : "`column-name` NOT IN (?,?)" ,
234+ }, {
235+ Expressions : []clause.Expression {
236+ clause.Eq {Column : column , Value : []int8 {1 , 2 }},
237+ },
238+ ExpectedVars : []interface {}{int8 (1 ), int8 (2 )},
239+ Result : "`column-name` IN (?,?)" ,
240+ }, {
241+ Expressions : []clause.Expression {
242+ clause.Eq {Column : column , Value : []bool {true , false }},
243+ },
244+ ExpectedVars : []interface {}{true , false },
245+ Result : "`column-name` IN (?,?)" ,
246+ }, {
247+ // a named slice type must behave the same as its underlying type
248+ Expressions : []clause.Expression {
249+ clause.Eq {Column : column , Value : namedFloat64s {1.5 , 2.5 }},
250+ },
251+ ExpectedVars : []interface {}{1.5 , 2.5 },
252+ Result : "`column-name` IN (?,?)" ,
253+ }, {
254+ // []byte is a single value, never a list
255+ Expressions : []clause.Expression {
256+ clause.Eq {Column : column , Value : []byte {1 , 2 }},
257+ },
258+ ExpectedVars : []interface {}{[]byte {1 , 2 }},
259+ Result : "`column-name` = ?" ,
260+ }, {
261+ Expressions : []clause.Expression {
262+ clause.Eq {Column : column , Value : namedBytes {1 , 2 }},
263+ },
264+ ExpectedVars : []interface {}{namedBytes {1 , 2 }},
265+ Result : "`column-name` = ?" ,
266+ }, {
267+ // an empty list of any element type must still be IN (NULL)
268+ Expressions : []clause.Expression {
269+ clause.Eq {Column : column , Value : []float64 {}},
270+ },
271+ Result : "`column-name` IN (NULL)" ,
217272 }, {
218273 Expressions : []clause.Expression {
219274 clause.Eq {Column : clause.Expr {SQL : "SUM(?)" , Vars : []interface {}{clause.Column {Name : "id" }}}, Value : 100 },
0 commit comments