Simplify equality assertions (#10988)

# Objective

- Shorten assertions.

## Solution

- Replace '==' assertions with 'assert_eq()' and '!=' assertions with
'assert_ne()' .
This commit is contained in:
Tygyh 2023-12-17 00:58:41 +01:00 committed by GitHub
parent 645625b789
commit 63d17e8494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 51 additions and 40 deletions

View File

@ -4,9 +4,9 @@ use syn::{parse_macro_input, ItemFn};
pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream { pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemFn); let input = parse_macro_input!(item as ItemFn);
assert!( assert_eq!(
input.sig.ident == "main", input.sig.ident, "main",
"`bevy_main` can only be used on a function called 'main'.", "`bevy_main` can only be used on a function called 'main'."
); );
TokenStream::from(quote! { TokenStream::from(quote! {

View File

@ -1051,8 +1051,8 @@ mod tests {
for tracker in query.iter(&world) { for tracker in query.iter(&world) {
let ticks_since_insert = change_tick.relative_to(*tracker.ticks.added).get(); let ticks_since_insert = change_tick.relative_to(*tracker.ticks.added).get();
let ticks_since_change = change_tick.relative_to(*tracker.ticks.changed).get(); let ticks_since_change = change_tick.relative_to(*tracker.ticks.changed).get();
assert!(ticks_since_insert == MAX_CHANGE_AGE); assert_eq!(ticks_since_insert, MAX_CHANGE_AGE);
assert!(ticks_since_change == MAX_CHANGE_AGE); assert_eq!(ticks_since_change, MAX_CHANGE_AGE);
} }
} }

View File

@ -977,10 +977,10 @@ mod tests {
// This is intentionally testing `lt` and `ge` as separate functions. // This is intentionally testing `lt` and `ge` as separate functions.
#![allow(clippy::nonminimal_bool)] #![allow(clippy::nonminimal_bool)]
assert!(Entity::new(123, 456) == Entity::new(123, 456)); assert_eq!(Entity::new(123, 456), Entity::new(123, 456));
assert!(Entity::new(123, 789) != Entity::new(123, 456)); assert_ne!(Entity::new(123, 789), Entity::new(123, 456));
assert!(Entity::new(123, 456) != Entity::new(123, 789)); assert_ne!(Entity::new(123, 456), Entity::new(123, 789));
assert!(Entity::new(123, 456) != Entity::new(456, 123)); assert_ne!(Entity::new(123, 456), Entity::new(456, 123));
// ordering is by generation then by index // ordering is by generation then by index

View File

@ -239,7 +239,7 @@ mod tests {
partially_ordered == [8, 9, 10] || partially_ordered == [10, 8, 9], partially_ordered == [8, 9, 10] || partially_ordered == [10, 8, 9],
"partially_ordered must be [8, 9, 10] or [10, 8, 9]" "partially_ordered must be [8, 9, 10] or [10, 8, 9]"
); );
assert!(order.len() == 11, "must have exactly 11 order entries"); assert_eq!(order.len(), 11, "must have exactly 11 order entries");
} }
} }

View File

@ -1297,7 +1297,7 @@ mod tests {
.spawn((W(1u32), W(2u64))) .spawn((W(1u32), W(2u64)))
.id(); .id();
command_queue.apply(&mut world); command_queue.apply(&mut world);
assert!(world.entities().len() == 1); assert_eq!(world.entities().len(), 1);
let results = world let results = world
.query::<(&W<u32>, &W<u64>)>() .query::<(&W<u32>, &W<u64>)>()
.iter(&world) .iter(&world)

View File

@ -520,7 +520,7 @@ where
} }
fn update_archetype_component_access(&mut self, world: UnsafeWorldCell) { fn update_archetype_component_access(&mut self, world: UnsafeWorldCell) {
assert!(self.world_id == Some(world.id()), "Encountered a mismatched World. A System cannot be used with Worlds other than the one it was initialized with."); assert_eq!(self.world_id, Some(world.id()), "Encountered a mismatched World. A System cannot be used with Worlds other than the one it was initialized with.");
let archetypes = world.archetypes(); let archetypes = world.archetypes();
let old_generation = let old_generation =
std::mem::replace(&mut self.archetype_generation, archetypes.generation()); std::mem::replace(&mut self.archetype_generation, archetypes.generation());

View File

@ -1812,7 +1812,7 @@ mod tests {
assert!(res.is_err()); assert!(res.is_err());
// Ensure that the location has been properly updated. // Ensure that the location has been properly updated.
assert!(entity.location() != old_location); assert_ne!(entity.location(), old_location);
} }
// regression test for https://github.com/bevyengine/bevy/pull/7805 // regression test for https://github.com/bevyengine/bevy/pull/7805

View File

@ -272,7 +272,7 @@ mod tests {
// The parent's Children component should still have two children. // The parent's Children component should still have two children.
let children = world.entity(parent).get::<Children>(); let children = world.entity(parent).get::<Children>();
assert!(children.is_some()); assert!(children.is_some());
assert!(children.unwrap().len() == 2_usize); assert_eq!(children.unwrap().len(), 2_usize);
// The original child should be despawned. // The original child should be despawned.
assert!(world.get_entity(child).is_none()); assert!(world.get_entity(child).is_none());
} }

View File

@ -481,7 +481,7 @@ mod test {
assert!(touches.pressed.get(&touch_event.id).is_none()); assert!(touches.pressed.get(&touch_event.id).is_none());
let touch = touches.just_released.get(&touch_event.id).unwrap(); let touch = touches.just_released.get(&touch_event.id).unwrap();
// Make sure the position is updated from TouchPhase::Moved and TouchPhase::Ended // Make sure the position is updated from TouchPhase::Moved and TouchPhase::Ended
assert!(touch.previous_position != touch.position); assert_ne!(touch.previous_position, touch.position);
} }
#[test] #[test]

View File

@ -464,12 +464,13 @@ impl<T: Sized> DebugEnsureAligned for *mut T {
// ptr.is_aligned_to. // ptr.is_aligned_to.
// //
// Replace once https://github.com/rust-lang/rust/issues/96284 is stable. // Replace once https://github.com/rust-lang/rust/issues/96284 is stable.
assert!( assert_eq!(
self as usize & (align - 1) == 0, self as usize & (align - 1),
0,
"pointer is not aligned. Address {:p} does not have alignment {} for type {}", "pointer is not aligned. Address {:p} does not have alignment {} for type {}",
self, self,
align, align,
core::any::type_name::<T>(), core::any::type_name::<T>()
); );
self self
} }

View File

@ -755,28 +755,33 @@ mod tests {
graph.add_slot_edge("C", 0, "D", 0); graph.add_slot_edge("C", 0, "D", 0);
assert!(input_nodes("A", &graph).is_empty(), "A has no inputs"); assert!(input_nodes("A", &graph).is_empty(), "A has no inputs");
assert!( assert_eq!(
output_nodes("A", &graph) == HashSet::from_iter(vec![c_id]), output_nodes("A", &graph),
HashSet::from_iter(vec![c_id]),
"A outputs to C" "A outputs to C"
); );
assert!(input_nodes("B", &graph).is_empty(), "B has no inputs"); assert!(input_nodes("B", &graph).is_empty(), "B has no inputs");
assert!( assert_eq!(
output_nodes("B", &graph) == HashSet::from_iter(vec![c_id]), output_nodes("B", &graph),
HashSet::from_iter(vec![c_id]),
"B outputs to C" "B outputs to C"
); );
assert!( assert_eq!(
input_nodes("C", &graph) == HashSet::from_iter(vec![a_id, b_id]), input_nodes("C", &graph),
HashSet::from_iter(vec![a_id, b_id]),
"A and B input to C" "A and B input to C"
); );
assert!( assert_eq!(
output_nodes("C", &graph) == HashSet::from_iter(vec![d_id]), output_nodes("C", &graph),
HashSet::from_iter(vec![d_id]),
"C outputs to D" "C outputs to D"
); );
assert!( assert_eq!(
input_nodes("D", &graph) == HashSet::from_iter(vec![c_id]), input_nodes("D", &graph),
HashSet::from_iter(vec![c_id]),
"C inputs to D" "C inputs to D"
); );
assert!(output_nodes("D", &graph).is_empty(), "D has no outputs"); assert!(output_nodes("D", &graph).is_empty(), "D has no outputs");
@ -880,20 +885,24 @@ mod tests {
graph.add_node_edges(&["A", "B", "C"]); graph.add_node_edges(&["A", "B", "C"]);
assert!( assert_eq!(
output_nodes("A", &graph) == HashSet::from_iter(vec![b_id]), output_nodes("A", &graph),
HashSet::from_iter(vec![b_id]),
"A -> B" "A -> B"
); );
assert!( assert_eq!(
input_nodes("B", &graph) == HashSet::from_iter(vec![a_id]), input_nodes("B", &graph),
HashSet::from_iter(vec![a_id]),
"A -> B" "A -> B"
); );
assert!( assert_eq!(
output_nodes("B", &graph) == HashSet::from_iter(vec![c_id]), output_nodes("B", &graph),
HashSet::from_iter(vec![c_id]),
"B -> C" "B -> C"
); );
assert!( assert_eq!(
input_nodes("C", &graph) == HashSet::from_iter(vec![b_id]), input_nodes("C", &graph),
HashSet::from_iter(vec![b_id]),
"B -> C" "B -> C"
); );
} }

View File

@ -573,8 +573,9 @@ impl Image {
/// # Panics /// # Panics
/// Panics if the `new_size` does not have the same volume as to old one. /// Panics if the `new_size` does not have the same volume as to old one.
pub fn reinterpret_size(&mut self, new_size: Extent3d) { pub fn reinterpret_size(&mut self, new_size: Extent3d) {
assert!( assert_eq!(
new_size.volume() == self.texture_descriptor.size.volume(), new_size.volume(),
self.texture_descriptor.size.volume(),
"Incompatible sizes: old = {:?} new = {:?}", "Incompatible sizes: old = {:?} new = {:?}",
self.texture_descriptor.size, self.texture_descriptor.size,
new_size new_size
@ -592,8 +593,8 @@ impl Image {
/// the `layers`. /// the `layers`.
pub fn reinterpret_stacked_2d_as_array(&mut self, layers: u32) { pub fn reinterpret_stacked_2d_as_array(&mut self, layers: u32) {
// Must be a stacked image, and the height must be divisible by layers. // Must be a stacked image, and the height must be divisible by layers.
assert!(self.texture_descriptor.dimension == TextureDimension::D2); assert_eq!(self.texture_descriptor.dimension, TextureDimension::D2);
assert!(self.texture_descriptor.size.depth_or_array_layers == 1); assert_eq!(self.texture_descriptor.size.depth_or_array_layers, 1);
assert_eq!(self.height() % layers, 0); assert_eq!(self.height() % layers, 0);
self.reinterpret_size(Extent3d { self.reinterpret_size(Extent3d {