Skip to content

Commit

Permalink
[unstable-rust] Use feature(assert_matches).
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 15, 2024
1 parent 58a6c90 commit e64a3cc
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 62 deletions.
5 changes: 3 additions & 2 deletions all-is-cubes-port/src/gltf/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::assert_matches::assert_matches;
use std::path::{Path, PathBuf};
use std::time::Duration;

Expand Down Expand Up @@ -146,11 +147,11 @@ async fn export_character_not_supported() {
)
.await
.unwrap_err();
assert!(matches!(
assert_matches!(
error,
ExportError::NotRepresentable {
name: Some(name),
..
}
if name == "x".into()));
if name == "x".into());
}
1 change: 1 addition & 0 deletions all-is-cubes-port/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(assert_matches)]
#![feature(large_assignments)]
#![move_size_limit = "5000"]
#![feature(let_chains)]
Expand Down
9 changes: 5 additions & 4 deletions all-is-cubes-port/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ fn aic_to_mv_coordinate_transform(aic_bounds: GridAab) -> Gridgid {

#[cfg(test)]
mod tests {
use super::*;
use std::assert_matches::assert_matches;
use super::*;
use all_is_cubes::block::BlockDef;
use all_is_cubes::universe::Handle;
use all_is_cubes::util::yield_progress_for_testing;
Expand Down Expand Up @@ -475,7 +476,7 @@ mod tests {
)
.await
.unwrap_err();
assert!(matches!(error, ExportError::NotRepresentable { .. }));
assert_matches!(error, ExportError::NotRepresentable { .. });
}

#[cfg(feature = "export")]
Expand All @@ -492,13 +493,13 @@ mod tests {
)
.await
.unwrap_err();
assert!(matches!(
assert_matches!(
error,
ExportError::NotRepresentable {
name: Some(name),
..
}
if name == "x".into()));
if name == "x".into());
}

// TODO: add tests of loading valid files (we will need to create test data files)
Expand Down
1 change: 1 addition & 0 deletions all-is-cubes-ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(assert_matches)]
#![feature(large_assignments)]
#![move_size_limit = "2500"] // TODO: look at `Session` size
#![feature(let_chains)]
Expand Down
5 changes: 3 additions & 2 deletions all-is-cubes-ui/src/ui_content/vui_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ pub(crate) enum CueMessage {
#[cfg(test)]
mod tests {
use super::*;
use std::assert_matches::assert_matches;

async fn new_vui_for_test(paused: bool) -> (Vui, flume::Receiver<ControlMessage>) {
let (cctx, ccrx) = flume::bounded(1);
Expand All @@ -603,7 +604,7 @@ mod tests {
let (mut vui, control_channel) = new_vui_for_test(false).await;
vui.back();
let msg = control_channel.try_recv().unwrap();
assert!(matches!(msg, ControlMessage::TogglePause), "{msg:?}");
assert_matches!(msg, ControlMessage::TogglePause);
assert!(control_channel.try_recv().is_err());
}

Expand All @@ -613,7 +614,7 @@ mod tests {
vui.set_state(VuiPageState::Paused);
vui.back();
let msg = control_channel.try_recv().unwrap();
assert!(matches!(msg, ControlMessage::TogglePause), "{msg:?}");
assert_matches!(msg, ControlMessage::TogglePause);
assert!(control_channel.try_recv().is_err());
}
}
10 changes: 4 additions & 6 deletions all-is-cubes/src/block/modifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ mod tests {
use super::*;
use crate::block::BlockAttributes;
use pretty_assertions::assert_eq;


/// Track the size of the `Modifier` enum to make sure we don't accidentally make it bigger
/// by giving one variant more data.
Expand All @@ -313,10 +314,8 @@ mod tests {
Modifier::Composite(Composite::new(block::AIR, CompositeOperator::Over)),
Modifier::Inventory(inv::Inventory::from_slots([])),
];
assert_eq!(
format!("{modifiers:#?}"),
indoc::indoc! {
r#"[
assert_eq!(format!("{modifiers:#?}"), indoc::indoc! {
r#"[
BlockAttributes {
display_name: "hello",
},
Expand All @@ -336,7 +335,6 @@ mod tests {
slots: [],
},
]"#
}
);
});
}
}
89 changes: 44 additions & 45 deletions all-is-cubes/src/block/modifier/rotate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! The modifier implementation itself is so simple that it does not have its own file.
use std::assert_matches::assert_matches;

use super::*;
use crate::block::{
BlockAttributes, BlockCollision, EvaluatedBlock, Evoxel, Primitive, Resolution::R2, TickAction,
Expand Down Expand Up @@ -51,54 +53,51 @@ fn rotate_evaluation() {
let rotated = block.clone().rotate(rotation);
let re = rotated.evaluate().unwrap();

assert_eq!(
re,
EvaluatedBlock {
block: rotated.clone(),
voxels: Evoxels::from_many(
R2,
assert_eq!(re, EvaluatedBlock {
block: rotated.clone(),
voxels: Evoxels::from_many(
R2,
Vol::from_fn(block_bounds, |cube| {
Evoxel {
color: rotated_color_fn(cube),
emission: Rgb::ZERO,
selectable: true,
collision: BlockCollision::Hard,
}
})
),
attributes: BlockAttributes {
display_name: "foo".into(),
tick_action: Some(TickAction::from(Operation::Become(
replacement.rotate(rotation).clone()
))),
rotation_rule: block::RotationPlacementRule::Attach { by: Face6::PY },
..BlockAttributes::default()
},
cost: block::Cost {
components: 3, // Primitive + display_name + Rotate
voxels: 2u32.pow(3) * 2, // original + rotation
recursion: 0
},
derived: block::Derived {
color: be.color(),
face_colors: be.face_colors().rotate(rotation),
light_emission: Rgb::ZERO,
opaque: FaceMap::splat(false).with(rotation.transform(Face6::NY), true),
visible: true,
uniform_collision: Some(BlockCollision::Hard),
voxel_opacity_mask: block::VoxelOpacityMask::new_raw(
resolution,
Vol::from_fn(block_bounds, |cube| {
Evoxel {
color: rotated_color_fn(cube),
emission: Rgb::ZERO,
selectable: true,
collision: BlockCollision::Hard,
if cube.x == 0 {
OpacityCategory::Opaque
} else {
OpacityCategory::Invisible
}
})
),
attributes: BlockAttributes {
display_name: "foo".into(),
tick_action: Some(TickAction::from(Operation::Become(
replacement.rotate(rotation).clone()
))),
rotation_rule: block::RotationPlacementRule::Attach { by: Face6::PY },
..BlockAttributes::default()
},
cost: block::Cost {
components: 3, // Primitive + display_name + Rotate
voxels: 2u32.pow(3) * 2, // original + rotation
recursion: 0
},
derived: block::Derived {
color: be.color(),
face_colors: be.face_colors().rotate(rotation),
light_emission: Rgb::ZERO,
opaque: FaceMap::splat(false).with(rotation.transform(Face6::NY), true),
visible: true,
uniform_collision: Some(BlockCollision::Hard),
voxel_opacity_mask: block::VoxelOpacityMask::new_raw(
resolution,
Vol::from_fn(block_bounds, |cube| {
if cube.x == 0 {
OpacityCategory::Opaque
} else {
OpacityCategory::Invisible
}
})
),
},
}
);
},
});
}

/// Check that [`Block::rotate`]'s pre-composition is consistent with the interpretation
Expand All @@ -107,7 +106,7 @@ fn rotate_evaluation() {
fn rotate_rotated_consistency() {
let mut universe = Universe::new();
let [block] = make_some_voxel_blocks(&mut universe);
assert!(matches!(block.primitive(), Primitive::Recur { .. }));
assert_matches!(block.primitive(), Primitive::Recur { .. });

// Two rotations not in the same plane, so they are not commutative.
let rotation_1 = GridRotation::RyXZ;
Expand Down
5 changes: 3 additions & 2 deletions all-is-cubes/src/character/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::sync::Arc;
use std::assert_matches::assert_matches;

use euclid::{point3, Vector3D};

Expand Down Expand Up @@ -258,13 +259,13 @@ fn click_wrong_space_or_correct_space() {
let cursor = cursor_raycast(Ray::new([0.5, 0.5, 0.5], [1., 0., 0.]), &sp1, 10.);
assert!(cursor.is_some());
let error = Character::click(character.clone(), cursor.as_ref(), 0).unwrap_err();
assert!(matches!(error, ToolError::Internal(_)));
assert_matches!(error, ToolError::Internal(_));

// Click in right space
let cursor = cursor_raycast(Ray::new([0.5, 0.5, 0.5], [1., 0., 0.]), &sp2, 10.);
assert!(cursor.is_some());
let error = Character::click(character, cursor.as_ref(), 0).unwrap_err();
assert!(matches!(error, ToolError::NoTool));
assert_matches!(error, ToolError::NoTool);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions all-is-cubes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(assert_matches)]
#![feature(doc_notable_trait)]
#![feature(impl_trait_in_assoc_type)]
#![feature(large_assignments)]
Expand Down
3 changes: 2 additions & 1 deletion all-is-cubes/src/universe/universe_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ mod tests {
use crate::universe::{self, HandleError};
use alloc::sync::Arc;
use indoc::indoc;
use std::assert_matches::assert_matches;

#[test]
fn has_default() {
Expand Down Expand Up @@ -1215,7 +1216,7 @@ mod tests {
let t1 = SpaceTransaction::set_cube([0, 0, 0], None, Some(block)).bind(s1);

let e = t1.execute(&mut u2, &mut drop).unwrap_err();
assert!(matches!(e, ExecuteError::Check(_)));
assert_matches!(e, ExecuteError::Check(_));
}

#[test]
Expand Down

0 comments on commit e64a3cc

Please sign in to comment.