diff --git a/lyra-ecs/src/system/graph.rs b/lyra-ecs/src/system/graph.rs index 5c32e84..68c6651 100644 --- a/lyra-ecs/src/system/graph.rs +++ b/lyra-ecs/src/system/graph.rs @@ -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, Resource>)>| -> anyhow::Result<()> { + let a_system = |view: View>>| -> 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>| -> anyhow::Result<()> { + let b_system = |view: View>>| -> 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>| -> anyhow::Result<()> { + let c_system = |view: View>>| -> 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::>(); + 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"); } } \ No newline at end of file