fix id claiming test
This commit is contained in:
parent
e37a293992
commit
7ff2a6d393
|
@ -1,4 +1,4 @@
|
|||
use ecs_derive::{component_container};
|
||||
use ecs_derive::component_container;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Name(&'static str);
|
||||
|
@ -9,6 +9,9 @@ struct Vec2 {
|
|||
y: u32
|
||||
}
|
||||
|
||||
// begin paste
|
||||
// end paste
|
||||
|
||||
component_container!{
|
||||
sparse name: Name,
|
||||
contiguous 0..69 pos: Vec2,
|
||||
|
@ -31,17 +34,68 @@ mod tests {
|
|||
fn id_claiming() {
|
||||
let mut cc = ComponentContainer::new().unwrap();
|
||||
// It's empty atm
|
||||
assert_eq!(cc.component_num_next_free_id(), Some(0));
|
||||
assert_eq!(cc.component_num_claim_id(), Some(0));
|
||||
assert_eq!(cc.component_num_next_free_id(), Some(1));
|
||||
assert_eq!(cc.component_num_claim_id(), Some(1));
|
||||
match cc.component_num_next_free_id() {
|
||||
Ok(id) => assert_eq!(id, 0),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert_eq!(id, 0),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
match cc.component_num_next_free_id() {
|
||||
Ok(id) => assert_eq!(id, 1),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert_eq!(id, 1),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
for i in 2..10 {
|
||||
assert_eq!(cc.component_num_claim_id(), Some(i));
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert_eq!(id, i),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
}
|
||||
assert_eq!(cc.component_num_claim_id(), None);
|
||||
assert_eq!(cc.component_num_claim_id(), None);
|
||||
|
||||
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert!(false),
|
||||
Err(ecs::ContiguousComponentError::NoSpace) => assert!(true),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
match cc.component_num_release_id(1) {
|
||||
Ok(id) => assert_eq!(*id, 0), // uninitialzed value that isn't really important in the scope of this test
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert_eq!(id, 1),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
match cc.component_num_claim_id() {
|
||||
Ok(id) => assert!(false),
|
||||
Err(ecs::ContiguousComponentError::NoSpace) => assert!(true),
|
||||
Err(_) => assert!(false),
|
||||
}
|
||||
|
||||
// assert_eq!(cc.component_num_next_free_id(), Ok(0));
|
||||
// assert_eq!(cc.component_num_claim_id(), Ok(0));
|
||||
// assert_eq!(cc.component_num_next_free_id(), Ok(1));
|
||||
// assert_eq!(cc.component_num_claim_id(), Ok(1));
|
||||
|
||||
// for i in 2..10 {
|
||||
// assert_eq!(cc.component_num_claim_id(), Ok(i));
|
||||
// }
|
||||
// assert_eq!(cc.component_num_claim_id(), Ok(1));
|
||||
// assert_eq!(cc.component_num_claim_id(), Err(ecs::ContiguousComponentError::NoSpace));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue