@@ -351,7 +351,7 @@ mod tests {
351
351
}
352
352
353
353
#[ test]
354
- fn test_is_compatible_to ( ) {
354
+ fn test_is_compatible_to_failed_when_types_differ ( ) {
355
355
let left = MessageTypeDetails :: from :: < i64 , i64 , i8 > ( TypeVariant :: FixedSize ) ;
356
356
let right = MessageTypeDetails :: from :: < i64 , i64 , u8 > ( TypeVariant :: FixedSize ) ;
357
357
let sut = left. is_compatible_to ( & right) ;
@@ -361,6 +361,11 @@ mod tests {
361
361
let right = MessageTypeDetails :: from :: < i64 , i64 , i32 > ( TypeVariant :: FixedSize ) ;
362
362
let sut = left. is_compatible_to ( & right) ;
363
363
assert_that ! ( sut, eq false ) ;
364
+ }
365
+
366
+ #[ test]
367
+ fn test_is_compatible_to_succeed_when_rhs_aligment_is_bigger ( ) {
368
+ let left = MessageTypeDetails :: from :: < i64 , i64 , i64 > ( TypeVariant :: FixedSize ) ;
364
369
365
370
// right may have a different alignment from left.
366
371
// but note that the header alignment must be the same
@@ -392,4 +397,35 @@ mod tests {
392
397
let sut = right. is_compatible_to ( & left) ;
393
398
assert_that ! ( sut, eq false ) ;
394
399
}
400
+
401
+ #[ test]
402
+ fn test_is_compatible_to_fail_when_rhs_aligment_is_smaller ( ) {
403
+ let left = MessageTypeDetails :: from :: < i64 , i64 , i64 > ( TypeVariant :: FixedSize ) ;
404
+
405
+ // right may have a different alignment from left.
406
+ // but note that the header alignment must be the same
407
+ let right = MessageTypeDetails {
408
+ header : TypeDetail {
409
+ variant : TypeVariant :: FixedSize ,
410
+ type_name : "i64" . to_string ( ) ,
411
+ size : 8 ,
412
+ alignment : ALIGNMENT ,
413
+ } ,
414
+ user_header : TypeDetail {
415
+ variant : TypeVariant :: FixedSize ,
416
+ type_name : "i64" . to_string ( ) ,
417
+ size : 8 ,
418
+ alignment : 2 * ALIGNMENT ,
419
+ } ,
420
+ payload : TypeDetail {
421
+ variant : TypeVariant :: FixedSize ,
422
+ type_name : "i64" . to_string ( ) ,
423
+ size : 8 ,
424
+ alignment : 2 * ALIGNMENT ,
425
+ } ,
426
+ } ;
427
+ // bigger to smaller is invalid.
428
+ let sut = right. is_compatible_to ( & left) ;
429
+ assert_that ! ( sut, eq false ) ;
430
+ }
395
431
}
0 commit comments