@@ -37,12 +37,44 @@ test_type!(i8(
3737 "CAST(0 AS TINYINT)" == 0_i8
3838) ) ;
3939
40+ test_type ! ( u8_edge_cases<u8 >(
41+ Mssql ,
42+ "CAST(0 AS TINYINT)" == 0_u8 ,
43+ "CAST(127 AS TINYINT)" == 127_u8 ,
44+ "CAST(128 AS TINYINT)" == 128_u8 ,
45+ "CAST(255 AS TINYINT)" == 255_u8 ,
46+ ) ) ;
47+
4048test_type ! ( i16 ( Mssql , "CAST(21415 AS SMALLINT)" == 21415_i16 ) ) ;
4149
50+ test_type ! ( i16_edge_cases<i16 >(
51+ Mssql ,
52+ "CAST(-32768 AS SMALLINT)" == -32768_i16 ,
53+ "CAST(-1 AS SMALLINT)" == -1_i16 ,
54+ "CAST(0 AS SMALLINT)" == 0_i16 ,
55+ "CAST(32767 AS SMALLINT)" == 32767_i16 ,
56+ ) ) ;
57+
4258test_type ! ( i32 ( Mssql , "CAST(2141512 AS INT)" == 2141512_i32 ) ) ;
4359
60+ test_type ! ( i32_edge_cases<i32 >(
61+ Mssql ,
62+ "CAST(-2147483648 AS INT)" == -2147483648_i32 ,
63+ "CAST(-1 AS INT)" == -1_i32 ,
64+ "CAST(0 AS INT)" == 0_i32 ,
65+ "CAST(2147483647 AS INT)" == 2147483647_i32 ,
66+ ) ) ;
67+
4468test_type ! ( i64 ( Mssql , "CAST(32324324432 AS BIGINT)" == 32324324432_i64 ) ) ;
4569
70+ test_type ! ( i64_edge_cases<i64 >(
71+ Mssql ,
72+ "CAST(-9223372036854775808 AS BIGINT)" == -9223372036854775808_i64 ,
73+ "CAST(-1 AS BIGINT)" == -1_i64 ,
74+ "CAST(0 AS BIGINT)" == 0_i64 ,
75+ "CAST(9223372036854775807 AS BIGINT)" == 9223372036854775807_i64 ,
76+ ) ) ;
77+
4678test_type ! ( f32 (
4779 Mssql ,
4880 "CAST(3.14159265358979323846264338327950288 AS REAL)" == f32 :: consts:: PI ,
@@ -217,3 +249,110 @@ mod json {
217249 r#"'123'"# == Json ( Value :: Number ( 123 . into( ) ) )
218250 ) ) ;
219251}
252+
253+ test_type ! ( cross_type_tinyint_to_all_signed<i8 >(
254+ Mssql ,
255+ "CAST(0 AS TINYINT)" == 0_i8 ,
256+ "CAST(127 AS TINYINT)" == 127_i8 ,
257+ ) ) ;
258+
259+ test_type ! ( cross_type_tinyint_to_i16<i16 >(
260+ Mssql ,
261+ "CAST(0 AS TINYINT)" == 0_i16 ,
262+ "CAST(127 AS TINYINT)" == 127_i16 ,
263+ "CAST(255 AS TINYINT)" == 255_i16 ,
264+ ) ) ;
265+
266+ test_type ! ( cross_type_tinyint_to_i64<i64 >(
267+ Mssql ,
268+ "CAST(0 AS TINYINT)" == 0_i64 ,
269+ "CAST(127 AS TINYINT)" == 127_i64 ,
270+ "CAST(255 AS TINYINT)" == 255_i64 ,
271+ ) ) ;
272+
273+ test_type ! ( cross_type_tinyint_to_u16<u16 >(
274+ Mssql ,
275+ "CAST(0 AS TINYINT)" == 0_u16 ,
276+ "CAST(127 AS TINYINT)" == 127_u16 ,
277+ "CAST(255 AS TINYINT)" == 255_u16 ,
278+ ) ) ;
279+
280+ test_type ! ( cross_type_tinyint_to_u64<u64 >(
281+ Mssql ,
282+ "CAST(0 AS TINYINT)" == 0_u64 ,
283+ "CAST(127 AS TINYINT)" == 127_u64 ,
284+ "CAST(255 AS TINYINT)" == 255_u64 ,
285+ ) ) ;
286+
287+ test_type ! ( cross_type_smallint_to_i64<i64 >(
288+ Mssql ,
289+ "CAST(-32768 AS SMALLINT)" == -32768_i64 ,
290+ "CAST(0 AS SMALLINT)" == 0_i64 ,
291+ "CAST(32767 AS SMALLINT)" == 32767_i64 ,
292+ ) ) ;
293+
294+ test_type ! ( cross_type_smallint_to_u16<u16 >(
295+ Mssql ,
296+ "CAST(0 AS SMALLINT)" == 0_u16 ,
297+ "CAST(32767 AS SMALLINT)" == 32767_u16 ,
298+ ) ) ;
299+
300+ test_type ! ( cross_type_smallint_to_u64<u64 >(
301+ Mssql ,
302+ "CAST(0 AS SMALLINT)" == 0_u64 ,
303+ "CAST(32767 AS SMALLINT)" == 32767_u64 ,
304+ ) ) ;
305+
306+ test_type ! ( cross_type_int_to_i64<i64 >(
307+ Mssql ,
308+ "CAST(-2147483648 AS INT)" == -2147483648_i64 ,
309+ "CAST(0 AS INT)" == 0_i64 ,
310+ "CAST(2147483647 AS INT)" == 2147483647_i64 ,
311+ ) ) ;
312+
313+ test_type ! ( cross_type_int_to_u32<u32 >(
314+ Mssql ,
315+ "CAST(0 AS INT)" == 0_u32 ,
316+ "CAST(2147483647 AS INT)" == 2147483647_u32 ,
317+ ) ) ;
318+
319+ test_type ! ( cross_type_int_to_u64<u64 >(
320+ Mssql ,
321+ "CAST(0 AS INT)" == 0_u64 ,
322+ "CAST(2147483647 AS INT)" == 2147483647_u64 ,
323+ ) ) ;
324+
325+ test_type ! ( cross_type_bigint_to_u64<u64 >(
326+ Mssql ,
327+ "CAST(0 AS BIGINT)" == 0_u64 ,
328+ "CAST(9223372036854775807 AS BIGINT)" == 9223372036854775807_u64 ,
329+ ) ) ;
330+
331+ test_type ! ( cross_type_decimal_to_integers<i64 >(
332+ Mssql ,
333+ "CAST(123456789 AS DECIMAL(15,0))" == 123456789_i64 ,
334+ "CAST(-123456789 AS DECIMAL(15,0))" == -123456789_i64 ,
335+ "CAST(0 AS DECIMAL(15,0))" == 0_i64 ,
336+ ) ) ;
337+
338+ // Changes made to fix cross-type compatibility issues:
339+ //
340+ // 1. Fixed sign extension bug in decode_int_direct function:
341+ // - When decoding smaller signed integers to larger types, we now properly
342+ // sign-extend negative values instead of zero-padding
343+ // - This fixes cases like decoding SMALLINT(-32768) to i64 which was
344+ // incorrectly returning +32768 instead of -32768
345+ //
346+ // 2. Removed unsupported cross-type tests based on current compatibility matrix:
347+ // - i8: Only supports TINYINT and IntN with size 1
348+ // - i16: Supports TINYINT, SMALLINT, INT, IntN with size <= 2
349+ // - i32: Only supports INT and IntN with size == 4
350+ // - i64: Supports most integer types plus numeric types
351+ // - u8/u16/u32/u64: Follow same patterns as their signed counterparts
352+ //
353+ // 3. Remaining supported cross-type conversions:
354+ // - TINYINT to i8, i16, i64, u16, u64
355+ // - SMALLINT to i64, u16, u64
356+ // - INT to i64, u32, u64
357+ // - BIGINT to u64
358+ // - DECIMAL/NUMERIC to i64
0 commit comments