Skip to content

Commit

Permalink
Adjust CubeTransaction debug prints and tests.
Browse files Browse the repository at this point in the history
Broken by not testing previous changes.
  • Loading branch information
kpreid committed Oct 18, 2023
1 parent fdcf85d commit 429f2b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
20 changes: 13 additions & 7 deletions all-is-cubes/src/inv/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,11 @@ mod tests {
});
let transaction = tester.equip_and_use_tool(tool.clone()).unwrap();

let mut expected_cube_transaction =
SpaceTransaction::set_cube(Cube::ORIGIN, Some(AIR), Some(tool_block.clone()));
expected_cube_transaction.add_fluff(Cube::ORIGIN, Fluff::PlaceBlockGeneric);
let expected_cube_transaction =
SpaceTransaction::set_cube([0, 0, 0], Some(AIR), Some(tool_block.clone()))
.bind(tester.space_ref.clone());
expected_cube_transaction.bind(tester.space_ref.clone());
assert_eq!(
transaction,
if expect_consume {
Expand Down Expand Up @@ -809,11 +811,15 @@ mod tests {
.unwrap();
assert_eq!(
transaction,
SpaceTransaction::set_cube(
[0, 0, 0],
Some(AIR),
Some(tool_block.clone().rotate(GridRotation::CLOCKWISE))
)
{
let mut t = SpaceTransaction::set_cube(
[0, 0, 0],
Some(AIR),
Some(tool_block.clone().rotate(GridRotation::CLOCKWISE)),
);
t.add_fluff(Cube::ORIGIN, Fluff::PlaceBlockGeneric);
t
}
.bind(tester.space_ref.clone())
);
}
Expand Down
34 changes: 30 additions & 4 deletions all-is-cubes/src/space/space_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ impl Merge for SpaceTransaction {

impl fmt::Debug for SpaceTransaction {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { cubes, behaviors } = self;
let mut ds = fmt.debug_struct("SpaceTransaction");
for (cube, txn) in &self.cubes {
for (cube, txn) in cubes {
ds.field(&Cube::from(*cube).refmt(&ConciseDebug).to_string(), txn);
}
if !self.behaviors.is_empty() {
ds.field("behaviors", &self.behaviors);
if !behaviors.is_empty() {
ds.field("behaviors", &behaviors);
}
ds.finish()
}
Expand Down Expand Up @@ -444,7 +445,7 @@ impl fmt::Display for SpaceTransactionConflict {

/// Data for a single cube in a [`SpaceTransaction`]. This does not function as a
/// transaction on its own, though it does implement [`Merge`].
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Default, Eq, PartialEq)]
struct CubeTransaction {
/// Previous block which must occupy this cube.
/// If `None`, no precondition.
Expand All @@ -471,6 +472,31 @@ struct CubeTransaction {
fluff: Vec<Fluff>,
}

impl fmt::Debug for CubeTransaction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
old,
new,
conserved,
activate,
fluff,
} = self;
let mut ds = f.debug_struct("CubeTransaction");
if old.is_some() || new.is_some() {
ds.field("old", &old);
ds.field("new", &new);
ds.field("conserved", &conserved);
}
if *activate {
ds.field("activate", &activate);
}
if !fluff.is_empty() {
ds.field("fluff", &fluff);
}
ds.finish()
}
}

impl CubeTransaction {
const ACTIVATE: Self = Self {
old: None,
Expand Down
1 change: 0 additions & 1 deletion all-is-cubes/src/universe/universe_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ mod tests {
},
),
conserved: true,
activate: false,
},
},
}
Expand Down

0 comments on commit 429f2b4

Please sign in to comment.