Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[unstable-rust] Use feature(assert_matches).
Browse files Browse the repository at this point in the history
kpreid committed Sep 14, 2024
1 parent 71a5783 commit ebe7279
Showing 9 changed files with 21 additions and 12 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;

@@ -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)]
9 changes: 5 additions & 4 deletions all-is-cubes-port/src/mv.rs
Original file line number Diff line number Diff line change
@@ -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)
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 = "2100"] // TODO: look at `Session` size
#![feature(let_chains)]
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
@@ -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);
@@ -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());
}
}
3 changes: 2 additions & 1 deletion all-is-cubes/src/block/modifier.rs
Original file line number Diff line number Diff line change
@@ -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;
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};

@@ -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]
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)]
3 changes: 2 additions & 1 deletion all-is-cubes/src/universe/universe_txn.rs
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit ebe7279

Please sign in to comment.