Finish GraphExecutor `execution` test
This commit is contained in:
parent
c3c1e81913
commit
27b0b87bd7
|
@ -106,7 +106,7 @@ impl GraphExecutor {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{View, QueryBorrow, tests::Vec2, IntoSystem, world::World, Resource};
|
use crate::{View, QueryBorrow, tests::Vec2, IntoSystem, world::World, Resource, ResourceMut};
|
||||||
|
|
||||||
use super::GraphExecutor;
|
use super::GraphExecutor;
|
||||||
|
|
||||||
|
@ -118,36 +118,48 @@ mod tests {
|
||||||
|
|
||||||
let mut exec = GraphExecutor::new();
|
let mut exec = GraphExecutor::new();
|
||||||
|
|
||||||
/// TODO:
|
let a_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||||
/// * Implement FnArg for World
|
|
||||||
/// * Implement ResourceMut
|
|
||||||
|
|
||||||
let a_system = |view: View<(QueryBorrow<Vec2>, Resource<Vec<String>>)>| -> anyhow::Result<()> {
|
|
||||||
println!("System 'a' ran!");
|
println!("System 'a' ran!");
|
||||||
|
|
||||||
let order = view.into_iter().next();
|
let mut order = view.into_iter().next().unwrap();
|
||||||
|
order.push("a".to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
let b_system = |view: View<QueryBorrow<Vec2>>| -> anyhow::Result<()> {
|
let b_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||||
println!("System 'b' ran!");
|
println!("System 'b' ran!");
|
||||||
|
|
||||||
|
let mut order = view.into_iter().next().unwrap();
|
||||||
|
order.push("b".to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
let c_system = |view: View<QueryBorrow<Vec2>>| -> anyhow::Result<()> {
|
let c_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||||
println!("System 'c' ran!");
|
println!("System 'c' ran!");
|
||||||
|
|
||||||
|
let mut order = view.into_iter().next().unwrap();
|
||||||
|
order.push("c".to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
exec.insert_system("c", c_system.into_system(), &[]);
|
// inserted into the graph out of order...
|
||||||
|
exec.insert_system("c", c_system.into_system(), &["b"]);
|
||||||
exec.insert_system("a", a_system.into_system(), &[]);
|
exec.insert_system("a", a_system.into_system(), &[]);
|
||||||
exec.insert_system("b", b_system.into_system(), &["a"]);
|
exec.insert_system("b", b_system.into_system(), &["a"]);
|
||||||
|
|
||||||
|
|
||||||
exec.execute(&world, true).unwrap();
|
exec.execute(&world, true).unwrap();
|
||||||
println!("Executed systems");
|
println!("Executed systems");
|
||||||
|
|
||||||
|
let order = world.get_resource::<Vec<String>>();
|
||||||
|
let mut order_iter = order.iter();
|
||||||
|
|
||||||
|
// ... but still executed in order
|
||||||
|
assert_eq!(order_iter.next().unwrap().clone(), "a".to_string());
|
||||||
|
assert_eq!(order_iter.next().unwrap().clone(), "b".to_string());
|
||||||
|
assert_eq!(order_iter.next().unwrap().clone(), "c".to_string());
|
||||||
|
println!("Systems executed in order");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue