From f34b1b78cf80124d4f922a2627f3229100146490 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Fri, 28 Oct 2022 12:07:55 +0200 Subject: [PATCH] add test checking that as_readonly works as expected --- crates/bevy_ecs/src/query/state.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 5ca6311d960f38..0d2b60c9922237 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -1427,6 +1427,33 @@ mod tests { } } + #[test] + fn query_state_with_config_as_readonly() { + let mut world = World::new(); + + let num = 42; + + let component_id = world.init_component::(); + let spawned_entity = world.spawn(TestComponent(num)).id(); + + let mut query_state = QueryState::<(Entity, PtrMut<'_>), ()>::new_with_config( + &mut world, + ((), component_id), + (), + ); + + let results: Vec<_> = query_state.iter(&world).collect(); + match results.as_slice() { + [(entity, value)] => { + assert_eq!(*entity, spawned_entity); + // SAFETY: correct type, read access + let value = unsafe { value.deref::() }; + assert_eq!(value.0, num); + } + _ => panic!("expected to get one result"), + } + } + #[test] fn query_state_with_config_vec() { let mut world = World::new();