@@ -97,6 +97,60 @@ fn handle_incorrect_dates<T>(error: &DeserializationError) -> Option<T> {
9797    } 
9898} 
9999
100+ // Native type test, which expects value to have the display trait and be trivially copyable 
101+ async  fn  run_native_serialize_test < T > ( table_name :  & str ,  type_name :  & str ,  values :  & [ Option < T > ] ) 
102+ where 
103+     T :  SerializeValue 
104+         + DeserializeOwnedValue 
105+         + FromStr 
106+         + Debug 
107+         + Clone 
108+         + PartialEq 
109+         + Default 
110+         + Display 
111+         + Copy , 
112+ { 
113+     let  session = init_test ( table_name,  type_name) . await ; 
114+     tracing:: debug!( "Active keyspace: {}" ,  session. get_keyspace( ) . unwrap( ) ) ; 
115+ 
116+     for  original_value in  values { 
117+         session
118+             . query_unpaged ( 
119+                 format ! ( "INSERT INTO {} (id, val) VALUES (1, ?)" ,  table_name) , 
120+                 ( & original_value, ) , 
121+             ) 
122+             . await 
123+             . unwrap ( ) ; 
124+ 
125+         let  selected_value:  Vec < T >  = session
126+             . query_unpaged ( format ! ( "SELECT val FROM {}" ,  table_name) ,  & [ ] ) 
127+             . await 
128+             . unwrap ( ) 
129+             . into_rows_result ( ) 
130+             . unwrap ( ) 
131+             . rows :: < ( T , ) > ( ) 
132+             . unwrap ( ) 
133+             . map ( |row| match  row { 
134+                 Ok ( ( val, ) )  => val, 
135+                 Err ( e)  => handle_deserialize_error ( & e,  || T :: default ( ) ) , 
136+             } ) 
137+             . collect :: < Vec < _ > > ( ) ; 
138+ 
139+         for  value in  selected_value { 
140+             tracing:: debug!( 
141+                 "Received: {} | Expected: {}" , 
142+                 value, 
143+                 if  original_value. is_none( )  { 
144+                     T :: default ( ) 
145+                 }  else { 
146+                     original_value. unwrap( ) 
147+                 } 
148+             ) ; 
149+             assert_eq ! ( value,  original_value. unwrap_or( T :: default ( ) ) ) ; 
150+         } 
151+     } 
152+ } 
153+ 
100154// Test for types that either don't have the Display trait or foreign types from other libraries 
101155async  fn  run_foreign_serialize_test < T > ( table_name :  & str ,  type_name :  & str ,  values :  & [ Option < T > ] ) 
102156where 
@@ -273,6 +327,146 @@ async fn run_literal_input_maybe_empty_output_test<X>(
273327    } 
274328} 
275329
330+ // Scalar types 
331+ 
332+ #[ tokio:: test]  
333+ async  fn  test_serialize_deserialize_bigint ( )  { 
334+     setup_tracing ( ) ; 
335+     const  TABLE_NAME :  & str  = "bigint_serialization_test" ; 
336+ 
337+     let  test_cases = [ 
338+         Some ( i64:: MIN ) , 
339+         Some ( i64:: MAX ) , 
340+         Some ( 1 ) , 
341+         Some ( -1 ) , 
342+         Some ( 0 ) , 
343+         None , 
344+     ] ; 
345+ 
346+     run_native_serialize_test ( TABLE_NAME ,  "bigint" ,  & test_cases) . await ; 
347+ } 
348+ 
349+ #[ tokio:: test]  
350+ async  fn  test_serialize_deserialize_int ( )  { 
351+     setup_tracing ( ) ; 
352+     const  TABLE_NAME :  & str  = "int_serialization_test" ; 
353+ 
354+     let  test_cases = [ 
355+         Some ( i32:: MIN ) , 
356+         Some ( i32:: MAX ) , 
357+         Some ( 1 ) , 
358+         Some ( -1 ) , 
359+         Some ( 0 ) , 
360+         None , 
361+     ] ; 
362+ 
363+     run_native_serialize_test ( TABLE_NAME ,  "int" ,  & test_cases) . await ; 
364+ } 
365+ 
366+ #[ tokio:: test]  
367+ async  fn  test_serialize_deserialize_smallint ( )  { 
368+     setup_tracing ( ) ; 
369+     const  TABLE_NAME :  & str  = "smallint_serialization_test" ; 
370+ 
371+     let  test_cases = [ 
372+         Some ( i16:: MIN ) , 
373+         Some ( i16:: MAX ) , 
374+         Some ( 1 ) , 
375+         Some ( -1 ) , 
376+         Some ( 0 ) , 
377+         None , 
378+     ] ; 
379+ 
380+     run_native_serialize_test ( TABLE_NAME ,  "smallint" ,  & test_cases) . await ; 
381+ } 
382+ 
383+ #[ tokio:: test]  
384+ async  fn  test_serialize_deserialize_tinyint ( )  { 
385+     setup_tracing ( ) ; 
386+     const  TABLE_NAME :  & str  = "tinyint_serialization_test" ; 
387+ 
388+     let  test_cases = [ 
389+         Some ( i8:: MIN ) , 
390+         Some ( i8:: MAX ) , 
391+         Some ( 1 ) , 
392+         Some ( -1 ) , 
393+         Some ( 0 ) , 
394+         None , 
395+     ] ; 
396+ 
397+     run_native_serialize_test ( TABLE_NAME ,  "tinyint" ,  & test_cases) . await ; 
398+ } 
399+ 
400+ #[ tokio:: test]  
401+ async  fn  test_serialize_deserialize_float ( )  { 
402+     setup_tracing ( ) ; 
403+     const  TABLE_NAME :  & str  = "float_serialization_test" ; 
404+ 
405+     let  test_cases = [ 
406+         Some ( f32:: MIN ) , 
407+         Some ( f32:: MAX ) , 
408+         Some ( 1.0 ) , 
409+         Some ( -1.0 ) , 
410+         Some ( 0.0 ) , 
411+         None , 
412+     ] ; 
413+ 
414+     run_native_serialize_test ( TABLE_NAME ,  "float" ,  & test_cases) . await ; 
415+ } 
416+ 
417+ #[ tokio:: test]  
418+ async  fn  test_serialize_deserialize_bool ( )  { 
419+     setup_tracing ( ) ; 
420+     const  TABLE_NAME :  & str  = "bool_serialization_test" ; 
421+ 
422+     let  test_cases = [ Some ( true ) ,  Some ( false ) ,  None ] ; 
423+ 
424+     run_native_serialize_test ( TABLE_NAME ,  "boolean" ,  & test_cases) . await ; 
425+ } 
426+ 
427+ #[ tokio:: test]  
428+ async  fn  test_serialize_deserialize_double ( )  { 
429+     setup_tracing ( ) ; 
430+     const  TABLE_NAME :  & str  = "double_serialization_test" ; 
431+ 
432+     let  test_cases = [ 
433+         Some ( f64:: MIN ) , 
434+         Some ( f64:: MAX ) , 
435+         Some ( 1.0 ) , 
436+         Some ( -1.0 ) , 
437+         Some ( 0.0 ) , 
438+         None , 
439+     ] ; 
440+ 
441+     run_native_serialize_test ( TABLE_NAME ,  "double" ,  & test_cases) . await ; 
442+ } 
443+ 
444+ #[ tokio:: test]  
445+ async  fn  test_serialize_deserialize_double_literal ( )  { 
446+     setup_tracing ( ) ; 
447+     const  TABLE_NAME :  & str  = "double_serialization_test" ; 
448+ 
449+     let  test_cases:  Vec < ( String ,  f64 ) >  = [ f64:: MIN ,  f64:: MAX ,  1.0 ,  -1.0 ,  0.0 ,  0.1 ] 
450+         . iter ( ) 
451+         . map ( |val| ( val. to_string ( ) ,  * val) ) 
452+         . collect ( ) ; 
453+ 
454+     run_literal_and_bound_value_test ( TABLE_NAME ,  "double" ,  test_cases. as_slice ( ) ,  false ) . await ; 
455+ } 
456+ 
457+ #[ tokio:: test]  
458+ async  fn  test_serialize_deserialize_float_literal ( )  { 
459+     setup_tracing ( ) ; 
460+     const  TABLE_NAME :  & str  = "float_serialization_test" ; 
461+ 
462+     let  test_cases:  Vec < ( String ,  f32 ) >  = [ f32:: MIN ,  f32:: MAX ,  1.0 ,  -1.0 ,  0.0 ,  0.1 ] 
463+         . iter ( ) 
464+         . map ( |val| ( val. to_string ( ) ,  * val) ) 
465+         . collect ( ) ; 
466+ 
467+     run_literal_and_bound_value_test ( TABLE_NAME ,  "float" ,  test_cases. as_slice ( ) ,  false ) . await ; 
468+ } 
469+ 
276470// Arbitrary precision types 
277471
278472#[ tokio:: test]  
@@ -1223,6 +1417,19 @@ async fn test_serialize_deserialize_offset_date_time_03_high_precision_rounding_
12231417
12241418//UUID Types 
12251419
1420+ #[ tokio:: test]  
1421+ async  fn  test_serialize_deserialize_uuid ( )  { 
1422+     setup_tracing ( ) ; 
1423+     const  TABLE_NAME :  & str  = "uuid_serialization_test" ; 
1424+ 
1425+     let  tests:  Vec < ( String ,  uuid:: Uuid ) >  = ( 0 ..100 ) 
1426+         . map ( |_| uuid:: Uuid :: new_v4 ( ) ) 
1427+         . map ( |new_uuid| ( new_uuid. to_string ( ) ,  new_uuid) ) 
1428+         . collect ( ) ; 
1429+ 
1430+     run_literal_and_bound_value_test ( TABLE_NAME ,  "uuid" ,  tests. as_slice ( ) ,  false ) . await ; 
1431+ } 
1432+ 
12261433#[ tokio:: test]  
12271434async  fn  test_serialize_deserialize_timeuuid ( )  { 
12281435    setup_tracing ( ) ; 
@@ -1331,6 +1538,35 @@ async fn test_serialize_deserialize_timeuuid_ordering() {
13311538    } 
13321539} 
13331540
1541+ #[ tokio:: test]  
1542+ async  fn  test_serialize_deserialize_strings_varchar ( )  { 
1543+     let  table_name = "varchar_serialization_test" ; 
1544+ 
1545+     let  test_cases:  Vec < ( & str ,  String ) >  = vec ! [ 
1546+         ( "Hello, World!" ,  String :: from( "Hello, World!" ) ) , 
1547+         ( "Hello, Мир" ,  String :: from( "Hello, Мир" ) ) ,  // multi-byte string 
1548+         ( "🦀A🦀B🦀C" ,  String :: from( "🦀A🦀B🦀C" ) ) , 
1549+         ( "おはようございます" ,  String :: from( "おはようございます" ) ) , 
1550+     ] ; 
1551+ 
1552+     run_literal_and_bound_value_test ( table_name,  "varchar" ,  test_cases. as_slice ( ) ,  true ) . await ; 
1553+ } 
1554+ 
1555+ #[ tokio:: test]  
1556+ async  fn  test_serialize_deserialize_strings_ascii ( )  { 
1557+     let  table_name = "ascii_serialization_test" ; 
1558+ 
1559+     let  test_cases:  Vec < ( & str ,  String ) >  = vec ! [ 
1560+         ( "Hello, World!" ,  String :: from( "Hello, World!" ) ) , 
1561+         ( 
1562+             str :: from_utf8( & [ 0x0 ,  0x7f ] ) . unwrap( ) , 
1563+             String :: from_utf8( vec![ 0x0 ,  0x7f ] ) . unwrap( ) , 
1564+         ) ,  // min/max ASCII values 
1565+     ] ; 
1566+ 
1567+     run_literal_and_bound_value_test ( table_name,  "varchar" ,  test_cases. as_slice ( ) ,  true ) . await ; 
1568+ } 
1569+ 
13341570// UDT Types 
13351571
13361572#[ tokio:: test]  
0 commit comments