@@ -40,7 +40,8 @@ pub enum SlidingSyncRoomState {
40
40
/// It contains some information about a specific room, along with a queue of
41
41
/// events for the timeline.
42
42
///
43
- /// It is OK to clone this type as much as you need: cloning it is cheap.
43
+ /// It is OK to clone this type as much as you need: cloning it is cheap, and
44
+ /// shallow. All clones of the same value are sharing the same state.
44
45
#[ derive( Debug , Clone ) ]
45
46
pub struct SlidingSyncRoom {
46
47
inner : Arc < SlidingSyncRoomInner > ,
@@ -398,9 +399,11 @@ mod tests {
398
399
(
399
400
$(
400
401
$test_name: ident {
401
- $getter: ident ( ) $( . $getter_field: ident ) ? = $first_value : expr;
402
+ $getter: ident ( ) $( . $getter_field: ident ) ? = $default_value : expr;
402
403
receives $room_response: expr;
403
- _ = $second_value: expr;
404
+ _ = $init_or_updated_value: expr;
405
+ receives nothing;
406
+ _ = $no_update_value: expr;
404
407
}
405
408
) +
406
409
) => {
@@ -411,27 +414,35 @@ mod tests {
411
414
{
412
415
let room = new_room( room_id!( "!foo:bar.org" ) , room_response!( { } ) ) . await ;
413
416
414
- assert_eq!( room. $getter( ) $( . $getter_field ) ?, $first_value ) ;
417
+ assert_eq!( room. $getter( ) $( . $getter_field ) ?, $default_value , "default value" ) ;
415
418
}
416
419
417
420
// Some value when initializing.
418
421
{
419
422
let room = new_room( room_id!( "!foo:bar.org" ) , $room_response) . await ;
420
423
421
- assert_eq!( room. $getter( ) $( . $getter_field ) ?, $second_value ) ;
424
+ assert_eq!( room. $getter( ) $( . $getter_field ) ?, $init_or_updated_value , "init value" ) ;
422
425
}
423
426
424
427
// Some value when updating.
425
428
{
426
429
427
430
let mut room = new_room( room_id!( "!foo:bar.org" ) , room_response!( { } ) ) . await ;
428
431
429
- assert_eq!( room. $getter( ) $( . $getter_field ) ?, $first_value) ;
432
+ // Value is set to the default value.
433
+ assert_eq!( room. $getter( ) $( . $getter_field ) ?, $default_value, "default value (bis)" ) ;
430
434
431
435
room. update( $room_response, vec![ ] ) ;
432
436
433
- assert_eq!( room. $getter( ) $( . $getter_field ) ?, $second_value) ;
437
+ // Value has been updated.
438
+ assert_eq!( room. $getter( ) $( . $getter_field ) ?, $init_or_updated_value, "updated value" ) ;
439
+
440
+ room. update( room_response!( { } ) , vec![ ] ) ;
441
+
442
+ // Value is kept.
443
+ assert_eq!( room. $getter( ) $( . $getter_field ) ?, $no_update_value, "not updated value" ) ;
434
444
}
445
+
435
446
}
436
447
) +
437
448
} ;
@@ -442,42 +453,56 @@ mod tests {
442
453
name( ) = None ;
443
454
receives room_response!( { "name" : "gordon" } ) ;
444
455
_ = Some ( "gordon" . to_string( ) ) ;
456
+ receives nothing;
457
+ _ = Some ( "gordon" . to_string( ) ) ;
445
458
}
446
459
447
460
test_room_is_dm {
448
461
is_dm( ) = None ;
449
462
receives room_response!( { "is_dm" : true } ) ;
450
463
_ = Some ( true ) ;
464
+ receives nothing;
465
+ _ = Some ( true ) ;
451
466
}
452
467
453
468
test_room_is_initial_response {
454
469
is_initial_response( ) = None ;
455
470
receives room_response!( { "initial" : true } ) ;
456
471
_ = Some ( true ) ;
472
+ receives nothing;
473
+ _ = Some ( true ) ;
457
474
}
458
475
459
476
test_has_unread_notifications_with_notification_count {
460
477
has_unread_notifications( ) = false ;
461
478
receives room_response!( { "notification_count" : 42 } ) ;
462
479
_ = true ;
480
+ receives nothing;
481
+ _ = false ;
463
482
}
464
483
465
484
test_has_unread_notifications_with_highlight_count {
466
485
has_unread_notifications( ) = false ;
467
486
receives room_response!( { "highlight_count" : 42 } ) ;
468
487
_ = true ;
488
+ receives nothing;
489
+ _ = false ;
469
490
}
470
491
471
492
test_unread_notifications_with_notification_count {
472
493
unread_notifications( ) . notification_count = None ;
473
494
receives room_response!( { "notification_count" : 42 } ) ;
474
495
_ = Some ( uint!( 42 ) ) ;
496
+ receives nothing;
497
+ _ = None ;
475
498
}
476
499
477
500
test_unread_notifications_with_highlight_count {
478
501
unread_notifications( ) . highlight_count = None ;
479
502
receives room_response!( { "highlight_count" : 42 } ) ;
480
503
_ = Some ( uint!( 42 ) ) ;
504
+ receives nothing;
505
+ _ = None ;
481
506
}
482
507
}
483
508
@@ -506,7 +531,9 @@ mod tests {
506
531
assert_eq ! ( room. inner. prev_batch( ) , None ) ;
507
532
508
533
room. update ( room_response ! ( { "prev_batch" : "t111_222_333" } ) , vec ! [ ] ) ;
534
+ assert_eq ! ( room. inner. prev_batch( ) , Some ( "t111_222_333" . to_string( ) ) ) ;
509
535
536
+ room. update ( room_response ! ( { } ) , vec ! [ ] ) ;
510
537
assert_eq ! ( room. inner. prev_batch( ) , Some ( "t111_222_333" . to_string( ) ) ) ;
511
538
}
512
539
}
@@ -563,7 +590,9 @@ mod tests {
563
590
} ) ,
564
591
vec ! [ ] ,
565
592
) ;
593
+ assert ! ( !room. required_state( ) . is_empty( ) ) ;
566
594
595
+ room. update ( room_response ! ( { } ) , vec ! [ ] ) ;
567
596
assert ! ( !room. required_state( ) . is_empty( ) ) ;
568
597
}
569
598
}
0 commit comments