@@ -196,3 +196,44 @@ func TestAllUint64(t *testing.T) {
196196 })
197197 }
198198}
199+
200+ func TestBitOpType (t * testing.T ) {
201+ testCases := []struct {
202+ name string
203+ leftType sql.Type
204+ rightType sql.Type
205+ expectedType sql.Type
206+ description string
207+ }{
208+ {"unsigned & unsigned" , types .Uint64 , types .Uint64 , types .Uint64 , "Both operands are unsigned" },
209+ {"signed & signed" , types .Int64 , types .Int64 , types .Uint64 , "Both operands are signed - should return Uint64" },
210+ {"mixed signed & unsigned" , types .Int64 , types .Uint64 , types .Uint64 , "Mixed signed/unsigned operands" },
211+ {"text & text" , types .Text , types .Text , types .Uint64 , "Text operands should return Float64" },
212+ {"text & int" , types .Text , types .Int64 , types .Uint64 , "Mixed text and numeric operands" },
213+ {"float & float" , types .Float64 , types .Float64 , types .Uint64 , "Float operands should return Uint64" },
214+ }
215+
216+ operations := []struct {
217+ name string
218+ op func (left , right sql.Expression ) * BitOp
219+ }{
220+ {"BitAnd" , NewBitAnd },
221+ {"BitOr" , NewBitOr },
222+ {"BitXor" , NewBitXor },
223+ {"ShiftLeft" , NewShiftLeft },
224+ {"ShiftRight" , NewShiftRight },
225+ }
226+
227+ for _ , tt := range testCases {
228+ for _ , op := range operations {
229+ t .Run (tt .name + "_" + op .name , func (t * testing.T ) {
230+ require := require .New (t )
231+ bitOp := op .op (NewLiteral (1 , tt .leftType ), NewLiteral (1 , tt .rightType ))
232+ actualType := bitOp .Type ()
233+ require .Equal (tt .expectedType , actualType ,
234+ "BitOp.Type() should return %v for %s: %s" ,
235+ tt .expectedType , tt .name , tt .description )
236+ })
237+ }
238+ }
239+ }
0 commit comments