File tree 1 file changed +27
-0
lines changed
crates/bevy_ecs/src/query
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1442,6 +1442,33 @@ mod tests {
1442
1442
}
1443
1443
}
1444
1444
1445
+ #[ test]
1446
+ fn query_state_with_config_as_readonly ( ) {
1447
+ let mut world = World :: new ( ) ;
1448
+
1449
+ let num = 42 ;
1450
+
1451
+ let component_id = world. init_component :: < TestComponent > ( ) ;
1452
+ let spawned_entity = world. spawn ( TestComponent ( num) ) . id ( ) ;
1453
+
1454
+ let mut query_state = QueryState :: < ( Entity , PtrMut < ' _ > ) , ( ) > :: new_with_config (
1455
+ & mut world,
1456
+ ( ( ) , component_id) ,
1457
+ ( ) ,
1458
+ ) ;
1459
+
1460
+ let results: Vec < _ > = query_state. iter ( & world) . collect ( ) ;
1461
+ match results. as_slice ( ) {
1462
+ [ ( entity, value) ] => {
1463
+ assert_eq ! ( * entity, spawned_entity) ;
1464
+ // SAFETY: correct type, read access
1465
+ let value = unsafe { value. deref :: < TestComponent > ( ) } ;
1466
+ assert_eq ! ( value. 0 , num) ;
1467
+ }
1468
+ _ => panic ! ( "expected to get one result" ) ,
1469
+ }
1470
+ }
1471
+
1445
1472
#[ test]
1446
1473
fn query_state_with_config_vec ( ) {
1447
1474
let mut world = World :: new ( ) ;
You can’t perform that action at this time.
0 commit comments