Skip to content

Commit

Permalink
add test checking that as_readonly works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Oct 28, 2022
1 parent 4351ac2 commit f34b1b7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TestComponent>();
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::<TestComponent>() };
assert_eq!(value.0, num);
}
_ => panic!("expected to get one result"),
}
}

#[test]
fn query_state_with_config_vec() {
let mut world = World::new();
Expand Down

0 comments on commit f34b1b7

Please sign in to comment.