Skip to content

Commit 20fd3cc

Browse files
add test checking that as_readonly works as expected
1 parent 1305079 commit 20fd3cc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

crates/bevy_ecs/src/query/state.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,33 @@ mod tests {
14421442
}
14431443
}
14441444

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+
14451472
#[test]
14461473
fn query_state_with_config_vec() {
14471474
let mut world = World::new();

0 commit comments

Comments
 (0)