@@ -1157,6 +1157,22 @@ fn test_tuples() {
11571157 ) ;
11581158}
11591159
1160+ #[ test]
1161+ fn test_box ( ) {
1162+ let int = make_bytes ( & [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
1163+ let decoded_int: Box < i32 > =
1164+ deserialize :: < Box < i32 > > ( & ColumnType :: Native ( NativeType :: Int ) , & int) . unwrap ( ) ;
1165+ assert_eq ! ( * decoded_int, 0x01020304 ) ;
1166+ }
1167+
1168+ #[ test]
1169+ fn test_arc ( ) {
1170+ let int = make_bytes ( & [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
1171+ let decoded_int: Arc < i32 > =
1172+ deserialize :: < Arc < i32 > > ( & ColumnType :: Native ( NativeType :: Int ) , & int) . unwrap ( ) ;
1173+ assert_eq ! ( * decoded_int, 0x01020304 ) ;
1174+ }
1175+
11601176pub ( crate ) fn udt_def_with_fields (
11611177 fields : impl IntoIterator < Item = ( impl Into < Cow < ' static , str > > , ColumnType < ' static > ) > ,
11621178) -> ColumnType < ' static > {
@@ -2448,6 +2464,60 @@ fn test_null_errors() {
24482464 deserialize :: < MaybeEmpty < i32 > > ( & ser_typ, & bytes) . unwrap_err ( ) ;
24492465}
24502466
2467+ #[ test]
2468+ fn test_box_errors ( ) {
2469+ let v = 123_i32 ;
2470+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: Int ) , & v) ;
2471+
2472+ // Incompatible types render type check error.
2473+ assert_type_check_error ! (
2474+ & bytes,
2475+ Box <f64 >,
2476+ ColumnType :: Native ( NativeType :: Int ) ,
2477+ BuiltinTypeCheckErrorKind :: MismatchedType {
2478+ expected: & [ ColumnType :: Native ( NativeType :: Double ) ] ,
2479+ }
2480+ ) ;
2481+
2482+ // ColumnType is said to be Double (8 bytes expected), but in reality the serialized form has 4 bytes only.
2483+ assert_deser_error ! (
2484+ & bytes,
2485+ Box <f64 >,
2486+ ColumnType :: Native ( NativeType :: Double ) ,
2487+ BuiltinDeserializationErrorKind :: ByteLengthMismatch {
2488+ expected: 8 ,
2489+ got: 4 ,
2490+ }
2491+ ) ;
2492+ }
2493+
2494+ #[ test]
2495+ fn test_arc_errors ( ) {
2496+ let v = 123_i32 ;
2497+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: Int ) , & v) ;
2498+
2499+ // Incompatible types render type check error.
2500+ assert_type_check_error ! (
2501+ & bytes,
2502+ Arc <f64 >,
2503+ ColumnType :: Native ( NativeType :: Int ) ,
2504+ BuiltinTypeCheckErrorKind :: MismatchedType {
2505+ expected: & [ ColumnType :: Native ( NativeType :: Double ) ] ,
2506+ }
2507+ ) ;
2508+
2509+ // ColumnType is said to be Double (8 bytes expected), but in reality the serialized form has 4 bytes only.
2510+ assert_deser_error ! (
2511+ & bytes,
2512+ Arc <f64 >,
2513+ ColumnType :: Native ( NativeType :: Double ) ,
2514+ BuiltinDeserializationErrorKind :: ByteLengthMismatch {
2515+ expected: 8 ,
2516+ got: 4 ,
2517+ }
2518+ ) ;
2519+ }
2520+
24512521#[ test]
24522522fn test_udt_errors ( ) {
24532523 // Loose ordering
0 commit comments