From 34db91480879e11e1a97d4066b4f9f7e93ff5635 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Sat, 14 Sep 2024 15:21:18 -0700 Subject: [PATCH] [unstable-rust] Use `feature(assert_matches)`. --- all-is-cubes-port/src/gltf/tests.rs | 5 +++-- all-is-cubes-port/src/lib.rs | 1 + all-is-cubes-port/src/mv.rs | 9 +++++---- all-is-cubes-ui/src/lib.rs | 1 + all-is-cubes-ui/src/ui_content/vui_manager.rs | 5 +++-- all-is-cubes/src/block/modifier.rs | 3 ++- all-is-cubes/src/character/tests.rs | 5 +++-- all-is-cubes/src/lib.rs | 1 + all-is-cubes/src/universe/universe_txn.rs | 3 ++- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/all-is-cubes-port/src/gltf/tests.rs b/all-is-cubes-port/src/gltf/tests.rs index a4eb008cc..ac7c0a134 100644 --- a/all-is-cubes-port/src/gltf/tests.rs +++ b/all-is-cubes-port/src/gltf/tests.rs @@ -1,3 +1,4 @@ +use std::assert_matches::assert_matches; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -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()); } diff --git a/all-is-cubes-port/src/lib.rs b/all-is-cubes-port/src/lib.rs index 7b387a6e6..9e2ee858f 100644 --- a/all-is-cubes-port/src/lib.rs +++ b/all-is-cubes-port/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(assert_matches)] #![feature(large_assignments)] #![move_size_limit = "5000"] #![feature(let_chains)] diff --git a/all-is-cubes-port/src/mv.rs b/all-is-cubes-port/src/mv.rs index aa22864d6..5d408153d 100644 --- a/all-is-cubes-port/src/mv.rs +++ b/all-is-cubes-port/src/mv.rs @@ -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; @@ -475,7 +476,7 @@ mod tests { ) .await .unwrap_err(); - assert!(matches!(error, ExportError::NotRepresentable { .. })); + assert_matches!(error, ExportError::NotRepresentable { .. }); } #[cfg(feature = "export")] @@ -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) diff --git a/all-is-cubes-ui/src/lib.rs b/all-is-cubes-ui/src/lib.rs index 4991683c4..f50722af2 100644 --- a/all-is-cubes-ui/src/lib.rs +++ b/all-is-cubes-ui/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(assert_matches)] #![feature(async_closure)] #![feature(large_assignments)] #![move_size_limit = "2100"] // TODO: look at `Session` size diff --git a/all-is-cubes-ui/src/ui_content/vui_manager.rs b/all-is-cubes-ui/src/ui_content/vui_manager.rs index 83eded86a..ad00ec6dc 100644 --- a/all-is-cubes-ui/src/ui_content/vui_manager.rs +++ b/all-is-cubes-ui/src/ui_content/vui_manager.rs @@ -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) { let (cctx, ccrx) = flume::bounded(1); @@ -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()); } @@ -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()); } } diff --git a/all-is-cubes/src/block/modifier.rs b/all-is-cubes/src/block/modifier.rs index c7c4fb17f..24b7b0942 100644 --- a/all-is-cubes/src/block/modifier.rs +++ b/all-is-cubes/src/block/modifier.rs @@ -280,6 +280,7 @@ pub(crate) enum ModifierUnspecialize { #[cfg(test)] mod tests { + use std::assert_matches::assert_matches; use super::*; use crate::block::{ BlockAttributes, BlockCollision, EvaluatedBlock, Evoxel, Primitive, Resolution::R2, @@ -438,7 +439,7 @@ mod tests { 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; diff --git a/all-is-cubes/src/character/tests.rs b/all-is-cubes/src/character/tests.rs index aa85691f0..4fe4bb98e 100644 --- a/all-is-cubes/src/character/tests.rs +++ b/all-is-cubes/src/character/tests.rs @@ -1,4 +1,5 @@ use alloc::sync::Arc; +use std::assert_matches::assert_matches; use euclid::{point3, Vector3D}; @@ -245,13 +246,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] diff --git a/all-is-cubes/src/lib.rs b/all-is-cubes/src/lib.rs index 390370e6e..c0fa3d566 100644 --- a/all-is-cubes/src/lib.rs +++ b/all-is-cubes/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(assert_matches)] #![feature(doc_notable_trait)] #![feature(impl_trait_in_assoc_type)] #![feature(large_assignments)] diff --git a/all-is-cubes/src/universe/universe_txn.rs b/all-is-cubes/src/universe/universe_txn.rs index ffdfed296..e71e1e920 100644 --- a/all-is-cubes/src/universe/universe_txn.rs +++ b/all-is-cubes/src/universe/universe_txn.rs @@ -983,6 +983,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() { @@ -1221,7 +1222,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]