@@ -685,7 +685,7 @@ mod tests {
685685 } ,
686686 renderer:: RenderContext ,
687687 } ;
688- use bevy_ecs:: world:: World ;
688+ use bevy_ecs:: world:: { FromWorld , World } ;
689689 use bevy_utils:: HashSet ;
690690
691691 #[ derive( Debug ) ]
@@ -726,6 +726,22 @@ mod tests {
726726 }
727727 }
728728
729+ fn input_nodes ( name : & ' static str , graph : & RenderGraph ) -> HashSet < NodeId > {
730+ graph
731+ . iter_node_inputs ( name)
732+ . unwrap ( )
733+ . map ( |( _edge, node) | node. id )
734+ . collect :: < HashSet < NodeId > > ( )
735+ }
736+
737+ fn output_nodes ( name : & ' static str , graph : & RenderGraph ) -> HashSet < NodeId > {
738+ graph
739+ . iter_node_outputs ( name)
740+ . unwrap ( )
741+ . map ( |( _edge, node) | node. id )
742+ . collect :: < HashSet < NodeId > > ( )
743+ }
744+
729745 #[ test]
730746 fn test_graph_edges ( ) {
731747 let mut graph = RenderGraph :: default ( ) ;
@@ -738,22 +754,6 @@ mod tests {
738754 graph. add_node_edge ( "B" , "C" ) ;
739755 graph. add_slot_edge ( "C" , 0 , "D" , 0 ) ;
740756
741- fn input_nodes ( name : & ' static str , graph : & RenderGraph ) -> HashSet < NodeId > {
742- graph
743- . iter_node_inputs ( name)
744- . unwrap ( )
745- . map ( |( _edge, node) | node. id )
746- . collect :: < HashSet < NodeId > > ( )
747- }
748-
749- fn output_nodes ( name : & ' static str , graph : & RenderGraph ) -> HashSet < NodeId > {
750- graph
751- . iter_node_outputs ( name)
752- . unwrap ( )
753- . map ( |( _edge, node) | node. id )
754- . collect :: < HashSet < NodeId > > ( )
755- }
756-
757757 assert ! ( input_nodes( "A" , & graph) . is_empty( ) , "A has no inputs" ) ;
758758 assert ! (
759759 output_nodes( "A" , & graph) == HashSet :: from_iter( vec![ c_id] ) ,
@@ -853,4 +853,48 @@ mod tests {
853853 "Adding to a duplicate edge should return an error"
854854 ) ;
855855 }
856+
857+ #[ test]
858+ fn test_add_node_with_edges ( ) {
859+ struct SimpleNode ;
860+ impl Node for SimpleNode {
861+ fn run (
862+ & self ,
863+ _graph : & mut RenderGraphContext ,
864+ _render_context : & mut RenderContext ,
865+ _world : & World ,
866+ ) -> Result < ( ) , NodeRunError > {
867+ Ok ( ( ) )
868+ }
869+ }
870+ impl FromWorld for SimpleNode {
871+ fn from_world ( _world : & mut World ) -> Self {
872+ Self
873+ }
874+ }
875+
876+ let mut graph = RenderGraph :: default ( ) ;
877+ let a_id = graph. add_node ( "A" , SimpleNode ) ;
878+ let c_id = graph. add_node ( "C" , SimpleNode ) ;
879+
880+ // A and C need to exist first
881+ let b_id = graph. add_node_with_edges ( "B" , SimpleNode , & [ "A" , "B" , "C" ] ) ;
882+
883+ assert ! (
884+ output_nodes( "A" , & graph) == HashSet :: from_iter( vec![ b_id] ) ,
885+ "A -> B"
886+ ) ;
887+ assert ! (
888+ input_nodes( "B" , & graph) == HashSet :: from_iter( vec![ a_id] ) ,
889+ "B -> C"
890+ ) ;
891+ assert ! (
892+ output_nodes( "B" , & graph) == HashSet :: from_iter( vec![ c_id] ) ,
893+ "B -> C"
894+ ) ;
895+ assert ! (
896+ input_nodes( "C" , & graph) == HashSet :: from_iter( vec![ b_id] ) ,
897+ "B -> C"
898+ ) ;
899+ }
856900}
0 commit comments