use bevy_ecs::system::RunSystemOnce;
use super::*;
fn coming(world: &mut World, agent: Entity) -> bool {
let coming = move |inboxes: Inboxes| inboxes.coming(agent);
world.run_system_once(coming).ok() == Some(true)
}
fn steer(world: &mut World, agent: Entity, text: &str) -> Entity {
let message = Incoming::new(text, DeliveryMode::Steer);
world
.spawn((message, Decision::default(), ForAgent(agent)))
.id()
}
#[test]
fn a_message_superseded_or_settled_is_not_on_its_way() {
let mut world = World::new();
let agent = world.spawn_empty().id();
let held = steer(&mut world, agent, "count: !{printf 3}");
assert!(coming(&mut world, agent));
let expanded = steer(&mut world, agent, "count: 3");
world.entity_mut(held).insert(SupersededBy(expanded));
assert!(coming(&mut world, agent));
let at = std::time::SystemTime::UNIX_EPOCH;
world.entity_mut(expanded).insert(Started { at });
assert!(!coming(&mut world, agent));
let dropped = steer(&mut world, agent, "never mind");
assert!(coming(&mut world, agent));
world.entity_mut(dropped).insert(Settled);
assert!(!coming(&mut world, agent));
}