@@ -1157,6 +1157,40 @@ fn test_tuples() {
11571157 ) ;
11581158}
11591159
1160+ #[ test]
1161+ fn test_box ( ) {
1162+ {
1163+ let int = make_bytes ( & [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
1164+ let decoded_int: Box < i32 > =
1165+ deserialize :: < Box < i32 > > ( & ColumnType :: Native ( NativeType :: Int ) , & int) . unwrap ( ) ;
1166+ assert_eq ! ( * decoded_int, 0x01020304 ) ;
1167+ }
1168+
1169+ {
1170+ let text_bytes = make_bytes ( b"abcd" ) ;
1171+ let decoded_int: Box < str > =
1172+ deserialize :: < Box < str > > ( & ColumnType :: Native ( NativeType :: Text ) , & text_bytes) . unwrap ( ) ;
1173+ assert_eq ! ( & * decoded_int, "abcd" ) ;
1174+ }
1175+ }
1176+
1177+ #[ test]
1178+ fn test_arc ( ) {
1179+ {
1180+ let int = make_bytes ( & [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
1181+ let decoded_int: Arc < i32 > =
1182+ deserialize :: < Arc < i32 > > ( & ColumnType :: Native ( NativeType :: Int ) , & int) . unwrap ( ) ;
1183+ assert_eq ! ( * decoded_int, 0x01020304 ) ;
1184+ }
1185+
1186+ {
1187+ let text_bytes = make_bytes ( b"abcd" ) ;
1188+ let decoded_int: Arc < str > =
1189+ deserialize :: < Arc < str > > ( & ColumnType :: Native ( NativeType :: Text ) , & text_bytes) . unwrap ( ) ;
1190+ assert_eq ! ( & * decoded_int, "abcd" ) ;
1191+ }
1192+ }
1193+
11601194pub ( crate ) fn udt_def_with_fields (
11611195 fields : impl IntoIterator < Item = ( impl Into < Cow < ' static , str > > , ColumnType < ' static > ) > ,
11621196) -> ColumnType < ' static > {
@@ -2448,6 +2482,108 @@ fn test_null_errors() {
24482482 deserialize :: < MaybeEmpty < i32 > > ( & ser_typ, & bytes) . unwrap_err ( ) ;
24492483}
24502484
2485+ #[ test]
2486+ fn test_box_errors ( ) {
2487+ let v = 123_i32 ;
2488+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: Int ) , & v) ;
2489+
2490+ // Incompatible types render type check error.
2491+ assert_type_check_error ! (
2492+ & bytes,
2493+ Box <f64 >,
2494+ ColumnType :: Native ( NativeType :: Int ) ,
2495+ BuiltinTypeCheckErrorKind :: MismatchedType {
2496+ expected: & [ ColumnType :: Native ( NativeType :: Double ) ] ,
2497+ }
2498+ ) ;
2499+
2500+ // ColumnType is said to be Double (8 bytes expected), but in reality the serialized form has 4 bytes only.
2501+ assert_deser_error ! (
2502+ & bytes,
2503+ Box <f64 >,
2504+ ColumnType :: Native ( NativeType :: Double ) ,
2505+ BuiltinDeserializationErrorKind :: ByteLengthMismatch {
2506+ expected: 8 ,
2507+ got: 4 ,
2508+ }
2509+ ) ;
2510+
2511+ // Arc<str> is a special case, let's test it separately
2512+ assert_type_check_error ! (
2513+ & bytes,
2514+ Box <str >,
2515+ ColumnType :: Native ( NativeType :: Int ) ,
2516+ BuiltinTypeCheckErrorKind :: MismatchedType {
2517+ expected: & [
2518+ ColumnType :: Native ( NativeType :: Ascii ) ,
2519+ ColumnType :: Native ( NativeType :: Text )
2520+ ] ,
2521+ }
2522+ ) ;
2523+
2524+ // -126 is not a valid ASCII nor UTF-8 byte.
2525+ let v = -126_i8 ;
2526+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: TinyInt ) , & v) ;
2527+
2528+ assert_deser_error ! (
2529+ & bytes,
2530+ Box <str >,
2531+ ColumnType :: Native ( NativeType :: Text ) ,
2532+ BuiltinDeserializationErrorKind :: InvalidUtf8 ( _)
2533+ ) ;
2534+ }
2535+
2536+ #[ test]
2537+ fn test_arc_errors ( ) {
2538+ let v = 123_i32 ;
2539+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: Int ) , & v) ;
2540+
2541+ // Incompatible types render type check error.
2542+ assert_type_check_error ! (
2543+ & bytes,
2544+ Arc <f64 >,
2545+ ColumnType :: Native ( NativeType :: Int ) ,
2546+ BuiltinTypeCheckErrorKind :: MismatchedType {
2547+ expected: & [ ColumnType :: Native ( NativeType :: Double ) ] ,
2548+ }
2549+ ) ;
2550+
2551+ // ColumnType is said to be Double (8 bytes expected), but in reality the serialized form has 4 bytes only.
2552+ assert_deser_error ! (
2553+ & bytes,
2554+ Arc <f64 >,
2555+ ColumnType :: Native ( NativeType :: Double ) ,
2556+ BuiltinDeserializationErrorKind :: ByteLengthMismatch {
2557+ expected: 8 ,
2558+ got: 4 ,
2559+ }
2560+ ) ;
2561+
2562+ // Arc<str> is a special case, let's test it separately
2563+ assert_type_check_error ! (
2564+ & bytes,
2565+ Arc <str >,
2566+ ColumnType :: Native ( NativeType :: Int ) ,
2567+ BuiltinTypeCheckErrorKind :: MismatchedType {
2568+ expected: & [
2569+ ColumnType :: Native ( NativeType :: Ascii ) ,
2570+ ColumnType :: Native ( NativeType :: Text )
2571+ ] ,
2572+ }
2573+ ) ;
2574+
2575+ // -126 is not a valid ASCII nor UTF-8 byte.
2576+ let v = -126_i8 ;
2577+ let bytes = serialize ( & ColumnType :: Native ( NativeType :: TinyInt ) , & v) ;
2578+
2579+ assert_deser_error ! (
2580+ & bytes,
2581+ Arc <str >,
2582+ ColumnType :: Native ( NativeType :: Text ) ,
2583+ BuiltinDeserializationErrorKind :: InvalidUtf8 ( _)
2584+ ) ;
2585+ }
2586+
24512587#[ test]
24522588fn test_udt_errors ( ) {
24532589 // Loose ordering
0 commit comments