Skip to content

Commit

Permalink
create test for checking with_id
Browse files Browse the repository at this point in the history
It seems like the entity itself is changing when
adding a component.

Not sure if it's a bug in with_id() or something deeper.
  • Loading branch information
dakom committed Dec 18, 2019
1 parent 2ccdae2 commit 76f6161
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/lib.rs
Expand Up @@ -1738,6 +1738,55 @@ fn not_unique_storage() {
}
}

#[test]
fn key_equality() {
let world = World::default();
world.register::<usize>();
world.register::<u32>();

//create 3 entities
let (e0, e1, e2) = world.run::<(EntitiesMut, &mut usize), _, _>(
|(mut entities, mut usizes)| {
(
entities.add_entity(&mut usizes, 0),
entities.add_entity(&mut usizes, 1),
entities.add_entity(&mut usizes, 2)
)
},
);

//add a component to e1
world.run::<(EntitiesMut, &mut u32), _, _>(
|(ref mut entities, ref mut u32s)| {
entities.add_component(u32s, 42, e1);
}
);

//confirm that the entity keys have not changed for usizes storage
world.run::<&usize, _, _>(
|usizes| {
//sanity check
assert_eq!((&usizes).iter().with_id().count(), 3);

let keys:Vec<Key> = (&usizes).iter().with_id().map(|(entity, _)| entity).collect();

assert_eq!(keys, vec![e0, e1, e2]);
}
);

//confirm that the entity key for (usize) is the same as (usize, u32)
//in other words that the entity itself did not somehow change from adding a component
world.run::<(&usize, &u32), _, _>(
|(usizes, u32s)| {
//sanity check
assert_eq!((&usizes, &u32s).iter().with_id().count(), 1);

let (entity, _, _) = (&usizes, &u32s).iter().with_id().next().unwrap();
assert_eq!(entity, e1);
}
);
}

#[test]
fn unique_storage_pack() {
let world = World::new::<(u32,)>();
Expand Down

0 comments on commit 76f6161

Please sign in to comment.