Finish GraphExecutor `execution` test
This commit is contained in:
parent
c3c1e81913
commit
27b0b87bd7
|
@ -106,7 +106,7 @@ impl GraphExecutor {
|
|||
|
||||
#[cfg(test)]
|
||||
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;
|
||||
|
||||
|
@ -118,36 +118,48 @@ mod tests {
|
|||
|
||||
let mut exec = GraphExecutor::new();
|
||||
|
||||
/// TODO:
|
||||
/// * Implement FnArg for World
|
||||
/// * Implement ResourceMut
|
||||
|
||||
let a_system = |view: View<(QueryBorrow<Vec2>, Resource<Vec<String>>)>| -> anyhow::Result<()> {
|
||||
let a_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||
println!("System 'a' ran!");
|
||||
|
||||
let order = view.into_iter().next();
|
||||
let mut order = view.into_iter().next().unwrap();
|
||||
order.push("a".to_string());
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
let b_system = |view: View<QueryBorrow<Vec2>>| -> anyhow::Result<()> {
|
||||
let b_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||
println!("System 'b' ran!");
|
||||
|
||||
let mut order = view.into_iter().next().unwrap();
|
||||
order.push("b".to_string());
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
let c_system = |view: View<QueryBorrow<Vec2>>| -> anyhow::Result<()> {
|
||||
let c_system = |view: View<ResourceMut<Vec<String>>>| -> anyhow::Result<()> {
|
||||
println!("System 'c' ran!");
|
||||
|
||||
let mut order = view.into_iter().next().unwrap();
|
||||
order.push("c".to_string());
|
||||
|
||||
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("b", b_system.into_system(), &["a"]);
|
||||
|
||||
|
||||
exec.execute(&world, true).unwrap();
|
||||
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