File tree 1 file changed +30
-0
lines changed
crates/bevy_ecs/src/system
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -463,6 +463,11 @@ mod tests {
463
463
#[ derive( Resource , Default , PartialEq , Debug ) ]
464
464
struct Counter ( u8 ) ;
465
465
466
+ #[ derive( Event ) ]
467
+ struct MyEvent {
468
+ cancelled : bool ,
469
+ }
470
+
466
471
#[ test]
467
472
fn change_detection ( ) {
468
473
#[ derive( Resource , Default ) ]
@@ -664,4 +669,29 @@ mod tests {
664
669
world. run_system_with_input ( id, & 2 ) . unwrap ( ) ;
665
670
assert_eq ! ( * world. resource:: <Counter >( ) , Counter ( 2 ) ) ;
666
671
}
672
+
673
+ #[ test]
674
+ fn system_with_input_mut ( ) {
675
+ fn post ( InMut ( event) : InMut < MyEvent > , counter : ResMut < Counter > ) {
676
+ if counter. 0 > 0 {
677
+ event. cancelled = true ;
678
+ }
679
+ }
680
+
681
+ let mut world = World :: new ( ) ;
682
+ world. insert_resource ( Counter ( 0 ) ) ;
683
+ let post_system = world. register_system ( post) ;
684
+
685
+ let mut event = MyEvent { cancelled : false } ;
686
+ world
687
+ . run_system_with_input ( post_system, & mut event)
688
+ . unwrap ( ) ;
689
+ assert ! ( !event. cancelled) ;
690
+
691
+ world. resource_mut :: < Counter > ( ) . 0 = 1 ;
692
+ world
693
+ . run_system_with_input ( post_system, & mut event)
694
+ . unwrap ( ) ;
695
+ assert ! ( event. cancelled) ;
696
+ }
667
697
}
You can’t perform that action at this time.
0 commit comments