improved the entity_index_map unit test (#19936)
...which previously used a HashSet, whos iter has no ordering guarantee fixes #19687 i also discovered that the asserted order in the unit test is reversed, so i fixed that. I dont know if that reversed order is intentional Edit: i referenced the wrong issue oops
This commit is contained in:
parent
4e32caf027
commit
4564a5ba0d
@ -687,36 +687,40 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn entity_index_map() {
|
fn entity_index_map() {
|
||||||
#[derive(Component)]
|
for add_before in [false, true] {
|
||||||
#[relationship(relationship_target = RelTarget)]
|
#[derive(Component)]
|
||||||
struct Rel(Entity);
|
#[relationship(relationship_target = RelTarget)]
|
||||||
|
struct Rel(Entity);
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
#[relationship_target(relationship = Rel, linked_spawn)]
|
#[relationship_target(relationship = Rel, linked_spawn)]
|
||||||
struct RelTarget(EntityHashSet);
|
struct RelTarget(Vec<Entity>);
|
||||||
|
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
let a = world.spawn_empty().id();
|
if add_before {
|
||||||
let b = world.spawn_empty().id();
|
let _ = world.spawn_empty().id();
|
||||||
let c = world.spawn_empty().id();
|
}
|
||||||
|
let a = world.spawn_empty().id();
|
||||||
|
let b = world.spawn_empty().id();
|
||||||
|
let c = world.spawn_empty().id();
|
||||||
|
let d = world.spawn_empty().id();
|
||||||
|
|
||||||
let d = world.spawn_empty().id();
|
world.entity_mut(a).add_related::<Rel>(&[b, c, d]);
|
||||||
|
|
||||||
world.entity_mut(a).add_related::<Rel>(&[b, c, d]);
|
let rel_target = world.get::<RelTarget>(a).unwrap();
|
||||||
|
let collection = rel_target.collection();
|
||||||
|
|
||||||
let rel_target = world.get::<RelTarget>(a).unwrap();
|
// Insertions should maintain ordering
|
||||||
let collection = rel_target.collection();
|
assert!(collection.iter().eq([b, c, d]));
|
||||||
|
|
||||||
// Insertions should maintain ordering
|
world.entity_mut(c).despawn();
|
||||||
assert!(collection.iter().eq(&[d, c, b]));
|
|
||||||
|
|
||||||
world.entity_mut(c).despawn();
|
let rel_target = world.get::<RelTarget>(a).unwrap();
|
||||||
|
let collection = rel_target.collection();
|
||||||
|
|
||||||
let rel_target = world.get::<RelTarget>(a).unwrap();
|
// Removals should maintain ordering
|
||||||
let collection = rel_target.collection();
|
assert!(collection.iter().eq([b, d]));
|
||||||
|
}
|
||||||
// Removals should maintain ordering
|
|
||||||
assert!(collection.iter().eq(&[d, b]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user