1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use anymap::AnyMap;
#[derive(Debug)]
pub struct Entity {
pub label: String,
pub components: AnyMap,
}
impl Entity {
pub fn new(label: String) -> Entity {
Entity {
label: label,
components: AnyMap::new(),
}
}
}
impl PartialEq for Entity {
fn eq(&self, other: &Entity) -> bool {
self.label == other.label
}
}
#[cfg(test)]
mod tests {
use ::EntityBuilder;
#[derive(Debug, PartialEq)]
struct TestComponent(pub u8);
#[derive(Debug, PartialEq)]
struct AnotherComponent;
#[test]
fn entity_can_contain_components() {
let entity = EntityBuilder::create_str("test")
.add(TestComponent(1))
.build();
assert_eq!(entity.label, "test");
assert_eq!(entity.components.get::<TestComponent>(),
Some(&TestComponent(1)));
}
#[test]
fn entity_has_components_works() {
let entity = EntityBuilder::create_str("test")
.add(TestComponent(1))
.build();
assert!(entity.components.contains::<TestComponent>());
assert!(!entity.components.contains::<AnotherComponent>());
let entity = EntityBuilder::create_str("test")
.add(AnotherComponent)
.build();
assert!(!entity.components.contains::<TestComponent>());
assert!(entity.components.contains::<AnotherComponent>());
}
}