use behaviortree_rs::{blackboard::Blackboard, macros::register_action_node, tree::Factory}; use log::{error, info}; mod nodes; use nodes::{EchoNode, RunForNode, StatusNode}; #[tokio::test] async fn fallback() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("{status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn if_then_else() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn parallel_all() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn parallel() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn reactive_fallback() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn reactive_sequence() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); register_action_node!(factory, "RunForNode", RunForNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn sequence_star() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); register_action_node!(factory, "RunForNode", RunForNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn sequence_vanilla() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); register_action_node!(factory, "RunForNode", RunForNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } } #[tokio::test] async fn while_do_else() { nodes::test_setup(); let xml = r#" "# .to_string(); let mut factory = Factory::new(); register_action_node!(factory, "StatusNode", StatusNode); register_action_node!(factory, "EchoNode", EchoNode); register_action_node!(factory, "RunForNode", RunForNode); let blackboard = Blackboard::create(); factory.register_bt_from_text(xml).unwrap(); let mut tree = factory .instantiate_async_tree(&blackboard, "main") .await .unwrap(); match tree.tick_while_running().await { Ok(status) => info!("Final status: {status:?}"), Err(e) => error!("{e}"), } }