Build production-ready editor authoring workflows
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-07-11 12:41:04 -04:00
1 parent cc1fa6ea3b
commit 0553a85220
163 files changed
+34547 -1565

No files matched your search

+69 -26
View File
@@ -4,6 +4,9 @@ use bevy::prelude::*;
use crate::history::EditorHistory;
#[cfg(test)]
pub(crate) mod test_harness;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OperatorPhase {
Idle,
@@ -227,12 +230,19 @@ fn set_operator_status(world: &mut World, status: OperatorStatus) {
#[cfg(test)]
mod tests {
use super::*;
use crate::history::EditorHistory;
use crate::operators::test_harness::OperatorInvariantHarness;
use crate::scene_io::SceneIo;
#[derive(Resource, Default)]
struct Counter(i32);
#[derive(Component)]
struct PreviewHelper;
struct CounterOperator {
before: i32,
helper: Option<Entity>,
}
impl EditorOperator for CounterOperator {
@@ -246,6 +256,7 @@ mod tests {
fn begin(&mut self, world: &mut World) -> Result<(), String> {
self.before = world.resource::<Counter>().0;
self.helper = Some(world.spawn(PreviewHelper).id());
Ok(())
}
@@ -254,34 +265,50 @@ mod tests {
Ok(())
}
fn commit(&mut self, _world: &mut World) -> Result<(), String> {
fn commit(&mut self, world: &mut World) -> Result<(), String> {
self.remove_helper(world);
Ok(())
}
fn cancel(&mut self, world: &mut World) {
world.resource_mut::<Counter>().0 = self.before;
self.remove_helper(world);
}
}
impl CounterOperator {
fn remove_helper(&mut self, world: &mut World) {
if let Some(helper) = self.helper.take() {
if let Ok(entity) = world.get_entity_mut(helper) {
entity.despawn();
}
}
}
}
fn test_world() -> World {
let mut world = World::new();
world.init_resource::<ActiveOperator>();
world.init_resource::<Counter>();
world.init_resource::<EditorHistory>();
world.init_resource::<SceneIo>();
world
}
#[test]
fn operator_commit_keeps_previewed_change() {
let mut world = World::new();
world.init_resource::<ActiveOperator>();
world.init_resource::<Counter>();
let mut world = test_world();
let harness = OperatorInvariantHarness::capture(&mut world);
let mut operator = CounterOperator { before: 0 };
let mut operator = CounterOperator {
before: 0,
helper: None,
};
assert!(run_operator(&mut world, &mut operator));
assert_eq!(world.resource::<Counter>().0, 1);
assert_eq!(
world
.resource::<ActiveOperator>()
.status
.as_ref()
.unwrap()
.phase,
OperatorPhase::Committed
);
harness.assert_committed(&mut world, 0, 0);
harness.assert_no_helpers::<PreviewHelper>(&mut world);
}
#[test]
@@ -314,22 +341,38 @@ mod tests {
}
}
let mut world = World::new();
world.init_resource::<ActiveOperator>();
world.init_resource::<Counter>();
let mut world = test_world();
let harness = OperatorInvariantHarness::capture(&mut world);
let mut operator = FailingCounterOperator(CounterOperator { before: 0 });
let mut operator = FailingCounterOperator(CounterOperator {
before: 0,
helper: None,
});
assert!(!run_operator(&mut world, &mut operator));
assert_eq!(world.resource::<Counter>().0, 0);
assert_eq!(
world
.resource::<ActiveOperator>()
.status
.as_ref()
.unwrap()
.phase,
OperatorPhase::Canceled
harness.assert_canceled(&mut world);
harness.assert_no_helpers::<PreviewHelper>(&mut world);
}
#[test]
fn blocked_operator_never_begins_or_mutates_world() {
let mut world = test_world();
let harness = OperatorInvariantHarness::capture(&mut world);
let result = run_immediate_operator(
&mut world,
"test.blocked",
"Blocked Operator",
OperatorAvailability::Disabled("fixture unavailable".to_string()),
|world| {
world.resource_mut::<Counter>().0 += 1;
Ok(())
},
);
assert!(!result);
assert_eq!(world.resource::<Counter>().0, 0);
harness.assert_blocked(&mut world);
}
}