From 7b03fca99c0e3b0a7d1c3534f2874385c793765f Mon Sep 17 00:00:00 2001 From: Imbris Date: Tue, 6 Jun 2023 00:57:22 -0400 Subject: [PATCH] Test that attempting to delete an entity with the wrong generation doesn't clear components --- tests/tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index ded6c1cb5..4cbd17ca5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -53,6 +53,35 @@ fn task_panics() { .dispatch(&mut world); } +#[test] +fn delete_wrong_gen() { + let mut world = create_world(); + + // create + let entity_a = world.create_entity().with(CompInt(7)).build(); + assert_eq!( + world.read_component::().get(entity_a), + Some(&CompInt(7)) + ); + // delete + assert!(world.delete_entity(entity_a).is_ok()); + assert_eq!(world.read_component::().get(entity_a), None); + // create + let entity_b = world.create_entity().with(CompInt(6)).build(); + assert_eq!( + world.read_component::().get(entity_b), + Some(&CompInt(6)) + ); + assert_eq!(world.read_component::().get(entity_a), None); + // delete stale + assert!(world.delete_entity(entity_a).is_err()); + assert_eq!( + world.read_component::().get(entity_b), + Some(&CompInt(6)) + ); + assert_eq!(world.read_component::().get(entity_a), None); +} + #[test] fn dynamic_create() { struct Sys;